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.
}
}
-/* 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;
void tmr_mwait(unsigned ms)
{
- unsigned t0 = TMR0;
-
- while (ms >= 32) {
- tmr_wait(t0);
- ms -= 32;
- }
while (ms >= 16) {
tmr_cwait(128);
ms -= 16;
#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. */