From 35c6b9f8a4931fbe6bd3cb3a4cabb343b39a335f Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 17 Apr 2006 00:03:17 +0000 Subject: [PATCH] Simplify delay loop by moving the maths to before the loop. There is minimal risk of overflow unless something delays >134s. --- sys/arch/arm/footbridge/footbridge_clock.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/sys/arch/arm/footbridge/footbridge_clock.c b/sys/arch/arm/footbridge/footbridge_clock.c index d5227792bf1f..61c9253669ab 100644 --- a/sys/arch/arm/footbridge/footbridge_clock.c +++ b/sys/arch/arm/footbridge/footbridge_clock.c @@ -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 -__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; - } } }