1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

Make implementation of hwtimer_spin() easier to read and understand

This commit is contained in:
Kévin Roussel 2014-04-11 11:44:04 +02:00
parent c6f66bfe51
commit f763cb9ec2

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2013 Freie Universität Berlin * Copyright (C) 2014 Freie Universität Berlin
* *
* This file is subject to the terms and conditions of the GNU Lesser General * This file is subject to the terms and conditions of the GNU Lesser General
* Public License. See the file LICENSE in the top level directory for more * Public License. See the file LICENSE in the top level directory for more
@ -17,6 +17,7 @@
* @author Thomas Hillebrandt <hillebra@inf.fu-berlin.de> * @author Thomas Hillebrandt <hillebra@inf.fu-berlin.de>
* @author Kaspar Schleiser <kaspar@schleiser.de> * @author Kaspar Schleiser <kaspar@schleiser.de>
* @author Oliver Hahm <oliver.hahm@fu-berlin.de> * @author Oliver Hahm <oliver.hahm@fu-berlin.de>
* @author Kévin Roussel <Kevin.Roussel@inria.fr>
* *
* @} * @}
*/ */
@ -63,28 +64,21 @@ static void hwtimer_releasemutex(void* mutex) {
void hwtimer_spin(unsigned long ticks) void hwtimer_spin(unsigned long ticks)
{ {
DEBUG("hwtimer_spin ticks=%lu\n", ticks); DEBUG("hwtimer_spin ticks=%lu\n", ticks);
unsigned long t = hwtimer_arch_now();
/** unsigned long start = hwtimer_arch_now();
* If hwtimer_arch_now + ticks results in an overflow, /* compute destination time, possibly resulting in an overflow */
unsigned long stop = start + ticks;
/*
* If there is an overflow (that is: stop time is inferior to start),
* hwtimer_arch_now needs to spin until it has overflowed as well. * hwtimer_arch_now needs to spin until it has overflowed as well.
*
* If the destination time will result in an overflow, the result
* is smaller than ticks by at least one.
*/ */
if (t + ticks < ticks) { if (stop < start) {
while (hwtimer_arch_now() > t); while (hwtimer_arch_now() > start) /* do nothing */;
} }
/** /* wait until we have passed destination (stop) time */
* set t to destination time, possibly overflowing it while (hwtimer_arch_now() < stop) /* do nothing again */;
*/
t += ticks;
/**
* wait until the present has past destination time t
*/
while (hwtimer_arch_now() < t);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/