diff --git a/core/include/hwtimer.h b/core/include/hwtimer.h index 2f3c4ddcd7..5a2d701c6e 100644 --- a/core/include/hwtimer.h +++ b/core/include/hwtimer.h @@ -86,14 +86,22 @@ per second for the current architecture." * @param[in] us number of microseconds * @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 * @param[in] ticks number of ticks * @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) @@ -107,7 +115,11 @@ number of ticks countable on the current architecture." /** * @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 */