|
@@ -9,10 +9,7 @@
|
9
|
9
|
#include "timer.h"
|
10
|
10
|
#include "cppm.h"
|
11
|
11
|
#include "rx.h"
|
12
|
|
-
|
13
|
|
-#ifdef DEBUG
|
14
|
|
-#include "serial.h"
|
15
|
|
-#endif
|
|
12
|
+#include "main.h"
|
16
|
13
|
|
17
|
14
|
void watchdogBoot(void) __attribute__((naked)) __attribute__((section(".init3")));
|
18
|
15
|
void watchdogBoot(void) {
|
|
@@ -20,31 +17,70 @@ void watchdogBoot(void) {
|
20
|
17
|
wdt_disable();
|
21
|
18
|
}
|
22
|
19
|
|
|
20
|
+#ifdef DEBUG
|
|
21
|
+void uartMenu(void) {
|
|
22
|
+ if (!serialHasChar(0)) {
|
|
23
|
+ return;
|
|
24
|
+ }
|
|
25
|
+
|
|
26
|
+ uint8_t c = serialGet(0);
|
|
27
|
+ time_t time = timerGet();
|
|
28
|
+ switch (c) {
|
|
29
|
+ case 't': case 'T':
|
|
30
|
+ debugWrite("Uptime: ");
|
|
31
|
+ serialWriteUnsigned64(0, time);
|
|
32
|
+ debugWrite("ms / ");
|
|
33
|
+ serialWriteUnsigned64(0, time / 1000);
|
|
34
|
+ debugWrite("s\n");
|
|
35
|
+ break;
|
|
36
|
+
|
|
37
|
+ case 'q': case 'Q':
|
|
38
|
+ debugWrite("Resetting...\n\n");
|
|
39
|
+ wdt_enable(WDTO_15MS);
|
|
40
|
+ for (;;) { }
|
|
41
|
+ break;
|
|
42
|
+
|
|
43
|
+ default:
|
|
44
|
+ debugWrite("Unknown command: '");
|
|
45
|
+ serialWrite(0, c);
|
|
46
|
+ debugWrite("'\n");
|
|
47
|
+
|
|
48
|
+ case 'h': case 'H': case '?':
|
|
49
|
+ debugWrite("Available commands:\n");
|
|
50
|
+ debugWrite(" h - Help\n");
|
|
51
|
+ debugWrite(" t - Time\n");
|
|
52
|
+ debugWrite(" q - Reset\n");
|
|
53
|
+ break;
|
|
54
|
+ }
|
|
55
|
+}
|
|
56
|
+#endif
|
|
57
|
+
|
23
|
58
|
void main(void) {
|
24
|
59
|
cppmInit();
|
25
|
60
|
timerInit();
|
26
|
61
|
|
27
|
62
|
#ifdef DEBUG
|
28
|
|
- serialInit(0, BAUD(19200, F_CPU));
|
|
63
|
+ serialInit(0, BAUD(38400, F_CPU));
|
29
|
64
|
#endif
|
30
|
65
|
|
31
|
66
|
sei(); // Enable interrupts (required for timer)
|
32
|
|
- wdt_enable(WDTO_250MS); // Trigger Watchdog after 250ms
|
|
67
|
+ //wdt_enable(WDTO_250MS); // Trigger Watchdog after 250ms
|
|
68
|
+ wdt_enable(WDTO_2S); // Trigger Watchdog after 2s
|
33
|
69
|
|
34
|
|
-#ifdef DEBUG
|
35
|
|
- serialWriteString(0, "RX reset.\n");
|
36
|
|
-#endif
|
|
70
|
+ debugWrite("RX reset.\n");
|
37
|
71
|
|
38
|
72
|
spiInit();
|
39
|
73
|
rxInit();
|
40
|
74
|
|
41
|
|
-#ifdef DEBUG
|
42
|
|
- serialWriteString(0, "RX ready!\n");
|
43
|
|
-#endif
|
|
75
|
+ debugWrite("RX ready!\n");
|
44
|
76
|
|
45
|
77
|
for(;;) {
|
46
|
78
|
wdt_reset();
|
47
|
79
|
rxReceivePacket();
|
|
80
|
+
|
|
81
|
+#ifdef DEBUG
|
|
82
|
+ uartMenu();
|
|
83
|
+#endif
|
48
|
84
|
}
|
49
|
85
|
}
|
50
|
86
|
|