diff --git a/sys/include/xtimer.h b/sys/include/xtimer.h index 961b9043a3..488f50fa3e 100644 --- a/sys/include/xtimer.h +++ b/sys/include/xtimer.h @@ -401,7 +401,7 @@ extern volatile uint32_t _high_cnt; /** * @brief returns the (masked) low-level timer counter value. */ -static inline uint32_t _xtimer_now(void) +static inline uint32_t _lltimer_now(void) { #if XTIMER_SHIFT return ((uint32_t)timer_read(XTIMER)) << XTIMER_SHIFT; @@ -413,7 +413,7 @@ static inline uint32_t _xtimer_now(void) /** * @brief drop bits of a value that don't fit into the low-level timer. */ -static inline uint32_t _mask(uint32_t val) +static inline uint32_t _lltimer_mask(uint32_t val) { return val & ~XTIMER_MASK_SHIFTED; } @@ -436,8 +436,8 @@ static inline void xtimer_spin_until(uint32_t value); * * (only relevant when XTIMER_MASK != 0, e.g., timers < 32bit.) * - * When combining _xtimer_now() and _high_cnt, we have to get the same value in - * order to work around a race between overflowing _xtimer_now() and OR'ing the + * When combining _lltimer_now() and _high_cnt, we have to get the same value in + * order to work around a race between overflowing _lltimer_now() and OR'ing the * resulting values. * But some platforms are too slow to get the same timer * value twice, so we use this define to ignore some of the bits. @@ -460,31 +460,31 @@ static inline uint32_t xtimer_now(void) #if XTIMER_MASK uint32_t a, b; do { - a = _xtimer_now() | _high_cnt; - b = _xtimer_now() | _high_cnt; + a = _lltimer_now() | _high_cnt; + b = _lltimer_now() | _high_cnt; } while ((a >> XTIMER_SHIFT_ON_COMPARE) != (b >> XTIMER_SHIFT_ON_COMPARE)); return b; #else - return _xtimer_now(); + return _lltimer_now(); #endif } -static inline void xtimer_spin_until(uint32_t value) { +static inline void xtimer_spin_until(uint32_t target) { #if XTIMER_MASK - value = _mask(value); + target = _lltimer_mask(target); #endif - while (_xtimer_now() > value); - while (_xtimer_now() < value); + while (_lltimer_now() > target); + while (_lltimer_now() < target); } static inline void xtimer_spin(uint32_t offset) { - uint32_t start = _xtimer_now(); - while ((_xtimer_now() - start) < offset); + uint32_t start = _lltimer_now(); + while ((_lltimer_now() - start) < offset); } -static inline void xtimer_usleep(uint32_t offset) +static inline void xtimer_usleep(uint32_t microseconds) { - _xtimer_sleep(offset, 0); + _xtimer_sleep(microseconds, 0); } static inline void xtimer_usleep64(uint64_t microseconds) @@ -494,12 +494,12 @@ static inline void xtimer_usleep64(uint64_t microseconds) static inline void xtimer_sleep(uint32_t seconds) { - xtimer_usleep64((uint64_t)seconds*SEC_IN_USEC); + xtimer_usleep64((uint64_t)seconds * SEC_IN_USEC); } static inline void xtimer_nanosleep(uint32_t nanoseconds) { - _xtimer_sleep(nanoseconds/1000, 0); + _xtimer_sleep(nanoseconds / USEC_IN_NS, 0); } #ifdef __cplusplus diff --git a/sys/xtimer/xtimer_core.c b/sys/xtimer/xtimer_core.c index 92db65faab..2c4dabb341 100644 --- a/sys/xtimer/xtimer_core.c +++ b/sys/xtimer/xtimer_core.c @@ -113,7 +113,7 @@ void _xtimer_set64(xtimer_t *timer, uint32_t offset, uint32_t long_offset) void xtimer_set(xtimer_t *timer, uint32_t offset) { - DEBUG("timer_set(): offset=%" PRIu32 " now=%" PRIu32 " (%" PRIu32 ")\n", offset, xtimer_now(), _xtimer_now()); + DEBUG("timer_set(): offset=%" PRIu32 " now=%" PRIu32 " (%" PRIu32 ")\n", offset, xtimer_now(), _lltimer_now()); if (!timer->callback) { DEBUG("timer_set(): timer has no callback.\n"); return; @@ -147,14 +147,14 @@ static inline void _lltimer_set(uint32_t target) if (_in_handler) { return; } - DEBUG("__lltimer_set(): setting %" PRIu32 "\n", _mask(target)); + DEBUG("_lltimer_set(): setting %" PRIu32 "\n", _lltimer_mask(target)); #ifdef XTIMER_SHIFT target >>= XTIMER_SHIFT; if (!target) { target++; } #endif - timer_set_absolute(XTIMER, XTIMER_CHAN, _mask(target)); + timer_set_absolute(XTIMER, XTIMER_CHAN, _lltimer_mask(target)); } int _xtimer_set_absolute(xtimer_t *timer, uint32_t target) @@ -167,7 +167,7 @@ int _xtimer_set_absolute(xtimer_t *timer, uint32_t target) timer->next = NULL; if ((target >= now) && ((target - XTIMER_BACKOFF) < now)) { /* backoff */ - xtimer_spin_until(target+XTIMER_BACKOFF); + xtimer_spin_until(target + XTIMER_BACKOFF); _shoot(timer); return 0; } @@ -184,7 +184,7 @@ int _xtimer_set_absolute(xtimer_t *timer, uint32_t target) _add_timer_to_long_list(&long_list_head, timer); } else { - if (_mask(now) >= target) { + if (_lltimer_mask(now) >= target) { DEBUG("xtimer_set_absolute(): the timer will expire in the next timer period\n"); _add_timer_to_list(&overflow_list_head, timer); } @@ -255,7 +255,7 @@ int xtimer_remove(xtimer_t *timer) next = timer_list_head->target - XTIMER_OVERHEAD; } else { - next = _mask(0xFFFFFFFF); + next = _lltimer_mask(0xFFFFFFFF); } _lltimer_set(next); } @@ -275,7 +275,7 @@ int xtimer_remove(xtimer_t *timer) static uint32_t _time_left(uint32_t target, uint32_t reference) { - uint32_t now = _xtimer_now(); + uint32_t now = _lltimer_now(); if (now < reference) { return 0; @@ -307,10 +307,10 @@ static inline int _this_high_period(uint32_t target) { static inline xtimer_t *_compare(xtimer_t *a, xtimer_t *b) { if (a && b) { - return a->target <= b->target ? a : b; + return ((a->target <= b->target) ? a : b); } else { - return a ? a : b; + return (a ? a : b); } } @@ -423,7 +423,7 @@ static void _timer_callback(void) _in_handler = 1; DEBUG("_timer_callback() now=%" PRIu32 " (%" PRIu32 ")pleft=%" PRIu32 "\n", xtimer_now(), - _mask(xtimer_now()), _mask(0xffffffff-xtimer_now())); + _lltimer_mask(xtimer_now()), _lltimer_mask(0xffffffff-xtimer_now())); if (!timer_list_head) { DEBUG("_timer_callback(): tick\n"); @@ -438,21 +438,21 @@ static void _timer_callback(void) /* make sure the timer counter also arrived * in the next timer period */ - while (_xtimer_now() == _mask(0xFFFFFFFF)); + while (_lltimer_now() == _lltimer_mask(0xFFFFFFFF)); } else { /* we ended up in _timer_callback and there is * a timer waiting. */ /* set our period reference to the current time. */ - reference = _xtimer_now(); + reference = _lltimer_now(); } overflow: /* check if next timers are close to expiring */ - while (timer_list_head && (_time_left(_mask(timer_list_head->target), reference) < XTIMER_ISR_BACKOFF)) { + while (timer_list_head && (_time_left(_lltimer_mask(timer_list_head->target), reference) < XTIMER_ISR_BACKOFF)) { /* make sure we don't fire too early */ - while (_time_left(_mask(timer_list_head->target), reference)); + while (_time_left(_lltimer_mask(timer_list_head->target), reference)); /* pick first timer in list */ xtimer_t *timer = timer_list_head; @@ -472,7 +472,7 @@ overflow: * time to overflow. In that case we advance to * next timer period and check again for expired * timers.*/ - if (reference > _xtimer_now()) { + if (reference > _lltimer_now()) { DEBUG("_timer_callback: overflowed while executing callbacks. %i\n", timer_list_head != 0); _next_period(); reference = 0; @@ -484,15 +484,15 @@ overflow: next_target = timer_list_head->target - XTIMER_OVERHEAD; /* make sure we're not setting a time in the past */ - if (next_target < (_xtimer_now() + XTIMER_ISR_BACKOFF)) { + if (next_target < (_lltimer_now() + XTIMER_ISR_BACKOFF)) { goto overflow; } } else { /* there's no timer planned for this timer period */ /* schedule callback on next overflow */ - next_target = _mask(0xFFFFFFFF); - uint32_t now = _xtimer_now(); + next_target = _lltimer_mask(0xFFFFFFFF); + uint32_t now = _lltimer_now(); /* check for overflow again */ if (now < reference) { @@ -502,9 +502,9 @@ overflow: } else { /* check if the end of this period is very soon */ - if (_mask(now + XTIMER_ISR_BACKOFF) < now) { + if (_lltimer_mask(now + XTIMER_ISR_BACKOFF) < now) { /* spin until next period, then advance */ - while (_xtimer_now() >= now); + while (_lltimer_now() >= now); _next_period(); reference = 0; goto overflow; diff --git a/tests/xtimer_shift_on_compare/main.c b/tests/xtimer_shift_on_compare/main.c index c6cd61533d..7349b2a200 100644 --- a/tests/xtimer_shift_on_compare/main.c +++ b/tests/xtimer_shift_on_compare/main.c @@ -55,8 +55,8 @@ int main(void) else { } - a = _xtimer_now() | _high_cnt; - b = _xtimer_now() | _high_cnt; + a = _lltimer_now() | _high_cnt; + b = _lltimer_now() | _high_cnt; } while ((a>>shift) != (b>>shift)); min[shift] = i < min[shift] ? i : min[shift];