diff options
author | 2015-10-27 14:52:18 -0400 | |
---|---|---|
committer | 2015-10-27 14:52:18 -0400 | |
commit | d311fd8d1a0af3b767d26b520d399bf0db22f058 (patch) | |
tree | b9de5704143ac205b4e26222f9d7551e9b161924 /tmk_core/common/mbed/timer.c | |
parent | a766918d5c48204375f4c207b30bbbf1389df14f (diff) | |
parent | 6f3141965e88c4ee0ebf7c18a243e4c2d9c5021b (diff) | |
download | qmk_firmware-d311fd8d1a0af3b767d26b520d399bf0db22f058.tar.gz |
Merge pull request #34 from jackhumbert/tmk-master
merging from tmk, new_project script and template
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 @@ +#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) +{ + timer_count = 0; + 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); +} |