6
6
//! Example configuration of Zephyr hardware watchdog with Memfault software watchdog
7
7
//! port such that a coredump is captured ahead of the hardware watchdog firing
8
8
9
- #include <zephyr.h>
10
- #include <device.h>
11
- #include <version.h>
9
+ #include "memfault/ports/watchdog.h"
12
10
11
+ #include <device.h>
13
12
#include <drivers/watchdog.h>
13
+ #include <version.h>
14
+ #include <zephyr.h>
14
15
15
16
#include "memfault/core/debug_log.h"
16
- #include "memfault/ports/watchdog.h"
17
17
18
18
//! Note: The timeout must be large enough to give us enough time to capture a coredump
19
19
//! before the system resets
20
20
#define MEMFAULT_WATCHDOG_HW_TIMEOUT_SECS (MEMFAULT_WATCHDOG_SW_TIMEOUT_SECS + 10)
21
21
22
- #define WDT_MAX_WINDOW (MEMFAULT_WATCHDOG_HW_TIMEOUT_SECS * 1000)
22
+ #define WDT_MAX_WINDOW (MEMFAULT_WATCHDOG_HW_TIMEOUT_SECS * 1000)
23
23
24
24
#define WATCHDOG_TASK_STACK_SIZE 512
25
25
K_THREAD_STACK_DEFINE (s_wdt_task_stack_area , WATCHDOG_TASK_STACK_SIZE );
@@ -32,10 +32,21 @@ static const struct device *s_wdt = NULL;
32
32
#endif
33
33
34
34
#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
36
36
#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)
39
50
#endif
40
51
41
52
static int s_wdt_channel_id = -1 ;
@@ -51,8 +62,8 @@ void memfault_demo_app_watchdog_feed(void) {
51
62
52
63
//! A basic watchdog implementation
53
64
//!
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
56
67
static void prv_wdt_task (void * arg1 , void * arg2 , void * arg3 ) {
57
68
while (1 ) {
58
69
k_sleep (K_SECONDS (1 ));
@@ -97,8 +108,6 @@ void memfault_demo_app_watchdog_boot(void) {
97
108
// cause the watchdog to not be fed
98
109
memfault_software_watchdog_enable ();
99
110
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 ,
103
112
K_LOWEST_APPLICATION_THREAD_PRIO , 0 , K_NO_WAIT );
104
113
}
0 commit comments