summaryrefslogtreecommitdiff
path: root/chip/npcx/clock.c
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2016-11-09 10:23:17 -0800
committerchrome-bot <chrome-bot@chromium.org>2016-11-09 21:14:09 -0800
commit92d91adbdb38e5639c200ad65c4651274a8d07f9 (patch)
tree31b9b70ff6484ba67b7e7945c01d0eee81909da0 /chip/npcx/clock.c
parentebdb6a62aa46f144bdb24da2eea3677ba4329482 (diff)
downloadchrome-ec-92d91adbdb38e5639c200ad65c4651274a8d07f9.tar.gz
npcx: hwtimer: Fix 'slow' timer count just before overflow
If our 32-bit usec timer is close to overflow, we may deep sleep several times in succession without making any adjustment to our count, causing deadlines on the other side (eg. HOOK_TICK expiration) to be reached much slower than expected. Avoid this by not entering deep sleep if our timer is about to overflow. This will result in a <= HOOK_TICK_INTERVAL (200ms interval) period of not entering deep sleep, every ~4300 seconds. BUG=chrome-os-partner:59240 BRANCH=gru TEST=Verify 3x kevin units survive 16 hours in S3 without EC watchdog. Change-Id: I2126458be8820f78212e19c2bb79242ff1194f6f Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/409673 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'chip/npcx/clock.c')
-rw-r--r--chip/npcx/clock.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/chip/npcx/clock.c b/chip/npcx/clock.c
index 718d7733b7..196248c592 100644
--- a/chip/npcx/clock.c
+++ b/chip/npcx/clock.c
@@ -312,6 +312,13 @@ void __idle(void)
/* Do we have enough time before next event to deep sleep. */
if (DEEP_SLEEP_ALLOWED &&
+ /*
+ * Our HW timer doesn't tick in deep sleep - we do manual
+ * adjustment based on sleep duration after wake. Avoid
+ * the tricky overflow case by waiting out the period just
+ * before overflow.
+ */
+ next_evt != EVT_MAX_EXPIRED_US &&
/* Ensure event hasn't already expired */
next_evt > t0.le.lo &&
/* Ensure we have sufficient time before expiration */