Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed busy wait to wfe #604

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions rp2040-hal/src/sio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,13 @@ impl SioFifo {
pub fn read(&mut self) -> Option<u32> {
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
}
Expand All @@ -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.
Expand Down