summaryrefslogtreecommitdiff
path: root/chip/npcx/hwtimer.c
diff options
context:
space:
mode:
Diffstat (limited to 'chip/npcx/hwtimer.c')
-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);
+}