]> oss.titaniummirror.com Git - rgblamp.git/commitdiff
fix tmr_uwait() and tmr_mwait()
authorR. Steve McKown <rsmckown@gmail.com>
Sat, 31 Dec 2011 17:43:48 +0000 (10:43 -0700)
committerR. Steve McKown <rsmckown@gmail.com>
Sat, 31 Dec 2011 19:47:13 +0000 (12:47 -0700)
Polling for a specific timer register value will miss that value, at
least at some CPU clock rates, so it is not usable for timer wait
functions.

tmr.c
tmr.h

diff --git a/tmr.c b/tmr.c
index 34a9733e5737aebf2f95e9f0c070fd76ffd0a027..09e6c2d3cef8dbbb1fe0170442bac3c77175bd8e 100644 (file)
--- a/tmr.c
+++ b/tmr.c
@@ -119,17 +119,8 @@ void tmr_isr()
   }
 }
 
-/* Wait for a specific timer value t */
-#define tmr_wait(t) while (TMR0 != t);
-
 void tmr_uwait(unsigned us)
 {
-  unsigned t0 = TMR0;
-
-  while (us >= 32768) {
-    tmr_wait(t0);
-    us -= 32768;
-  }
   while (us >= 16384) {
     tmr_cwait(128);
     us -= 16384;
@@ -139,12 +130,6 @@ void tmr_uwait(unsigned us)
 
 void tmr_mwait(unsigned ms)
 {
-  unsigned t0 = TMR0;
-
-  while (ms >= 32) {
-    tmr_wait(t0);
-    ms -= 32;
-  }
   while (ms >= 16) {
     tmr_cwait(128);
     ms -= 16;
diff --git a/tmr.h b/tmr.h
index b25e8ad25473b4145f3e971c9d61627e27a5e1a0..a204ab000675ed0f362c26465e95c3cc010c0d21 100644 (file)
--- a/tmr.h
+++ b/tmr.h
@@ -99,7 +99,7 @@ void tmr_isr();
 #define tmr_cwait(c) \
   do { \
     unsigned t0 = TMR0; \
-    while (TMR0 - t0 <= c); /* cast prevents integral promotion */ \
+    while (TMR0 - t0 <= c); \
   } while (0)
 
 /* Wait for a number of us.  This is pretty accurate. */