From 82184529ca82b955e227b50ad07837f14619a055 Mon Sep 17 00:00:00 2001 From: "R. Steve McKown" Date: Sat, 31 Dec 2011 10:43:48 -0700 Subject: [PATCH] fix tmr_uwait() and tmr_mwait() 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 | 15 --------------- tmr.h | 2 +- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/tmr.c b/tmr.c index 34a9733..09e6c2d 100644 --- 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 b25e8ad..a204ab0 100644 --- 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. */ -- 2.39.2