From: batt Date: Thu, 3 Feb 2011 18:29:25 +0000 (+0000) Subject: Merged from external project: X-Git-Tag: 2.7.0~286 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=9d47a03d8251b57383a391325022b7890f463f09;p=bertos.git 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 --- 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;