summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2021-10-11 12:50:25 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-03-28 18:17:32 +0000
commit5822c27c9775e21410e98ab72c64eb4c1b198e84 (patch)
tree504326d0830917b9a71af9f847a54b054b974d4e
parentb052c5d9ffebc48646a76922ed5711bf9a8d41dc (diff)
downloadchrome-ec-5822c27c9775e21410e98ab72c64eb4c1b198e84.tar.gz
npcx/timer: Unroll udelay
This patch flattens udelay by unrolling __hw_clock_source_read. This increases the chance that we record LR of the instruction near which an infinite loop happened. BUG=b:218982018,b:200593658 BRANCH= TEST=Sona. Run crash assert. Hack battery command to trigger WD reset. Verify LR points to the root causes. Change-Id: Ibd6cbcf18ab6d58c06ddfd19021058268289bf00 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> (cherry picked from commit cc1d30dd2bd3b92d29f5ffb942d016bc207e2ad0) Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3508422
-rw-r--r--chip/npcx/hwtimer.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/chip/npcx/hwtimer.c b/chip/npcx/hwtimer.c
index 76f1822a94..75b026c939 100644
--- a/chip/npcx/hwtimer.c
+++ b/chip/npcx/hwtimer.c
@@ -16,6 +16,7 @@
#include "console.h"
#include "task.h"
#include "timer.h"
+#include "registers.h"
#include "util.h"
/* Depth of event timer */
@@ -340,3 +341,23 @@ int __hw_clock_source_init(uint32_t start_t)
return NPCX_IRQ_ITIM32;
}
+
+/*
+ * Unrolled udelay. It preserves LR, which points to the root cause of WD crash.
+ */
+__override void udelay(unsigned us)
+{
+ uint32_t cnt, cnt2, t0;
+
+ cnt = NPCX_ITCNT32;
+ while ((cnt2 = NPCX_ITCNT32) != cnt)
+ cnt = cnt2;
+
+ t0 = TICK_ITIM32_MAX_CNT - cnt;
+
+ do {
+ cnt = NPCX_ITCNT32;
+ while ((cnt2 = NPCX_ITCNT32) != cnt)
+ cnt = cnt2;
+ } while (TICK_ITIM32_MAX_CNT - cnt - t0 <= us);
+}