aboutsummaryrefslogtreecommitdiffstats
path: root/wirish/time.h
diff options
context:
space:
mode:
Diffstat (limited to 'wirish/time.h')
-rw-r--r--wirish/time.h50
1 files changed, 29 insertions, 21 deletions
diff --git a/wirish/time.h b/wirish/time.h
index 9e5536b..33c04b4 100644
--- a/wirish/time.h
+++ b/wirish/time.h
@@ -23,8 +23,6 @@
* ****************************************************************************/
/**
- * @file time.h
- *
* @brief
*/
@@ -34,32 +32,42 @@
#ifdef __cplusplus
extern "C"{
#endif
-/* Returns time since boot in milliseconds */
-uint32 millis(void);
+
+#include "nvic.h"
+#include "systick.h"
+#include "boards.h"
+
+#define US_PER_MS 1000
+#define MAPLE_RELOAD_VAL (CYCLES_PER_MICROSECOND * US_PER_MS)
+
+extern volatile uint32 systick_timer_millis;
+
+/* time in milliseconds since boot */
+static inline uint32 millis(void) {
+ return systick_timer_millis;
+}
/* Time in microseconds since boot */
-uint32 micros(void);
+static inline uint32 micros(void) {
+ uint32 ms;
+ uint32 cycle_cnt;
+ uint32 res;
-/* Delay for ms milliseconds */
-void delay(unsigned long ms);
+ nvic_globalirq_disable();
-/* Delay for us microseconds */
-void delayMicroseconds(uint32 us);
+ cycle_cnt = systick_get_count();
+ ms = millis();
+
+ nvic_globalirq_enable();
-#if 0
-static inline void delay_us(uint32 us) {
- us *= 12;
- asm volatile("mov r0, %[us] \n\t"
- "subs r0, #2 \n\t"
-"1: \n\t"
- "subs r0, r0, #1 \n\t"
- "bne 1b"
- :
- : [us] "r" (us)
- : "r0", "cc");
+ res = (ms * US_PER_MS) + (MAPLE_RELOAD_VAL - cycle_cnt)/CYCLES_PER_MICROSECOND;
+ return res;
}
-#endif
+
+void delay(unsigned long ms);
+void delayMicroseconds(uint32 us);
+
#ifdef __cplusplus
} // extern "C"
#endif