summaryrefslogtreecommitdiffstats
path: root/common/mbed
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2014-06-16 11:12:45 +0900
committertmk <nobody@nowhere>2014-07-30 14:07:43 +0900
commit867f115bee190515aa195dc3e58f1c381ea9695b (patch)
treea738787299cbac2fbaf26e586393f4d4170e8775 /common/mbed
parentf15b2691c92e1d9b3c0e59363c803ec540303f37 (diff)
Port timer to mbed
Diffstat (limited to 'common/mbed')
-rw-r--r--common/mbed/timer.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/common/mbed/timer.c b/common/mbed/timer.c
new file mode 100644
index 0000000000..a64a77239c
--- /dev/null
+++ b/common/mbed/timer.c
@@ -0,0 +1,40 @@
+#include "cmsis.h"
+#include "timer.h"
+
+/* Mill second tick count */
+volatile uint32_t timer_count = 0;
+
+/* Timer interrupt handler */
+void SysTick_Handler(void) {
+ timer_count++;
+}
+
+void timer_init(void)
+{
+ SysTick_Config(SystemCoreClock / 1000); /* 1ms tick */
+}
+
+void timer_clear(void)
+{
+ timer_count = 0;
+}
+
+uint16_t timer_read(void)
+{
+ return (uint16_t)(timer_count & 0xFFFF);
+}
+
+uint32_t timer_read32(void)
+{
+ return timer_count;
+}
+
+uint16_t timer_elapsed(uint16_t last)
+{
+ return TIMER_DIFF_16(timer_read(), last);
+}
+
+uint32_t timer_elapsed32(uint32_t last)
+{
+ return TIMER_DIFF_32(timer_read32(), last);
+}