1
0
tmk_keyboard/common/mbed/timer.c

42 linhas
656 B
C
Original Visão normal Histórico

2014-06-16 02:12:45 +00:00
#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)
{
2014-06-16 06:38:39 +00:00
timer_count = 0;
2014-06-16 02:12:45 +00:00
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);
}