From a671364ca242421f6c51595867b2fe5574832a42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Wed, 20 Sep 2017 10:15:40 +0200 Subject: [PATCH] xtimer: Fix backoff condition in _xtimer_set_absolute When the target is inside the next long_period, the previous condition was incorrect. The new condition should give the same result regardless of whether there is a long_period tick coming soon or not. --- sys/xtimer/xtimer_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sys/xtimer/xtimer_core.c b/sys/xtimer/xtimer_core.c index d5765de89b84..33bd8c9aacda 100644 --- a/sys/xtimer/xtimer_core.c +++ b/sys/xtimer/xtimer_core.c @@ -176,7 +176,9 @@ int _xtimer_set_absolute(xtimer_t *timer, uint32_t target) DEBUG("timer_set_absolute(): now=%" PRIu32 " target=%" PRIu32 "\n", now, target); timer->next = NULL; - if ((target >= now) && ((target - XTIMER_BACKOFF) < now)) { + /* The (target - now) difference works across the long tick rollover, there + * is no need to check for (target > now) first. */ + if ((target - now) < XTIMER_BACKOFF) { /* backoff */ xtimer_spin_until(target + XTIMER_BACKOFF); _shoot(timer);