From ecd08a87a9571776927499156b9931b602b2b716 Mon Sep 17 00:00:00 2001 From: Charles Thompson Date: Sun, 7 May 2023 13:22:55 -0400 Subject: [PATCH] Changed busy wait to wfe --- rp2040-hal/src/sio.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/rp2040-hal/src/sio.rs b/rp2040-hal/src/sio.rs index 9238dd3f6..5d206d9c0 100644 --- a/rp2040-hal/src/sio.rs +++ b/rp2040-hal/src/sio.rs @@ -137,7 +137,13 @@ impl SioFifo { pub fn read(&mut self) -> Option { if self.is_read_ready() { let sio = unsafe { &(*pac::SIO::ptr()) }; - Some(sio.fifo_rd.read().bits()) + + let value = sio.fifo_rd.read().bits(); + + // Wake up the other core that might be waiting on a read + cortex_m::asm::sev(); + + Some(value) } else { None } @@ -152,17 +158,14 @@ impl SioFifo { /// Push to the FIFO, spinning if there's no space. pub fn write_blocking(&mut self, value: u32) { - // We busy-wait for the FIFO to have some space + // We wait for the FIFO to have some space while !self.is_write_ready() { - cortex_m::asm::nop(); + cortex_m::asm::wfe(); } // Write the value to the FIFO - the other core will now be able to // pop it off its end of the FIFO. self.write(value); - - // Fire off an event to the other core - cortex_m::asm::sev(); } /// Pop from the FIFO, spinning if there's currently no data.