From c2f978bd1e344b40e538afb4cffb72f9e98d5343 Mon Sep 17 00:00:00 2001 From: sg Date: Tue, 18 Aug 2015 21:38:08 +0200 Subject: [PATCH] patch by Chrysn: patch #8704 fix sys_timeouts_sleeptime function --- CHANGELOG | 3 +++ src/core/timers.c | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) 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 */