summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);