Simplify delay loop by moving the maths to before the loop.
There is minimal risk of overflow unless something delays >134s.
This commit is contained in:
parent
c75aeaa653
commit
35c6b9f8a4
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: footbridge_clock.c,v 1.20 2005/12/11 12:16:45 christos Exp $ */
|
||||
/* $NetBSD: footbridge_clock.c,v 1.21 2006/04/17 00:03:17 chris Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 Mark Brinicombe.
|
||||
@ -35,7 +35,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: footbridge_clock.c,v 1.20 2005/12/11 12:16:45 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: footbridge_clock.c,v 1.21 2006/04/17 00:03:17 chris Exp $");
|
||||
|
||||
/* Include header files */
|
||||
|
||||
@ -421,7 +421,6 @@ delay(n)
|
||||
|
||||
if (n == 0) return;
|
||||
|
||||
|
||||
/*
|
||||
* not calibrated the timer yet, so try to live with this horrible
|
||||
* loop!
|
||||
@ -440,9 +439,11 @@ delay(n)
|
||||
last = bus_space_read_4(clock_sc->sc_iot, clock_sc->sc_ioh,
|
||||
TIMER_3_VALUE);
|
||||
|
||||
delta = usecs = 0;
|
||||
delta = 0;
|
||||
|
||||
while (n > usecs)
|
||||
usecs = n * delay_count_per_usec;
|
||||
|
||||
while (usecs > delta)
|
||||
{
|
||||
cur = bus_space_read_4(clock_sc->sc_iot, clock_sc->sc_ioh,
|
||||
TIMER_3_VALUE);
|
||||
@ -463,12 +464,6 @@ delay(n)
|
||||
TIMER_3_CLEAR, 0);
|
||||
}
|
||||
last = cur;
|
||||
|
||||
if (delta >= delay_count_per_usec)
|
||||
{
|
||||
usecs += delta / delay_count_per_usec;
|
||||
delta %= delay_count_per_usec;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user