diff options
| author | James Munns <[email protected]> | 2025-04-03 19:01:00 +0200 |
|---|---|---|
| committer | James Munns <[email protected]> | 2025-04-03 19:01:00 +0200 |
| commit | 72832c1550201dba4629ee861b84143502465064 (patch) | |
| tree | bbe9ef5e9e67a4a1a275becc418bb19b0e1f6333 /embassy-rp | |
| parent | 99536219a3d83f53c32c37ff92175e278000221a (diff) | |
embassy-rp: defensive change to ensure wakers are registered
This change ensures that wakers are registered PRIOR to checking status
in i2c `wait_on` helpers.
Diffstat (limited to 'embassy-rp')
| -rw-r--r-- | embassy-rp/src/i2c.rs | 6 | ||||
| -rw-r--r-- | embassy-rp/src/i2c_slave.rs | 6 |
2 files changed, 8 insertions, 4 deletions
diff --git a/embassy-rp/src/i2c.rs b/embassy-rp/src/i2c.rs index adc38b73d..a983b7bc3 100644 --- a/embassy-rp/src/i2c.rs +++ b/embassy-rp/src/i2c.rs | |||
| @@ -114,17 +114,19 @@ impl<'d, T: Instance> I2c<'d, T, Async> { | |||
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | /// Calls `f` to check if we are ready or not. | 116 | /// Calls `f` to check if we are ready or not. |
| 117 | /// If not, `g` is called once the waker is set (to eg enable the required interrupts). | 117 | /// If not, `g` is called once(to eg enable the required interrupts). |
| 118 | /// The waker will always be registered prior to calling `f`. | ||
| 118 | async fn wait_on<F, U, G>(&mut self, mut f: F, mut g: G) -> U | 119 | async fn wait_on<F, U, G>(&mut self, mut f: F, mut g: G) -> U |
| 119 | where | 120 | where |
| 120 | F: FnMut(&mut Self) -> Poll<U>, | 121 | F: FnMut(&mut Self) -> Poll<U>, |
| 121 | G: FnMut(&mut Self), | 122 | G: FnMut(&mut Self), |
| 122 | { | 123 | { |
| 123 | future::poll_fn(|cx| { | 124 | future::poll_fn(|cx| { |
| 125 | // Register prior to checking the condition | ||
| 126 | T::waker().register(cx.waker()); | ||
| 124 | let r = f(self); | 127 | let r = f(self); |
| 125 | 128 | ||
| 126 | if r.is_pending() { | 129 | if r.is_pending() { |
| 127 | T::waker().register(cx.waker()); | ||
| 128 | g(self); | 130 | g(self); |
| 129 | } | 131 | } |
| 130 | r | 132 | r |
diff --git a/embassy-rp/src/i2c_slave.rs b/embassy-rp/src/i2c_slave.rs index d420030d8..7bc14511d 100644 --- a/embassy-rp/src/i2c_slave.rs +++ b/embassy-rp/src/i2c_slave.rs | |||
| @@ -159,7 +159,8 @@ impl<'d, T: Instance> I2cSlave<'d, T> { | |||
| 159 | } | 159 | } |
| 160 | 160 | ||
| 161 | /// Calls `f` to check if we are ready or not. | 161 | /// Calls `f` to check if we are ready or not. |
| 162 | /// If not, `g` is called once the waker is set (to eg enable the required interrupts). | 162 | /// If not, `g` is called once(to eg enable the required interrupts). |
| 163 | /// The waker will always be registered prior to calling `f`. | ||
| 163 | #[inline(always)] | 164 | #[inline(always)] |
| 164 | async fn wait_on<F, U, G>(&mut self, mut f: F, mut g: G) -> U | 165 | async fn wait_on<F, U, G>(&mut self, mut f: F, mut g: G) -> U |
| 165 | where | 166 | where |
| @@ -167,10 +168,11 @@ impl<'d, T: Instance> I2cSlave<'d, T> { | |||
| 167 | G: FnMut(&mut Self), | 168 | G: FnMut(&mut Self), |
| 168 | { | 169 | { |
| 169 | future::poll_fn(|cx| { | 170 | future::poll_fn(|cx| { |
| 171 | // Register prior to checking the condition | ||
| 172 | T::waker().register(cx.waker()); | ||
| 170 | let r = f(self); | 173 | let r = f(self); |
| 171 | 174 | ||
| 172 | if r.is_pending() { | 175 | if r.is_pending() { |
| 173 | T::waker().register(cx.waker()); | ||
| 174 | g(self); | 176 | g(self); |
| 175 | } | 177 | } |
| 176 | 178 | ||
