blob: cdab461088eea2f334a6c48b4a068fcc49b792e3 (
plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
#include "project.h"
static volatile uint32_t delay_ms_count;
volatile uint32_t ticks;
static uint32_t scale = 7;
void
delay_us (uint32_t d)
{
d *= scale;
while (d--)
{
__asm__ ("nop");
}
}
static void
s_tick_handler (void)
{
adc_tick ();
state_tick ();
}
void
sys_tick_handler (void)
{
static int s_count;
if (delay_ms_count)
delay_ms_count--;
ticks++;
led_tick ();
#ifndef SLIM
lcd_tick ();
#endif
usb_tick();
#if 0
s_count++;
if (s_count >= 1000)
{
s_count = 0;
s_tick_handler ();
}
#else
s_tick_handler ();
#endif
}
void
delay_ms (uint32_t d)
{
delay_ms_count = d;
while (delay_ms_count);
}
int
timed_out (uint32_t then, unsigned int ms)
{
then = ticks - then;
if (then > ms)
return 1;
return 0;
}
void
ticker_init (void)
{
uint32_t v, w;
/*Start periodic timer */
systick_set_clocksource (STK_CSR_CLKSOURCE_AHB_DIV8);
/* 24MHz / 8 = > 3Mhz */
systick_set_reload (3000);
/* 3MHz / 3000 => 1kHz */
systick_interrupt_enable ();
systick_counter_enable ();
/*Calibrate the delay loop */
do
{
scale--;
v = ticks;
while (v == ticks);
delay_us (1000);
w = ticks;
v++;
w -= v;
}
while (w);
}
|