diff --git a/CHANGELOG b/CHANGELOG index 7326d2a6..83e72a01 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -249,6 +249,9 @@ HISTORY ++ Bugfixes: + 2015-08-18: Chrysn + timers.c: patch #8704 fix sys_timeouts_sleeptime function + 2015-07-01: Erik Ekman * puf.c: fixed bug #45454 (pbuf_take_at() skips write and returns OK if offset is at start of pbuf in chain) diff --git a/src/core/timers.c b/src/core/timers.c index 92c69efe..74a5c4d4 100644 --- a/src/core/timers.c +++ b/src/core/timers.c @@ -495,10 +495,16 @@ sys_restart_timeouts(void) u32_t sys_timeouts_sleeptime(void) { + u32_t diff; if (next_timeout == NULL) { return 0xffffffff; } - return (sys_now() - timeouts_last_time) + next_timeout->time; + diff = sys_now() - timeouts_last_time; + if (diff > next_timeout->time) { + return 0; + } else { + return next_timeout->time - diff; + } } #else /* NO_SYS */