xtimer: refine config macros

- auto set XTIMER_SHIFT relative to XTIMER_HZ
    - refine setting of XTIMER_WIDTH
This commit is contained in:
smlng 2017-03-06 20:34:13 +01:00
parent 88e574871e
commit b012cdb8ad
3 changed files with 46 additions and 26 deletions

View File

@ -88,7 +88,6 @@ extern "C" {
* @{ * @{
*/ */
#define XTIMER_WIDTH (16) #define XTIMER_WIDTH (16)
#define XTIMER_SHIFT (2)
#define XTIMER_HZ (250000UL) #define XTIMER_HZ (250000UL)
#define XTIMER_BACKOFF (40) #define XTIMER_BACKOFF (40)
/** @} */ /** @} */

View File

@ -165,7 +165,6 @@ extern "C" {
* @{ * @{
*/ */
#define XTIMER_WIDTH (16) #define XTIMER_WIDTH (16)
#define XTIMER_SHIFT (4)
#define XTIMER_HZ (62500UL) #define XTIMER_HZ (62500UL)
#define XTIMER_BACKOFF (40) #define XTIMER_BACKOFF (40)
/** @} */ /** @} */

View File

@ -520,24 +520,6 @@ void xtimer_set_timeout_flag(xtimer_t *t, uint32_t timeout);
#define XTIMER_PERIODIC_RELATIVE (512) #define XTIMER_PERIODIC_RELATIVE (512)
#endif #endif
#ifndef XTIMER_SHIFT
/**
* @brief xtimer prescaler value
*
* If the underlying hardware timer is running at a power of two multiple of
* 15625, XTIMER_SHIFT can be used to adjust the difference.
*
* For a 1 MHz hardware timer, set XTIMER_SHIFT to 0.
*
* For a 4 MHz hardware timer, set XTIMER_SHIFT to 2.
* For a 16 MHz hardware timer, set XTIMER_SHIFT to 4.
* For a 250 kHz hardware timer, set XTIMER_SHIFT to 2.
*
* The direction of the shift is handled by the macros in tick_conversion.h
*/
#define XTIMER_SHIFT (0)
#endif
/* /*
* Default xtimer configuration * Default xtimer configuration
*/ */
@ -551,15 +533,14 @@ void xtimer_set_timeout_flag(xtimer_t *t, uint32_t timeout);
*/ */
#define XTIMER_CHAN (0) #define XTIMER_CHAN (0)
#endif
#ifndef XTIMER_WIDTH
#if (TIMER_0_MAX_VALUE) == 0xfffffful #if (TIMER_0_MAX_VALUE) == 0xfffffful
#define XTIMER_WIDTH (24) #define XTIMER_WIDTH (24)
#elif (TIMER_0_MAX_VALUE) == 0xffff #elif (TIMER_0_MAX_VALUE) == 0xffff
#define XTIMER_WIDTH (16) #define XTIMER_WIDTH (16)
#endif #else
#endif
#ifndef XTIMER_WIDTH
/** /**
* @brief xtimer timer width * @brief xtimer timer width
* *
@ -568,6 +549,7 @@ void xtimer_set_timeout_flag(xtimer_t *t, uint32_t timeout);
*/ */
#define XTIMER_WIDTH (32) #define XTIMER_WIDTH (32)
#endif #endif
#endif
#if (XTIMER_WIDTH != 32) || DOXYGEN #if (XTIMER_WIDTH != 32) || DOXYGEN
/** /**
@ -584,11 +566,51 @@ void xtimer_set_timeout_flag(xtimer_t *t, uint32_t timeout);
#define XTIMER_MASK (0) #define XTIMER_MASK (0)
#endif #endif
/**
* @brief Base frequency of xtimer is 1 MHz
*/
#define XTIMER_HZ_BASE (1000000ul)
#ifndef XTIMER_HZ #ifndef XTIMER_HZ
/** /**
* @brief Frequency of the underlying hardware timer * @brief Frequency of the underlying hardware timer
*/ */
#define XTIMER_HZ 1000000ul #define XTIMER_HZ XTIMER_HZ_BASE
#endif
#ifndef XTIMER_SHIFT
#if (XTIMER_HZ == XTIMER_HZ_BASE)
/**
* @brief xtimer prescaler value
*
* If the underlying hardware timer is running at a power of two multiple of
* 15625, XTIMER_SHIFT can be used to adjust the difference.
*
* For a 1 MHz hardware timer, set XTIMER_SHIFT to 0.
* For a 2 MHz or 500 kHz, set XTIMER_SHIFT to 1.
* For a 4 MHz or 250 kHz, set XTIMER_SHIFT to 2.
* For a 8 MHz or 125 kHz, set XTIMER_SHIFT to 3.
* For a 16 MHz or 62.5 kHz, set XTIMER_SHIFT to 4.
* and for 32 MHz, set XTIMER_SHIFT to 5.
*
* The direction of the shift is handled by the macros in tick_conversion.h
*/
#define XTIMER_SHIFT (0)
#elif (XTIMER_HZ >> 1 == XTIMER_HZ_BASE) || (XTIMER_HZ << 1 == XTIMER_HZ_BASE)
#define XTIMER_SHIFT (1)
#elif (XTIMER_HZ >> 2 == XTIMER_HZ_BASE) || (XTIMER_HZ << 2 == XTIMER_HZ_BASE)
#define XTIMER_SHIFT (2)
#elif (XTIMER_HZ >> 3 == XTIMER_HZ_BASE) || (XTIMER_HZ << 3 == XTIMER_HZ_BASE)
#define XTIMER_SHIFT (3)
#elif (XTIMER_HZ >> 4 == XTIMER_HZ_BASE) || (XTIMER_HZ << 4 == XTIMER_HZ_BASE)
#define XTIMER_SHIFT (4)
#elif (XTIMER_HZ >> 5 == XTIMER_HZ_BASE) || (XTIMER_HZ << 5 == XTIMER_HZ_BASE)
#define XTIMER_SHIFT (5)
#else
#error "XTIMER_SHIFT cannot be derived for given XTIMER_HZ, verify settings!"
#endif
#else
#error "XTIMER_SHIFT is set relative to XTIMER_HZ, no manual define required!"
#endif #endif
#include "xtimer/tick_conversion.h" #include "xtimer/tick_conversion.h"