Hi,
I'm using Zephyr with nrf52 and want to setup watchdog support with multiple channels (different timer settings for separate different threads).
I can add 1 channel, but adding two, get's me a fail, error.
This should not happen on the 52, it has support for at least 8 channels I see in the wdt spec for the chip.
I get error when creating the 2nd channel.
Code looks like this:
#define PERIPH_WATCHDOG_TIMEOUT_MS (30 * 1000U)
#define NETWORK_QUEUE_WATCHDOG_TIMEOUT_MS (10 * 1000U)
int watchdog_init()
{
int error_code = 0;
LOG_INF("Watchdog starting");
wdt = device_get_binding(WDT_DEV_NAME);
if (!wdt)
{
LOG_ERR("Cannot get WDT device\n");
return -ENXIO;
}
return error_code;
}
int watchdog_add_channel_timeout(u32_t timeout_ms)
{
/* Reset SoC when watchdog timer expires. */
struct wdt_timeout_cfg wdt_config;
wdt_config.flags = WDT_FLAG_RESET_SOC;
/* Expire watchdog after 30*1000 milliseconds. */
wdt_config.window.min = 0U;
wdt_config.window.max = timeout_ms; // 30 * 1000U;
/* Set up watchdog callback. Jump into it when watchdog expired. */
wdt_config.callback = wdt_callback;
int wdt_channel_id = wdt_install_timeout(wdt, &wdt_config);
if (wdt_channel_id == -ENOTSUP)
{
wdt_config.callback = NULL;
wdt_channel_id = wdt_install_timeout(wdt, &wdt_config);
}
if (wdt_channel_id < 0)
{
LOG_ERR("Watchdog install error");
return -ENXIO;
}
return wdt_channel_id;
}
int watchdog_start()
{
int error_code = wdt_setup(wdt, 0);
if (error_code < 0)
{
LOG_ERR("Watchdog setup error");
return error_code;
}
return error_code;
}
From main I setup like this:
main()
{
...
int error_code = watchdog_init();
if (error_code < 0)
{
LOG_ERR("Failed to init watchdog");
}
// install periph watchdog channel
int periph_channel_id = -1;
periph_channel_id = watchdog_add_channel_timeout(PERIPH_WATCHDOG_TIMEOUT_MS);
if (periph_channel_id < 0)
{
LOG_ERR("Failed to setup periph watchdog timer");
}
// install network_queue watchdog channel
int network_queue_channel_id = -1;
network_queue_channel_id = watchdog_add_channel_timeout(NETWORK_QUEUE_WATCHDOG_TIMEOUT_MS);
if (network_queue_channel_id < 0)
{
LOG_ERR("Failed to setup network_queue watchdog timer");
}
// Finally start the watchdog timer
watchdog_start();
...
}