summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorPatryk Duda <pdk@semihalf.com>2021-06-10 13:59:51 +0200
committerCommit Bot <commit-bot@chromium.org>2021-09-08 22:45:07 +0000
commit6b1c5a80aa337696c6ceb145e7de00f05b65ec04 (patch)
tree5cefb200e7f15dec15bce5512ec73c1350b418af /common
parentb35f8f07daaf148ffc4039c33f2fedcc4cb42cc2 (diff)
downloadchrome-ec-6b1c5a80aa337696c6ceb145e7de00f05b65ec04.tar.gz
common/timer: Fallback to udelay when interrupt conditions are not met
To call usleep() we must be sure that interrupts are enabled and we are not in interrupt context. This is required because hardware timer is used to make sleeping task ready. Also on Cortex-M task switching is not working properly when interrupts are disabled. If above conditions are not met, just print warning and use udelay(). BUG=b:190597666 BRANCH=none TEST=make -j buildall TEST=Call usleep() when interrupts are disabled and make sure that warning is printed and EC doesn't crash. One can implement console command to test this. Perform this test on following cores: cortex-m - this is the most common core, eg. bloonchipper minute-ia - this is used for Intel Sensor Hub (cros_ish) eg. drallion board riscv-rv32i - hayato (asurada family) has EC chip based on risc-v nds32 - ampton (octopus family) has EC chip based on it Signed-off-by: Patryk Duda <pdk@semihalf.com> Change-Id: Ia38ef0f0511ca1298d3153fa77e169019f4c4c31 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2953235 Tested-by: Patryk Duda <patrykd@google.com> Commit-Queue: Marcin Wojtas <mwojtas@google.com> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/timer.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/common/timer.c b/common/timer.c
index d0d3c80024..22cff4a325 100644
--- a/common/timer.c
+++ b/common/timer.c
@@ -23,6 +23,14 @@ extern __error("k_usleep() should only be called from Zephyr code")
int32_t k_usleep(int32_t);
#endif /* CONFIG_ZEPHYR */
+#ifdef CONFIG_COMMON_RUNTIME
+#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ## args)
+#else
+#define CPRINTS(format, args...)
+#define CPRINTF(format, args...)
+#endif
+
#define TIMER_SYSJUMP_TAG 0x4d54 /* "TM" */
/* High 32-bits of the 64-bit timestamp counter. */
@@ -181,6 +189,13 @@ void usleep(unsigned us)
return;
}
+ /* If in interrupt context or interrupts are disabled, use udelay() */
+ if (!is_interrupt_enabled() || in_interrupt_context()) {
+ CPRINTS("Sleeping not allowed");
+ udelay(us);
+ return;
+ }
+
ASSERT(us);
do {
evt |= task_wait_event(us);