From 7ed83dd2d364261da24f7579483d6f3a9ec60951 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Fri, 15 Dec 2023 13:36:51 +0000 Subject: [PATCH] Add calls to tight_loop_contents in a few more places. (#1401) Fixes #1290 --- src/rp2_common/hardware_sync/include/hardware/sync.h | 4 +++- src/rp2_common/hardware_xosc/xosc.c | 12 +++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/rp2_common/hardware_sync/include/hardware/sync.h b/src/rp2_common/hardware_sync/include/hardware/sync.h index b15f36bc4..35bd783e0 100644 --- a/src/rp2_common/hardware_sync/include/hardware/sync.h +++ b/src/rp2_common/hardware_sync/include/hardware/sync.h @@ -262,7 +262,9 @@ __force_inline static void spin_lock_unsafe_blocking(spin_lock_t *lock) { // Note we don't do a wfe or anything, because by convention these spin_locks are VERY SHORT LIVED and NEVER BLOCK and run // with INTERRUPTS disabled (to ensure that)... therefore nothing on our core could be blocking us, so we just need to wait on another core // anyway which should be finished soon - while (__builtin_expect(!*lock, 0)); + while (__builtin_expect(!*lock, 0)) { + tight_loop_contents(); + } __mem_fence_acquire(); } diff --git a/src/rp2_common/hardware_xosc/xosc.c b/src/rp2_common/hardware_xosc/xosc.c index 03e6785b3..e22602213 100644 --- a/src/rp2_common/hardware_xosc/xosc.c +++ b/src/rp2_common/hardware_xosc/xosc.c @@ -37,7 +37,9 @@ void xosc_init(void) { hw_set_bits(&xosc_hw->ctrl, XOSC_CTRL_ENABLE_VALUE_ENABLE << XOSC_CTRL_ENABLE_LSB); // Wait for XOSC to be stable - while(!(xosc_hw->status & XOSC_STATUS_STABLE_BITS)); + while(!(xosc_hw->status & XOSC_STATUS_STABLE_BITS)) { + tight_loop_contents(); + } } void xosc_disable(void) { @@ -46,12 +48,16 @@ void xosc_disable(void) { tmp |= (XOSC_CTRL_ENABLE_VALUE_DISABLE << XOSC_CTRL_ENABLE_LSB); xosc_hw->ctrl = tmp; // Wait for stable to go away - while(xosc_hw->status & XOSC_STATUS_STABLE_BITS); + while(xosc_hw->status & XOSC_STATUS_STABLE_BITS) { + tight_loop_contents(); + } } void xosc_dormant(void) { // WARNING: This stops the xosc until woken up by an irq xosc_hw->dormant = XOSC_DORMANT_VALUE_DORMANT; // Wait for it to become stable once woken up - while(!(xosc_hw->status & XOSC_STATUS_STABLE_BITS)); + while(!(xosc_hw->status & XOSC_STATUS_STABLE_BITS)) { + tight_loop_contents(); + } }