|
5 | 5 | #include <hardware/gpio.h>
|
6 | 6 | #include <hardware/spi.h>
|
7 | 7 | #include <hardware/dma.h>
|
| 8 | +#include <hardware/watchdog.h> |
8 | 9 | #include <pico/cyw43_arch.h>
|
9 | 10 |
|
10 | 11 | #include <FreeRTOS.h>
|
@@ -49,6 +50,9 @@ int main(void)
|
49 | 50 | {
|
50 | 51 | stdio_init_all();
|
51 | 52 |
|
| 53 | + // Let USB UART wake up on a listener. |
| 54 | + sleep_ms(1000); |
| 55 | + |
52 | 56 | DEBUG_printf("Hello, matrix here\n");
|
53 | 57 |
|
54 | 58 | srand(0);
|
@@ -83,6 +87,14 @@ void animate_task(void *dummy)
|
83 | 87 | DEBUG_printf("%s: core%u\n", pcTaskGetName(NULL), get_core_num());
|
84 | 88 | #endif
|
85 | 89 |
|
| 90 | + if (watchdog_enable_caused_reboot()) { |
| 91 | + DEBUG_printf("Restart caused by watchdog!\n"); |
| 92 | + } else { |
| 93 | + DEBUG_printf("Clean start; not caused by watchdog\n"); |
| 94 | + } |
| 95 | + |
| 96 | + bool watchdog_enabled = false; |
| 97 | + |
86 | 98 | message_anim_t message;
|
87 | 99 | memset(&message, 0, sizeof(message_anim_t));
|
88 | 100 |
|
@@ -123,6 +135,18 @@ void animate_task(void *dummy)
|
123 | 135 | break;
|
124 | 136 |
|
125 | 137 | case MESSAGE_ANIM_DS3231:
|
| 138 | + if (! watchdog_enabled) { |
| 139 | + // On the first message from the RTC task, Enable the watchdog |
| 140 | + // requiring the watchdog to be updated every 2s or the MCU will |
| 141 | + // reboot. |
| 142 | + watchdog_enable(2000, 1); |
| 143 | + watchdog_enabled = true; |
| 144 | + DEBUG_printf("Watchdog enabled\n"); |
| 145 | + } |
| 146 | + else { |
| 147 | + // We must now get a new time every two seconds or we will reboot |
| 148 | + watchdog_update(); |
| 149 | + } |
126 | 150 | anim.new_ds3231(&message.ds3231);
|
127 | 151 | break;
|
128 | 152 |
|
|
0 commit comments