]> cloudbase.mooo.com Git - irmp-demo.git/blob - timer.c
Small changes. Convert TABs to spaces.
[irmp-demo.git] / timer.c
1 /*
2 * (C) Copyright 20014 - 2017 Leo C. <erbl259-lmu@yahoo.de>
3 *
4 * SPDX-License-Identifier: GPL-2.0
5 */
6
7 #include "timer.h"
8 #include <libopencm3/cm3/nvic.h>
9 #include <libopencm3/cm3/systick.h>
10 #include <libopencm3/stm32/rcc.h>
11 #include <libopencm3/stm32/gpio.h>
12
13
14 /*
15 * timer interrupt/overflow counter, counts up every ms.
16 */
17 static
18 volatile uint32_t timestamp;
19
20 void systick_setup(void)
21 {
22 /* SysTick interrupt every N clock pulses: set reload to N-1 */
23 STK_RVR = rcc_ahb_frequency/1000 - 1;
24
25 /* Set source to core clock, enable int and start counting. */
26 STK_CSR = STK_CSR_CLKSOURCE_AHB | STK_CSR_TICKINT | STK_CSR_ENABLE;
27 }
28
29 /*--------------------------------------------------------------------------*/
30
31 /*
32 * 1000Hz timer interrupt generated by System Timer
33 */
34 void sys_tick_handler(void)
35 {
36 ++timestamp;
37 }
38
39 /*--------------------------------------------------------------------------*/
40
41 /*
42 * Return elapsed time in ms since base.
43 */
44 uint32_t get_timer(uint32_t base)
45 {
46 return timestamp - base;
47 }