13#include <zephyr/device.h>
14#include <zephyr/drivers/watchdog.h>
15#include <zephyr/kernel.h>
19#include <zephyr/logging/log.h>
24#define WDT_FEED_WORKER_DELAY_MS ((CONFIG_WATCHDOG_APPLICATION_TIMEOUT_SEC * 1000) / 2)
25#define WATCHDOG_TIMEOUT_MSEC (CONFIG_WATCHDOG_APPLICATION_TIMEOUT_SEC * 1000)
34 const struct device *
wdt;
60 __ASSERT(evt != NULL,
"Library event not found");
69 .wdt = DEVICE_DT_GET(DT_NODELABEL(
wdt)),
95 LOG_DBG(
"Feeding watchdog");
98 myPrintkE(
"Cannot feed watchdog. Error code: %d\n", err);
99 LOG_ERR(
"Cannot feed watchdog. Error code: %d", err);
117 static const struct wdt_timeout_cfg wdt_settings = {.window =
123 .flags = WDT_FLAG_RESET_SOC};
126 __ASSERT_NO_MSG(config != NULL);
127 __ASSERT_NO_MSG(data != NULL);
132 LOG_ERR(
"Cannot install watchdog timer! Error code: %d", data->
wdt_channel_id);
138 myPrintkI(
"Watchdog timeout installed. Timeout: %d Seconds\n", CONFIG_WATCHDOG_APPLICATION_TIMEOUT_SEC);
139 LOG_DBG(
"Watchdog timeout installed. Timeout: %d", CONFIG_WATCHDOG_APPLICATION_TIMEOUT_SEC);
152 __ASSERT_NO_MSG(config != NULL);
154 int err = wdt_setup(config->
wdt, WDT_OPT_PAUSE_HALTED_BY_DBG);
157 myPrintkE(
"Cannot start watchdog! Error code: %d\n", err);
158 LOG_ERR(
"Cannot start watchdog! Error code: %d", err);
161 LOG_DBG(
"Watchdog started");
183 __ASSERT_NO_MSG(config != NULL);
184 __ASSERT_NO_MSG(data != NULL);
198 LOG_ERR(
"Cannot feed watchdog. Error code: %d", err);
226 __ASSERT_NO_MSG(data != NULL);
228 if (!device_is_ready(config->
wdt)) {
229 myPrintkI(
"Watchdog device not ready\n");
230 LOG_ERR(
"Watchdog device not ready");
263 LOG_INF(
"start watchdog\n");
264 LOG_WRN(
"start watchdog\n");
265 LOG_DBG(
"start watchdog\n");
266 LOG_INF(
"start watchdog\n");
270 myPrintkE(
"Failed to enable watchdog, error: %d\n", err);
271 LOG_ERR(
"Failed to enable watchdog, error: %d", err);
292 if (evt_handler == NULL) {
296 LOG_DBG(
"Previously registered handler %p de-registered",
app_evt_handler);
301 myPrintkI(
"Registering handler %p\n", evt_handler);
302 LOG_DBG(
"Registering handler %p", evt_handler);
uint8_t stopWDTFeed
stop Watch Dog Timer feed causing a WDT interrupt for testing
common struct, enum, externs, prototypes
int myPrintkI(char *restrict fmt,...)
prints an information message to the UART
int myPrintkE(char *restrict fmt,...)
prints an error message to the UART
enum watchdog_evt_type type
Watchdog configuration storage.
const struct device * wdt
Watchdog runtime data storage.
struct k_work_delayable system_workqueue_work
static int watchdog_start(const struct wdt_config_storage *config)
Starts the watchdog timer hardware instance.
static int watchdog_enable(const struct wdt_config_storage *config, struct wdt_data_storage *data)
Enable and initialize the watchdog: verify device readiness, install the timeout, start the watchdog ...
static int watchdog_feed_enable(const struct wdt_config_storage *config, struct wdt_data_storage *data)
Enable periodic feeding of the hardware watchdog.
int watchdog_init_and_start(void)
Initialize and start the watchdog timer.
static void watchdog_notify_event(const struct watchdog_evt *evt)
Notify the registered watchdog event handler of an event.
LOG_MODULE_REGISTER(watchdog_app)
#define WDT_FEED_WORKER_DELAY_MS
static const struct wdt_config_storage wdt_config
Watchdog device configuration storage.
static struct wdt_data_storage wdt_data
static watchdog_evt_handler_t app_evt_handler
Registered application event handler.
static void primary_feed_worker(struct k_work *work_desc)
Primary watchdog feeding work handler.
static int watchdog_timeout_install(const struct wdt_config_storage *config, struct wdt_data_storage *data)
Installs a watchdog timeout configuration and registers it with the WDT device.
#define WATCHDOG_TIMEOUT_MSEC
static bool init_and_start
Flag set when the library has been initialized and started. */.
void watchdog_register_handler(watchdog_evt_handler_t evt_handler)
Register handler to receive watchdog callback events.
Watchdog module for Asset Tracker v2.
void(* watchdog_evt_handler_t)(const struct watchdog_evt *evt)
Watchdog library event handler.
@ WATCHDOG_EVT_TIMEOUT_INSTALLED