Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

timer.c 635B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "cmsis.h"
  2. #include "timer.h"
  3. /* Mill second tick count */
  4. volatile uint32_t timer_count = 0;
  5. /* Timer interrupt handler */
  6. void SysTick_Handler(void) {
  7. timer_count++;
  8. }
  9. void timer_init(void)
  10. {
  11. SysTick_Config(SystemCoreClock / 1000); /* 1ms tick */
  12. }
  13. void timer_clear(void)
  14. {
  15. timer_count = 0;
  16. }
  17. uint16_t timer_read(void)
  18. {
  19. return (uint16_t)(timer_count & 0xFFFF);
  20. }
  21. uint32_t timer_read32(void)
  22. {
  23. return timer_count;
  24. }
  25. uint16_t timer_elapsed(uint16_t last)
  26. {
  27. return TIMER_DIFF_16(timer_read(), last);
  28. }
  29. uint32_t timer_elapsed32(uint32_t last)
  30. {
  31. return TIMER_DIFF_32(timer_read32(), last);
  32. }