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);