|
11 | 11 | #include <memfault_ncs.h>
|
12 | 12 | #include <stdio.h>
|
13 | 13 |
|
| 14 | +#include "memfault/ports/watchdog.h" |
| 15 | + |
14 | 16 | LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);
|
15 | 17 |
|
16 | 18 | //! wrapper to enclose logic around log_strdup
|
@@ -51,11 +53,42 @@ static void prv_set_device_id(void) {
|
51 | 53 | memfault_ncs_device_id_set(dev_str, length * 2);
|
52 | 54 | }
|
53 | 55 |
|
| 56 | +#define WD_FEED_THREAD_STACK_SIZE 500 |
| 57 | +// set priority to lowest application thread; shell_uart, where the 'mflt test |
| 58 | +// hang' command runs from, uses the same priority by default, so this should |
| 59 | +// not preempt it and correctly trip the watchdog |
| 60 | +#if CONFIG_SHELL_THREAD_PRIORITY_OVERRIDE |
| 61 | + #error "Watchdog feed thread priority must be lower than shell thread priority" |
| 62 | +#endif |
| 63 | +#define WD_FEED_THREAD_PRIORITY K_LOWEST_APPLICATION_THREAD_PRIO |
| 64 | + |
| 65 | +static void prv_wd_feed_thread_function(void *arg0, void *arg1, void *arg2) { |
| 66 | + ARG_UNUSED(arg0); |
| 67 | + ARG_UNUSED(arg1); |
| 68 | + ARG_UNUSED(arg2); |
| 69 | + |
| 70 | + while (1) { |
| 71 | + memfault_software_watchdog_feed(); |
| 72 | + k_sleep(K_SECONDS(1)); |
| 73 | + } |
| 74 | +} |
| 75 | +K_THREAD_DEFINE(wd_feed_thread, WD_FEED_THREAD_STACK_SIZE, prv_wd_feed_thread_function, NULL, NULL, |
| 76 | + NULL, WD_FEED_THREAD_PRIORITY, 0, 0); |
| 77 | + |
| 78 | +static void prv_start_watchdog_feed_thread(void) { |
| 79 | + LOG_INF("starting watchdog feed thread 🐶"); |
| 80 | + memfault_software_watchdog_enable(); |
| 81 | + k_thread_name_set(wd_feed_thread, "wd_feed_thread"); |
| 82 | + k_thread_start(wd_feed_thread); |
| 83 | +} |
| 84 | + |
54 | 85 | void main(void) {
|
55 | 86 | LOG_INF("Booting Memfault sample app!");
|
56 | 87 |
|
57 | 88 | // Set the device id based on the hardware UID
|
58 | 89 | prv_set_device_id();
|
59 | 90 |
|
60 | 91 | memfault_device_info_dump();
|
| 92 | + |
| 93 | + prv_start_watchdog_feed_thread(); |
61 | 94 | }
|
0 commit comments