**********
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
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;