diff options
| author | Adrian Wowk <[email protected]> | 2025-03-26 17:11:27 -0500 |
|---|---|---|
| committer | Adrian Wowk <[email protected]> | 2025-03-26 17:11:27 -0500 |
| commit | 1b6e563260ec2b00cb518e0e801222ebd1ba9902 (patch) | |
| tree | ac3cdedf0efe3ec78998ae9134444861c53020cd | |
| parent | 9edf5b7f049f95742b60b041e4443967d8a6b708 (diff) | |
rp/adc: fix potential race condition
This commit rearranges the Adc::wait_for_ready function to make sure
that wakers are registered before the interrupt is enabled, and keeps
enabling the interrupt until the ADC is ready
| -rw-r--r-- | embassy-rp/src/adc.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/embassy-rp/src/adc.rs b/embassy-rp/src/adc.rs index 8defb5231..1265a22a0 100644 --- a/embassy-rp/src/adc.rs +++ b/embassy-rp/src/adc.rs | |||
| @@ -205,11 +205,13 @@ impl<'d> Adc<'d, Async> { | |||
| 205 | 205 | ||
| 206 | fn wait_for_ready() -> impl Future<Output = ()> { | 206 | fn wait_for_ready() -> impl Future<Output = ()> { |
| 207 | let r = Self::regs(); | 207 | let r = Self::regs(); |
| 208 | r.inte().write(|w| w.set_fifo(true)); | ||
| 209 | compiler_fence(Ordering::SeqCst); | ||
| 210 | 208 | ||
| 211 | poll_fn(move |cx| { | 209 | poll_fn(move |cx| { |
| 212 | WAKER.register(cx.waker()); | 210 | WAKER.register(cx.waker()); |
| 211 | |||
| 212 | r.inte().write(|w| w.set_fifo(true)); | ||
| 213 | compiler_fence(Ordering::SeqCst); | ||
| 214 | |||
| 213 | if r.cs().read().ready() { | 215 | if r.cs().read().ready() { |
| 214 | return Poll::Ready(()); | 216 | return Poll::Ready(()); |
| 215 | } | 217 | } |
