summaryrefslogtreecommitdiff
path: root/chip/npcx/watchdog.c
diff options
context:
space:
mode:
authorJett Rink <jettrink@chromium.org>2019-09-06 11:33:48 -0600
committerCommit Bot <commit-bot@chromium.org>2019-09-12 05:04:17 +0000
commit031c5d2d62dd891622ded885756c03021e934ef2 (patch)
treebddaeeeb33e89134f538795d050d5874649ef90f /chip/npcx/watchdog.c
parent8d9ddb34ed3465e5172c6d950a155c83dd6d5aa9 (diff)
downloadchrome-ec-031c5d2d62dd891622ded885756c03021e934ef2.tar.gz
npcx: ensure we don't unlock watchdog too soon
We cannot unlock the watchdog timer with 3 watch dog ticks of touching it per the datasheet. This is actually around 100ms so we should protect against this. BRANCH=none BUG=b:140207603 TEST=eliminates cold reset issue. Change-Id: Iaef59dad9f5640d64d5d430aea87bd16c2efd30d Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1790302 Reviewed-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org> Reviewed-by: ML Chao <mlchao@nuvoton.corp-partner.google.com> Reviewed-by: Furquan Shaikh <furquan@chromium.org> Tested-by: Furquan Shaikh <furquan@chromium.org> Commit-Queue: Furquan Shaikh <furquan@chromium.org>
Diffstat (limited to 'chip/npcx/watchdog.c')
-rw-r--r--chip/npcx/watchdog.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/chip/npcx/watchdog.c b/chip/npcx/watchdog.c
index 44a980326b..233c875643 100644
--- a/chip/npcx/watchdog.c
+++ b/chip/npcx/watchdog.c
@@ -58,6 +58,27 @@ static uint8_t watchdog_count(void)
return cnt;
}
+static timestamp_t last_watchdog_touch;
+void watchdog_stop_and_unlock(void)
+{
+ /*
+ * Ensure we have waited at least 3 watchdog ticks since touching WD
+ * timer. 3 / (32768 / 1024) HZ = 93.75ms
+ */
+ while (time_since32(last_watchdog_touch) < (100 * MSEC))
+ continue;
+
+ NPCX_WDSDM = 0x87;
+ NPCX_WDSDM = 0x61;
+ NPCX_WDSDM = 0x63;
+}
+
+static void touch_watchdog_count(void)
+{
+ NPCX_WDSDM = 0x5C;
+ last_watchdog_touch = get_time();
+}
+
void __keep watchdog_check(uint32_t excep_lr, uint32_t excep_sp)
{
int wd_cnt;
@@ -75,7 +96,8 @@ void __keep watchdog_check(uint32_t excep_lr, uint32_t excep_sp)
* Touch watchdog to let UART have enough time
* to print panic info
*/
- NPCX_WDSDM = 0x5C;
+ touch_watchdog_count();
+
/* Print panic info */
watchdog_trace(excep_lr, excep_sp);
cflush();
@@ -112,7 +134,7 @@ void watchdog_reload(void)
#if 1 /* mark this for testing watchdog */
/* Touch watchdog & reset software counter */
- NPCX_WDSDM = 0x5C;
+ touch_watchdog_count();
#endif
/* Enable watchdog interrupt */
@@ -125,7 +147,7 @@ int watchdog_init(void)
#if SUPPORT_WDG
/* Touch watchdog before init if it is already running */
if (IS_BIT_SET(NPCX_T0CSR, NPCX_T0CSR_WD_RUN))
- NPCX_WDSDM = 0x5C;
+ touch_watchdog_count();
/* Keep prescaler ratio timer0 clock to 1:1024 */
NPCX_TWCP = 0x0A;