cchoi22915 I’ll try to do a live session on this. It’s straight forward though, especially on the nRF52/91
/*
* Copyright (c) 2021 Circuit Dojo LLC
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <drivers/watchdog.h>
#include <watchdog.h>
#include <logging/log.h>
LOG_MODULE_REGISTER(app_watchdog);
static const struct device *wdt = DEVICE_DT_GET(DT_NODELABEL(wdt0));
static int wdt_channel_id;
int app_watchdog_setup()
{
int err;
if (!device_is_ready(wdt) || wdt == NULL)
{
LOG_WRN("Watchdog not ready");
return -EIO;
}
struct wdt_timeout_cfg wdt_config = {
/* Reset SoC when watchdog timer expires. */
.flags = WDT_FLAG_RESET_SOC,
/* Expire watchdog after max window */
.window.min = 0U,
.window.max = WDT_MAX_WINDOW};
wdt_channel_id = wdt_install_timeout(wdt, &wdt_config);
if (wdt_channel_id < 0)
{
LOG_ERR("Watchdog install error.");
return wdt_channel_id;
}
err = wdt_setup(wdt, WDT_OPT_PAUSE_HALTED_BY_DBG);
if (err)
{
LOG_ERR("Watchdog setup error");
return err;
}
return 0;
}
void app_watchdog_feed()
{
wdt_feed(wdt, wdt_channel_id);
}
First you set it up and then you feed it on whatever interval. That WDT_MAX_WINDOW sets the timeout in milliseconds. Make sure that wdt0
in your device overlay is set to status = "okay";