]> oss.titaniummirror.com Git - rgblamp.git/commitdiff
Ensure proper behavior in timer_cwait
authorR. Steve McKown <rsmckown@gmail.com>
Thu, 8 Dec 2011 03:05:19 +0000 (20:05 -0700)
committerR. Steve McKown <rsmckown@gmail.com>
Thu, 8 Dec 2011 03:05:19 +0000 (20:05 -0700)
Ah, the Hi-Tech compiler's lovely interpretation of promotions.  See
3.6.1, Integral Promotion.  This may affect the conditional in
timer_cwait(), so force a cast of the result to be sure it is correct.

timer.h

diff --git a/timer.h b/timer.h
index c28ed0b93b34d844f196a0b359645a579ec70e19..20e0c8bc9258b1def182068122b60ac2ad4853ed 100644 (file)
--- a/timer.h
+++ b/timer.h
@@ -44,7 +44,7 @@
 #define timer_cwait(c) \
   { \
     unsigned t0 = TMR0; \
-    while ((TMR0 - t0) <= c); \
+    while ((unsigned)(TMR0 - t0) <= c); /* cast prevents integral promotion */ \
   } while (0)
 
 void timer_uwait(unsigned us);