diff options
author | tmk <hasu@tmk-kbd.com> | 2015-04-10 01:32:04 +0900 |
---|---|---|
committer | tmk <hasu@tmk-kbd.com> | 2015-04-10 01:32:04 +0900 |
commit | 1a02ebcc612e9a9c0d87e02295c7258de3a70ccc (patch) | |
tree | e517f3c70bb2d542797e57d13e9023c84af230fb /tmk_core/common/mbed/timer.c | |
parent | 6746e37088ce8ba03529c1226bd216705edb2b1f (diff) | |
parent | a074364c3731d66b56d988c8a6c960a83ea0e0a1 (diff) | |
download | qmk_firmware-1a02ebcc612e9a9c0d87e02295c7258de3a70ccc.tar.gz qmk_firmware-1a02ebcc612e9a9c0d87e02295c7258de3a70ccc.zip |
Merge commit 'a074364c3731d66b56d988c8a6c960a83ea0e0a1' as 'tmk_core'
Diffstat (limited to 'tmk_core/common/mbed/timer.c')
-rw-r--r-- | tmk_core/common/mbed/timer.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tmk_core/common/mbed/timer.c b/tmk_core/common/mbed/timer.c new file mode 100644 index 000000000..c357ceb78 --- /dev/null +++ b/tmk_core/common/mbed/timer.c | |||
@@ -0,0 +1,41 @@ | |||
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 | timer_count = 0; | ||
15 | SysTick_Config(SystemCoreClock / 1000); /* 1ms tick */ | ||
16 | } | ||
17 | |||
18 | void timer_clear(void) | ||
19 | { | ||
20 | timer_count = 0; | ||
21 | } | ||
22 | |||
23 | uint16_t timer_read(void) | ||
24 | { | ||
25 | return (uint16_t)(timer_count & 0xFFFF); | ||
26 | } | ||
27 | |||
28 | uint32_t timer_read32(void) | ||
29 | { | ||
30 | return timer_count; | ||
31 | } | ||
32 | |||
33 | uint16_t timer_elapsed(uint16_t last) | ||
34 | { | ||
35 | return TIMER_DIFF_16(timer_read(), last); | ||
36 | } | ||
37 | |||
38 | uint32_t timer_elapsed32(uint32_t last) | ||
39 | { | ||
40 | return TIMER_DIFF_32(timer_read32(), last); | ||
41 | } | ||