Merged from external project:
authorbatt <batt@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 3 Feb 2011 18:29:25 +0000 (18:29 +0000)
committerbatt <batt@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 3 Feb 2011 18:29:25 +0000 (18:29 +0000)
**********
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

index e8508e047f18d3f767632eaf3809cd3bf5786ec0..4d1309466da6b37fb870ad244aa4f802df57f74a 100644 (file)
@@ -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;