|
13 | 13 | #include <version.h> |
14 | 14 | #include <zephyr.h> |
15 | 15 |
|
16 | | -#include "memfault/core/debug_log.h" |
| 16 | +#include "memfault/components.h" |
| 17 | + |
| 18 | +#include "memfault/ports/zephyr/version.h" |
17 | 19 |
|
18 | 20 | //! Note: The timeout must be large enough to give us enough time to capture a coredump |
19 | 21 | //! before the system resets |
|
25 | 27 | K_THREAD_STACK_DEFINE(s_wdt_task_stack_area, WATCHDOG_TASK_STACK_SIZE); |
26 | 28 | struct k_thread my_thread_data; |
27 | 29 |
|
28 | | -#if KERNEL_VERSION_MAJOR == 2 && KERNEL_VERSION_MINOR < 2 |
29 | | -static struct device *s_wdt = NULL; |
30 | | -#else |
| 30 | +#if MEMFAULT_ZEPHYR_VERSION_GT(3,1) |
| 31 | +// Between Zephyr 3.1 and 3.2, "label" properties in DTS started to get phased out: |
| 32 | +// https://github.com/zephyrproject-rtos/zephyr/pull/48360 |
| 33 | +// |
| 34 | +// This breaks support for accessing device tree information via device_get_binding / DT_LABEL |
| 35 | +// properties. The new preferred approach is accessing resources via the DEVICE_DT_GET macro |
| 36 | +static const struct device *s_wdt = DEVICE_DT_GET(DT_NODELABEL(wdt)); |
| 37 | + |
| 38 | +#elif MEMFAULT_ZEPHYR_VERSION_GT(2,1) |
31 | 39 | static const struct device *s_wdt = NULL; |
| 40 | +#else // Zephyr Kernel <= 2.1 |
| 41 | +static struct device *s_wdt = NULL; |
32 | 42 | #endif |
33 | 43 |
|
34 | 44 | #if KERNEL_VERSION_MAJOR == 2 && KERNEL_VERSION_MINOR < 3 |
@@ -75,11 +85,18 @@ static void prv_wdt_task(void *arg1, void *arg2, void *arg3) { |
75 | 85 | void memfault_demo_app_watchdog_boot(void) { |
76 | 86 | MEMFAULT_LOG_DEBUG("Initializing WDT Subsystem"); |
77 | 87 |
|
| 88 | +#if MEMFAULT_ZEPHYR_VERSION_GT(3,1) |
| 89 | + if (!device_is_ready(s_wdt)) { |
| 90 | + printk("Watchdog device not ready"); |
| 91 | + return; |
| 92 | + } |
| 93 | +#else // Zephyr <= 3.1 |
78 | 94 | s_wdt = device_get_binding(WDT_DEV_NAME); |
79 | 95 | if (s_wdt == NULL) { |
80 | 96 | printk("No WDT device available\n"); |
81 | 97 | return; |
82 | 98 | } |
| 99 | +#endif |
83 | 100 |
|
84 | 101 | struct wdt_timeout_cfg wdt_config = { |
85 | 102 | /* Reset SoC when watchdog timer expires. */ |
|
0 commit comments