]> git.gir.st - tmk_keyboard.git/blob - common/mbed/timer.c
Port timer to mbed
[tmk_keyboard.git] / common / mbed / timer.c
1 #include "cmsis.h"
2 #include "timer.h"
3
4 /* Mill second tick count */
5 volatile uint32_t timer_count = 0;
6
7 /* Timer interrupt handler */
8 void SysTick_Handler(void) {
9 timer_count++;
10 }
11
12 void timer_init(void)
13 {
14 SysTick_Config(SystemCoreClock / 1000); /* 1ms tick */
15 }
16
17 void timer_clear(void)
18 {
19 timer_count = 0;
20 }
21
22 uint16_t timer_read(void)
23 {
24 return (uint16_t)(timer_count & 0xFFFF);
25 }
26
27 uint32_t timer_read32(void)
28 {
29 return timer_count;
30 }
31
32 uint16_t timer_elapsed(uint16_t last)
33 {
34 return TIMER_DIFF_16(timer_read(), last);
35 }
36
37 uint32_t timer_elapsed32(uint32_t last)
38 {
39 return TIMER_DIFF_32(timer_read32(), last);
40 }
Imprint / Impressum