blob: b02e584ae8f2581f83967d4bc90a020464e0e8d0 (
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
|
#include "project.h"
#define FLASH 100
static unsigned led1 = FLASH, led2 = FLASH;
static void metric_pll (void)
{
static uint32_t last;
static int which;
static unsigned ttg;
EPOCH e;
uint64_t v;
if ((ticks - last) < ttg) return;
e = rtc_get();
if (which) {
led2 = FLASH;
CLEAR (LED2);
} else {
led1 = FLASH;
CLEAR (LED1);
}
last = ticks;
which = !which;
v = e.s;
v %= 86400;
v *= 1000;
v += e.ns / 1000000;
v %= 864;
//printf("M: %5u %9u\r\n",(unsigned) v, (unsigned ) (e.ns/1000000));
ttg = 864 - (unsigned)v;
}
static void customary_pll (void)
{
static uint32_t last;
static unsigned ttg;
EPOCH e;
uint64_t v;
if ((ticks - last) < ttg) return;
e = rtc_get();
led2 = FLASH;
CLEAR (LED2);
last = ticks;
v = e.ns / 1000000;
v %= 1000;
ttg = 1000 - (unsigned)v;
// printf("C: %9u\r\n",(unsigned ) (e.ns/1000000));
}
void led_tick (void)
{
if (led1) {
CLEAR (LED1);
led1--;
} else SET (LED1);
if (led2) {
CLEAR (LED2);
led2--;
} else SET (LED2);
if (!rtc_ready) return;
metric_pll();
// customary_pll();
}
void leds_init (void)
{
MAP_OUTPUT_OD (LED1);
MAP_OUTPUT_OD (LED2);
}
|