summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMulin Chao <mlchao@nuvoton.com>2021-04-07 19:31:03 -0700
committerCommit Bot <commit-bot@chromium.org>2021-04-14 22:15:45 +0000
commit0e30757012ae4daaa97593a781f74d1bfd83e13d (patch)
tree5f973ca4da6106f85a08f9f7f5c84e6df94d9a3e
parentfd16f618fa1e34a8c007f6a66a1ff4c9e9ef0424 (diff)
downloadchrome-ec-0e30757012ae4daaa97593a781f74d1bfd83e13d.tar.gz
zephyr: Adjust watchdog warning timer value and delay time
Adjusts the watchdog warning timer value and its delay time definitions to meet original chromium ec behavior. The system handles the warning event at CONFIG_AUX_TIMER_PERIOD_MS & issues the watchdog reset event at CONFIG_WATCHDOG_PERIOD_MS. Zephyr NPCX watchdog provides a config WDT_NPCX_DELAY_CYCLES for watchdog timeout delay. Set the zephyr timeout to CONFIG_AUX_TIMER_PERIOD_MS as warning time. So the NPCX watchdog hardware issue reset event at CONFIG_AUX_TIMER_PERIOD_MS + WDT_NPCX_DELAY_CYCLES. BUG=b:184683548 BRANCH=none TEST=Build & boot ec on volteer. TEST= `waitms 1000` warning doesn't issue & ec doesn't reboot `waitms 1200` warning issue & ec doesn't reboot `waitms 1500` warning issue & ec doesn't reboot `waitms 1700` warning issue & ec reboot Cq-Depend: chromium:2813911 Signed-off-by: Mulin Chao <mlchao@nuvoton.com> Signed-off-by: Wealian Liao <whliao@nuvoton.corp-partner.google.com> Change-Id: Ibee9c18cd9d2bae6d34ee9366755dec99687c3d4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2814728 Reviewed-by: Wai-Hong Tam <waihong@google.com> Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org>
-rw-r--r--include/config.h2
-rw-r--r--zephyr/Kconfig9
-rw-r--r--zephyr/Kconfig.watchdog15
-rw-r--r--zephyr/shim/include/config_chip.h26
-rw-r--r--zephyr/shim/src/watchdog.c9
5 files changed, 40 insertions, 21 deletions
diff --git a/include/config.h b/include/config.h
index 561e31ec55..aa3c67c534 100644
--- a/include/config.h
+++ b/include/config.h
@@ -5963,7 +5963,7 @@
* reloads of the watchdog timer should be less than half of the watchdog
* period.
*/
-#if !defined(CONFIG_ZEPHYR) && defined(CONFIG_WATCHDOG)
+#ifdef CONFIG_WATCHDOG
#if (CONFIG_AUX_TIMER_PERIOD_MS) < ((HOOK_TICK_INTERVAL_MS) * 2)
#error "CONFIG_AUX_TIMER_PERIOD_MS must be at least 2x HOOK_TICK_INTERVAL_MS"
#endif
diff --git a/zephyr/Kconfig b/zephyr/Kconfig
index 0b5f1dc100..e5b617d9c3 100644
--- a/zephyr/Kconfig
+++ b/zephyr/Kconfig
@@ -560,7 +560,7 @@ config PLATFORM_EC_VSTORE_SLOT_COUNT
checking on resume. For this, one slot is enough.
menuconfig PLATFORM_EC_WATCHDOG
- bool "watchdog"
+ bool "Watchdog"
depends on WATCHDOG
default y
help
@@ -569,4 +569,11 @@ menuconfig PLATFORM_EC_WATCHDOG
system) gets starved for CPU time and isn't able to fire its
HOOK_TICK event.
+ Chromium EC system uses an auxiliary timer to handle the system
+ warning event. This leaves some time to the system for preparing &
+ printing the debug information. The interval between reloads of the
+ watchdog timer should be less than half of the auxiliary timer
+ (PLATFORM_EC_WATCHDOG_PERIOD_MS -
+ PLATFORM_EC_WATCHDOG_WARNING_LEADING_TIME_MS).
+
endif # PLATFORM_EC
diff --git a/zephyr/Kconfig.watchdog b/zephyr/Kconfig.watchdog
index 57951b6f12..be87e4bce5 100644
--- a/zephyr/Kconfig.watchdog
+++ b/zephyr/Kconfig.watchdog
@@ -10,7 +10,18 @@ config PLATFORM_EC_WATCHDOG_PERIOD_MS
help
Set the timeout of the watchdog timer. The watchdog timer reboots
the system if no one reloads the watchdog timer before the timeout.
- The interval between reloads of the watchdog timer should be less than
- half of the watchdog period.
+
+config PLATFORM_EC_WATCHDOG_WARNING_LEADING_TIME_MS
+ int "Leading time of the watchdog warning timer in ms"
+ default 500
+ depends on !WDT_NPCX
+ help
+ Set the leading time of the watchdog warning timer. Chromium EC system
+ uses an auxiliary timer to handle the system warning event. The
+ auxiliary timer period (CONFIG_AUX_TIMER_PERIOD_MS) is set to
+ PLATFORM_EC_WATCHDOG_PERIOD_MS -
+ PLATFORM_EC_WATCHDOG_WARNING_LEADING_TIME_MS.
+
+ For the NPCX chip, use WDT_NPCX_DELAY_CYCLES instead of this config.
endif # PLATFORM_EC_WATCHDOG
diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h
index d8ce653fe1..b6fcfd3517 100644
--- a/zephyr/shim/include/config_chip.h
+++ b/zephyr/shim/include/config_chip.h
@@ -58,13 +58,6 @@
/*
* ECOS specific options, not used in Zephyr.
*/
-
- /*
- * The Zephyr npcx watchdog driver provider a delay set by
- * CONFIG_WDT_NPCX_DELAY_CYCLES for displaying the warning message.
- * CONFIG_AUX_TIMER_PERIOD_MS isn't used by the Zephyr code.
- */
-#undef CONFIG_AUX_TIMER_PERIOD_MS
#undef CONFIG_CONSOLE_UART /* Only used by the Chromium EC chip drivers */
#undef CONFIG_I2C_MULTI_PORT_CONTROLLER /* Not required by I2C shim */
#undef CONFIG_IRQ_COUNT /* Only used by Chromium EC core drivers */
@@ -1326,14 +1319,23 @@
#undef CONFIG_WATCHDOG_PERIOD_MS
#ifdef CONFIG_PLATFORM_EC_WATCHDOG_PERIOD_MS
#define CONFIG_WATCHDOG_PERIOD_MS CONFIG_PLATFORM_EC_WATCHDOG_PERIOD_MS
+#endif
+
+#undef CONFIG_WATCHDOG_WARNING_LEADING_TIME_MS
+#if defined(CONFIG_PLATFORM_EC_WATCHDOG_WARNING_LEADING_TIME_MS) || \
+ defined(CONFIG_WDT_NPCX_DELAY_CYCLES)
/*
- * Chromium ec uses hook tick to reload the watchdog. Interval between reloads
- * of the watchdog timer should be less than half of the watchdog period.
+ * Note: NPCX wdt driver uses CONFIG_WDT_NPCX_DELAY_CYCLES to set the leading
+ * time of the watchdog warning timer.
*/
-#if (CONFIG_WATCHDOG_PERIOD_MS) < ((HOOK_TICK_INTERVAL_MS) * 2)
-#error "CONFIG_WATCHDOG_PERIOD_MS must be at least 2x HOOK_TICK_INTERVAL_MS"
+#ifdef CONFIG_WDT_NPCX_DELAY_CYCLES
+#define CONFIG_WATCHDOG_WARNING_LEADING_TIME_MS \
+ (CONFIG_WDT_NPCX_DELAY_CYCLES * 31)
+#else
+#define CONFIG_WATCHDOG_WARNING_LEADING_TIME_MS \
+ CONFIG_PLATFORM_EC_WATCHDOG_WARNING_LEADING_TIME_MS
+#endif
#endif
-#endif /* CONFIG_PLATFORM_EC_WATCHDOG_PERIOD_MS */
#undef CONFIG_VBOOT_EFS
#undef CONFIG_VBOOT_EFS2
diff --git a/zephyr/shim/src/watchdog.c b/zephyr/shim/src/watchdog.c
index 8487fd1d75..13d380bfcb 100644
--- a/zephyr/shim/src/watchdog.c
+++ b/zephyr/shim/src/watchdog.c
@@ -17,7 +17,7 @@ LOG_MODULE_REGISTER(watchdog_shim, LOG_LEVEL_ERR);
static void wdt_warning_handler(const struct device *wdt_dev, int channel_id)
{
/* TODO(b/176523207): watchdog warning message */
- LOG_INF("Watchdog is expired");
+ printk("Watchdog deadline is close!\n");
}
int watchdog_init(void)
@@ -36,12 +36,11 @@ int watchdog_init(void)
wdt_config.flags = WDT_FLAG_RESET_SOC;
/*
- * The Warning timer = CONFIG_WATCHDOG_PERIOD_MS.
- * The watchdog reset time
- * = CONFIG_WATCHDOG_PERIOD_MS + time of CONFIG_WDT_NPCX_DELAY_CYCLES
+ * Set the Warning timer as CONFIG_AUX_TIMER_PERIOD_MS.
+ * Then the watchdog reset time = CONFIG_WATCHDOG_PERIOD_MS.
*/
wdt_config.window.min = 0U;
- wdt_config.window.max = CONFIG_WATCHDOG_PERIOD_MS;
+ wdt_config.window.max = CONFIG_AUX_TIMER_PERIOD_MS;
wdt_config.callback = wdt_warning_handler;
err = wdt_install_timeout(wdt, &wdt_config);