aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--wirish/include/wirish/wirish_time.h11
1 files changed, 4 insertions, 7 deletions
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 <wirish/boards.h>
-#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
}
/**