Skip to content

Commit

Permalink
xtimer: timer & target overflow, hang resolved.
Browse files Browse the repository at this point in the history
1. When the 32 bit target of the xtimer overflowed the timer was not placed in the right list.
2. When the hardware timer overflowed the comparison was wrong for setting next target.
  • Loading branch information
Josar committed May 28, 2018
1 parent 202fd41 commit f7d82dc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions sys/xtimer/xtimer_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ int _xtimer_set_absolute(xtimer_t *timer, uint32_t target)

timer->target = target;
timer->long_target = _long_cnt;

/* Ensure timer is fired in right hardware timer period. */
target = target - XTIMER_OVERHEAD;

/* 32 bit target overflow */
if (target < now) {
timer->long_target++;
}
Expand All @@ -209,7 +214,7 @@ int _xtimer_set_absolute(xtimer_t *timer, uint32_t target)

if (timer_list_head == timer) {
DEBUG("timer_set_absolute(): timer is new list head. updating lltimer.\n");
_lltimer_set(target - XTIMER_OVERHEAD);
_lltimer_set(target);
}
}
}
Expand Down Expand Up @@ -499,7 +504,7 @@ static void _timer_callback(void)
next_target = timer_list_head->target - XTIMER_OVERHEAD;

/* make sure we're not setting a time in the past */
if (next_target < (_xtimer_lltimer_now() + XTIMER_ISR_BACKOFF)) {
if (next_target < ( _xtimer_now() + XTIMER_ISR_BACKOFF)) {
goto overflow;
}
}
Expand Down

0 comments on commit f7d82dc

Please sign in to comment.