From 09f078a1cc33781a01012ebc43e9d20cff53e2a3 Mon Sep 17 00:00:00 2001 From: pennae Date: Thu, 4 May 2023 10:34:20 +0200 Subject: [PATCH] rp/pio: remove critical section in IrqFuture::poll there's nothing this critical section protects against. both read and write-to-clear are atomic and don't interfere with other irq futures, only potentially with setting/clearing an irq flag from an arm core. neither have ever been synchronized, and both have the same observable effects under atomic writes and critical sections. (for both setting and clearing an irq flag observable differences could only happen if the set/clear happened after the poll read, but before the write. if it's a clear we observe the same effects as sequencing the clear entirely after the poll, and if it's a set we observe the same effects as sequencing the set entirely before the poll) --- embassy-rp/src/pio.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/embassy-rp/src/pio.rs b/embassy-rp/src/pio.rs index 31273b5d..c2c144c0 100644 --- a/embassy-rp/src/pio.rs +++ b/embassy-rp/src/pio.rs @@ -191,17 +191,10 @@ impl<'a, 'd, PIO: Instance> Future for IrqFuture<'a, 'd, PIO> { //debug!("Poll {},{}", PIO::PIO_NO, SM); // Check if IRQ flag is already set - if critical_section::with(|_| unsafe { - let irq_flags = PIO::PIO.irq(); - if irq_flags.read().0 & (1 << self.irq_no) != 0 { - irq_flags.write(|m| { - m.0 = 1 << self.irq_no; - }); - true - } else { - false + if unsafe { PIO::PIO.irq().read().0 & (1 << self.irq_no) != 0 } { + unsafe { + PIO::PIO.irq().write(|m| m.0 = 1 << self.irq_no); } - }) { return Poll::Ready(()); }