]>
cloudbase.mooo.com Git - irmp-demo.git/blob - timer.c
2 * (C) Copyright 20014 - 2017 Leo C. <erbl259-lmu@yahoo.de>
4 * SPDX-License-Identifier: GPL-2.0
8 #include <libopencm3/cm3/nvic.h>
9 #include <libopencm3/cm3/systick.h>
10 #include <libopencm3/stm32/rcc.h>
11 #include <libopencm3/stm32/gpio.h>
15 * timer interrupt/overflow counter, counts up every ms.
18 volatile uint32_t timestamp
;
20 void systick_setup(void)
22 /* SysTick interrupt every N clock pulses: set reload to N-1 */
23 STK_RVR
= rcc_ahb_frequency
/1000 - 1;
25 /* Set source to core clock, enable int and start counting. */
26 STK_CSR
= STK_CSR_CLKSOURCE_AHB
| STK_CSR_TICKINT
| STK_CSR_ENABLE
;
29 /*--------------------------------------------------------------------------*/
32 * 1000Hz timer interrupt generated by System Timer
34 void sys_tick_handler(void)
39 /*--------------------------------------------------------------------------*/
42 * Return elapsed time in ms since base.
44 uint32_t get_timer(uint32_t base
)
46 return timestamp
- base
;