-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtimer.c
More file actions
52 lines (41 loc) · 970 Bytes
/
timer.c
File metadata and controls
52 lines (41 loc) · 970 Bytes
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
42
43
44
45
46
47
48
49
50
51
52
#include <stdlib.h>
#include <stdint.h>
#include <libopencm3/cm3/systick.h>
#include <defs.h>
#include <mod/led.h>
#include <mod/timer.h>
volatile unsigned timer[NTIMERS];
void sys_tick_handler(void)
{
unsigned i;
int blink;
for (i = 0; i < NTIMERS; i++)
if (timer[i] > 0)
timer[i]--;
if ((blink = led_blink_state()) != LED_STATE_NOBLINK &&
timer[TIMER_LED] == 0) {
led_toggle(led_blink_type());
timer[TIMER_LED] = (blink & LED_STATE_RAPID) ? 50 : 200;
}
}
void wait(unsigned msec)
{
timer[TIMER_DELAY] = msec;
while(timer[TIMER_DELAY] > 0);
}
void timers_init(void)
{
systick_set_clocksource(STK_CSR_CLKSOURCE_AHB);
/* systick mhz */
systick_set_reload(96 * 1000);
systick_interrupt_enable();
systick_counter_enable();
}
void set_timer(bl_timer_t tim, unsigned int msec)
{
timer[tim] = msec;
}
unsigned int check_timer(bl_timer_t tim)
{
return timer[tim];
}