~ruther/qmk_firmware

ref: 5daf24b1a5e2d6b07c90b87d9225db4d28aa2aa2 qmk_firmware/tmk_core/common/mbed/timer.c -rw-r--r-- 656 bytes
5daf24b1 — Nicholas Keene The Ordinary Layout is the most natural and powerful layout for the Ergodox EZ. Come check it out. 9 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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);
}