From dbbdd3c6cfe05ac45c2f1028f07696b23a85c8f6 Mon Sep 17 00:00:00 2001 From: Declan Snyder Date: Mon, 11 Sep 2023 11:49:52 -0500 Subject: [PATCH] drivers: wdt_mcux_wwdt: Fix warning callback Warning callback by default is configured to happen at the same time as reset, which results in unexpected behavior from the point of view of Zephyr API. Return -ENOTSUP from install_timeout if trying to set up callback with 0 warning time, and add kconfig to configure the warning time. Signed-off-by: Declan Snyder --- drivers/watchdog/Kconfig.mcux | 12 ++++++++++++ drivers/watchdog/wdt_mcux_wwdt.c | 11 +++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/watchdog/Kconfig.mcux b/drivers/watchdog/Kconfig.mcux index 805aae1cb32..c4b5a4d7fdd 100644 --- a/drivers/watchdog/Kconfig.mcux +++ b/drivers/watchdog/Kconfig.mcux @@ -25,3 +25,15 @@ config WDT_MCUX_WWDT depends on DT_HAS_NXP_LPC_WWDT_ENABLED help Enable the mcux wwdt driver. + +if WDT_MCUX_WWDT + +config WDT_MCUX_WWDT_WARNING_INTERRUPT_CFG + int "WWDT timeout warning interrupt configuration" + range 0 1023 + default 0 + help + WWDT timeout warning interrupt time. The units are + the number of watchdog counter ticks before timeout. + +endif # WDT_MCUX_WWDT diff --git a/drivers/watchdog/wdt_mcux_wwdt.c b/drivers/watchdog/wdt_mcux_wwdt.c index cef55b320a5..0181b3d406f 100644 --- a/drivers/watchdog/wdt_mcux_wwdt.c +++ b/drivers/watchdog/wdt_mcux_wwdt.c @@ -69,7 +69,7 @@ static int mcux_wwdt_disable(const struct device *dev) * This prescaler is different from the clock divider specified in Device Tree. */ #define MSEC_TO_WWDT_TICKS(clock_freq, msec) \ - ((uint32_t)(clock_freq * msec / MSEC_PER_SEC / 4)) + ((uint32_t)((clock_freq / MSEC_PER_SEC) * msec) / 4) static int mcux_wwdt_install_timeout(const struct device *dev, const struct wdt_timeout_cfg *cfg) @@ -115,7 +115,14 @@ static int mcux_wwdt_install_timeout(const struct device *dev, LOG_DBG("Enabling SoC reset"); } - data->callback = cfg->callback; + if (cfg->callback && (CONFIG_WDT_MCUX_WWDT_WARNING_INTERRUPT_CFG > 0)) { + data->callback = cfg->callback; + data->wwdt_config.warningValue = CONFIG_WDT_MCUX_WWDT_WARNING_INTERRUPT_CFG; + } else if (cfg->callback) { + return -ENOTSUP; + } + + data->timeout_valid = true; LOG_DBG("Installed timeout (timeoutValue = %d)", data->wwdt_config.timeoutValue);