Merge pull request #1709 from benpicco/hwtimer_fix
allow HWTIMER_SPEED > 1000000
This commit is contained in:
commit
07fe5bcc9f
@ -86,14 +86,22 @@ per second for the current architecture."
|
|||||||
* @param[in] us number of microseconds
|
* @param[in] us number of microseconds
|
||||||
* @return kernel timer ticks
|
* @return kernel timer ticks
|
||||||
*/
|
*/
|
||||||
#define HWTIMER_TICKS(us) ((us) / (1000000L / HWTIMER_SPEED))
|
#if HWTIMER_SPEED > 1000000L
|
||||||
|
#define HWTIMER_TICKS(us) ((us) * (HWTIMER_SPEED / 1000000L))
|
||||||
|
#else
|
||||||
|
#define HWTIMER_TICKS(us) ((us) / (1000000L / HWTIMER_SPEED))
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Convert ticks to microseconds
|
* @brief Convert ticks to microseconds
|
||||||
* @param[in] ticks number of ticks
|
* @param[in] ticks number of ticks
|
||||||
* @return microseconds
|
* @return microseconds
|
||||||
*/
|
*/
|
||||||
#define HWTIMER_TICKS_TO_US(ticks) ((ticks) * (1000000L/HWTIMER_SPEED))
|
#if HWTIMER_SPEED > 1000000L
|
||||||
|
#define HWTIMER_TICKS_TO_US(ticks) ((ticks) / (HWTIMER_SPEED / 1000000L))
|
||||||
|
#else
|
||||||
|
#define HWTIMER_TICKS_TO_US(ticks) ((ticks) * (1000000L / HWTIMER_SPEED))
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Maximum hwtimer tick count (before overflow)
|
* @brief Maximum hwtimer tick count (before overflow)
|
||||||
@ -107,7 +115,11 @@ number of ticks countable on the current architecture."
|
|||||||
/**
|
/**
|
||||||
* @brief microseconds before hwtimer overflow
|
* @brief microseconds before hwtimer overflow
|
||||||
*/
|
*/
|
||||||
#define HWTIMER_OVERFLOW_MICROS() (1000000L / HWTIMER_SPEED * HWTIMER_MAXTICKS)
|
#if HWTIMER_SPEED > 1000000L
|
||||||
|
#define HWTIMER_OVERFLOW_MICROS() (HWTIMER_MAXTICKS / HWTIMER_SPEED * 1000000L)
|
||||||
|
#else
|
||||||
|
#define HWTIMER_OVERFLOW_MICROS() (1000000L / HWTIMER_SPEED * HWTIMER_MAXTICKS)
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef uint32_t timer_tick_t; /**< data type for hwtimer ticks */
|
typedef uint32_t timer_tick_t; /**< data type for hwtimer ticks */
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user