From 9d47a03d8251b57383a391325022b7890f463f09 Mon Sep 17 00:00:00 2001 From: batt Date: Thu, 3 Feb 2011 18:29:25 +0000 Subject: [PATCH] Merged from external project: ********** r30427 | aleph | 2011-02-03 17:20:19 +0100 (gio, 03 feb 2011) | 2 lines timer driver: fix wrap bug in HP timer delay ********** git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4680 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/drv/timer.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/bertos/drv/timer.c b/bertos/drv/timer.c index e8508e04..4d130946 100644 --- a/bertos/drv/timer.c +++ b/bertos/drv/timer.c @@ -286,15 +286,10 @@ void timer_busyWait(hptime_t delay) hptime_t now, prev = timer_hw_hpread(); hptime_t delta; - for(;;) + for (;;) { now = timer_hw_hpread(); - /* - * We rely on hptime_t being unsigned here to - * reduce the modulo to an AND in the common - * case of TIMER_HW_CNT. - */ - delta = (now - prev) % TIMER_HW_CNT; + delta = (now < prev) ? (TIMER_HW_CNT - prev + now) : (now - prev); if (delta >= delay) break; delay -= delta; -- 2.25.1