From 0e7a40c7b790f13daec1b8a73f20d1dda57134f9 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Wed, 27 Jun 2012 14:04:10 -0400 Subject: Clean up micros(). Don't leave US_PER_MS user-visible. Remove an unnecessary variable. Signed-off-by: Marti Bolivar --- wirish/include/wirish/wirish_time.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'wirish/include/wirish') diff --git a/wirish/include/wirish/wirish_time.h b/wirish/include/wirish/wirish_time.h index 1520b1e..eb6c68f 100644 --- a/wirish/include/wirish/wirish_time.h +++ b/wirish/include/wirish/wirish_time.h @@ -37,8 +37,6 @@ #include -#define US_PER_MS 1000 - /** * Returns time (in milliseconds) since the beginning of program * execution. On overflow, restarts at 0. @@ -56,19 +54,18 @@ static inline uint32 millis(void) { static inline uint32 micros(void) { uint32 ms; uint32 cycle_cnt; - uint32 res; do { ms = millis(); cycle_cnt = systick_get_count(); } while (ms != millis()); +#define US_PER_MS 1000 /* SYSTICK_RELOAD_VAL is 1 less than the number of cycles it * actually takes to complete a SysTick reload */ - res = (ms * US_PER_MS) + - (SYSTICK_RELOAD_VAL + 1 - cycle_cnt) / CYCLES_PER_MICROSECOND; - - return res; + return ((ms * US_PER_MS) + + (SYSTICK_RELOAD_VAL + 1 - cycle_cnt) / CYCLES_PER_MICROSECOND); +#undef US_PER_MS } /** -- cgit v1.2.3