66//! Example configuration of Zephyr hardware watchdog with Memfault software watchdog
77//! port such that a coredump is captured ahead of the hardware watchdog firing
88
9- #include <zephyr.h>
10- #include <device.h>
11- #include <version.h>
9+ #include "memfault/ports/watchdog.h"
1210
11+ #include <device.h>
1312#include <drivers/watchdog.h>
13+ #include <version.h>
14+ #include <zephyr.h>
1415
1516#include "memfault/core/debug_log.h"
16- #include "memfault/ports/watchdog.h"
1717
1818//! Note: The timeout must be large enough to give us enough time to capture a coredump
1919//! before the system resets
2020#define MEMFAULT_WATCHDOG_HW_TIMEOUT_SECS (MEMFAULT_WATCHDOG_SW_TIMEOUT_SECS + 10)
2121
22- #define WDT_MAX_WINDOW (MEMFAULT_WATCHDOG_HW_TIMEOUT_SECS * 1000)
22+ #define WDT_MAX_WINDOW (MEMFAULT_WATCHDOG_HW_TIMEOUT_SECS * 1000)
2323
2424#define WATCHDOG_TASK_STACK_SIZE 512
2525K_THREAD_STACK_DEFINE (s_wdt_task_stack_area , WATCHDOG_TASK_STACK_SIZE );
@@ -32,10 +32,21 @@ static const struct device *s_wdt = NULL;
3232#endif
3333
3434#if KERNEL_VERSION_MAJOR == 2 && KERNEL_VERSION_MINOR < 3
35- #define WDT_DEV_NAME DT_WDT_0_NAME
35+ #define WDT_DEV_NAME DT_WDT_0_NAME
3636#else
37- #define WDT_NODE DT_INST(0, nordic_nrf_watchdog)
38- #define WDT_DEV_NAME DT_LABEL(WDT_NODE)
37+ //! Watchdog device tree name changed in NCS v2.0.0 :
38+ //! https://github.com/nrfconnect/sdk-zephyr/blob/12ee4d5f4b99acef542ce3977cb9078fcbb36d82/dts/arm/nordic/nrf9160_common.dtsi#L368
39+ //! Pick the one that's available in the current SDK version.
40+ #if DT_HAS_COMPAT_STATUS_OKAY (nordic_nrf_wdt )
41+ #define WDT_NODE_NAME nordic_nrf_wdt
42+ #elif DT_HAS_COMPAT_STATUS_OKAY (nordic_nrf_watchdog )
43+ #define WDT_NODE_NAME nordic_nrf_watchdog
44+ #else
45+ #error "No compatible watchdog instance for this configuration!"
46+ #endif
47+
48+ #define WDT_NODE DT_INST(0, WDT_NODE_NAME)
49+ #define WDT_DEV_NAME DT_LABEL(WDT_NODE)
3950#endif
4051
4152static int s_wdt_channel_id = -1 ;
@@ -51,8 +62,8 @@ void memfault_demo_app_watchdog_feed(void) {
5162
5263//! A basic watchdog implementation
5364//!
54- //! Once Zephyr has a Software & Task watchdog in place, the example will be updated to make use of that
55- //! For more info about watchdog setup in general, see https://mflt.io/root-cause-watchdogs
65+ //! Once Zephyr has a Software & Task watchdog in place, the example will be updated to make use of
66+ //! that For more info about watchdog setup in general, see https://mflt.io/root-cause-watchdogs
5667static void prv_wdt_task (void * arg1 , void * arg2 , void * arg3 ) {
5768 while (1 ) {
5869 k_sleep (K_SECONDS (1 ));
@@ -97,8 +108,6 @@ void memfault_demo_app_watchdog_boot(void) {
97108 // cause the watchdog to not be fed
98109 memfault_software_watchdog_enable ();
99110 k_thread_create (& my_thread_data , s_wdt_task_stack_area ,
100- K_THREAD_STACK_SIZEOF (s_wdt_task_stack_area ),
101- prv_wdt_task ,
102- NULL , NULL , NULL ,
111+ K_THREAD_STACK_SIZEOF (s_wdt_task_stack_area ), prv_wdt_task , NULL , NULL , NULL ,
103112 K_LOWEST_APPLICATION_THREAD_PRIO , 0 , K_NO_WAIT );
104113}
0 commit comments