diff options
| author | Henrik Alsér <[email protected]> | 2022-11-05 01:34:52 +0100 |
|---|---|---|
| committer | Henrik Alsér <[email protected]> | 2022-11-05 01:34:52 +0100 |
| commit | 207fa195512c9e6604a1dec80ec055b06b9b49dd (patch) | |
| tree | 16c092f9b055f058b687a95e850866810b2db0ea | |
| parent | 7da18e194a8a9fef207803b96b16e7b7bc787ca7 (diff) | |
Acquire semaphore on blocking
| -rw-r--r-- | embassy-nrf/src/spis.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/embassy-nrf/src/spis.rs b/embassy-nrf/src/spis.rs index 71106b7df..22c13557a 100644 --- a/embassy-nrf/src/spis.rs +++ b/embassy-nrf/src/spis.rs | |||
| @@ -257,9 +257,19 @@ impl<'d, T: Instance> Spis<'d, T> { | |||
| 257 | } | 257 | } |
| 258 | 258 | ||
| 259 | fn blocking_inner_from_ram(&mut self, rx: *mut [u8], tx: *const [u8]) -> Result<(usize, usize), Error> { | 259 | fn blocking_inner_from_ram(&mut self, rx: *mut [u8], tx: *const [u8]) -> Result<(usize, usize), Error> { |
| 260 | self.prepare(rx, tx)?; | 260 | compiler_fence(Ordering::SeqCst); |
| 261 | let r = T::regs(); | 261 | let r = T::regs(); |
| 262 | 262 | ||
| 263 | // Acquire semaphore. | ||
| 264 | if r.semstat.read().bits() != 1 { | ||
| 265 | r.events_acquired.reset(); | ||
| 266 | r.tasks_acquire.write(|w| unsafe { w.bits(1) }); | ||
| 267 | // Wait until CPU has acquired the semaphore. | ||
| 268 | while r.semstat.read().bits() != 1 {} | ||
| 269 | } | ||
| 270 | |||
| 271 | self.prepare(rx, tx)?; | ||
| 272 | |||
| 263 | // Wait for 'end' event. | 273 | // Wait for 'end' event. |
| 264 | while r.events_end.read().bits() == 0 {} | 274 | while r.events_end.read().bits() == 0 {} |
| 265 | 275 | ||
| @@ -291,6 +301,7 @@ impl<'d, T: Instance> Spis<'d, T> { | |||
| 291 | // Clear status register. | 301 | // Clear status register. |
| 292 | r.status.write(|w| w.overflow().clear().overread().clear()); | 302 | r.status.write(|w| w.overflow().clear().overread().clear()); |
| 293 | 303 | ||
| 304 | // Acquire semaphore. | ||
| 294 | if r.semstat.read().bits() != 1 { | 305 | if r.semstat.read().bits() != 1 { |
| 295 | // Reset and enable the acquire event. | 306 | // Reset and enable the acquire event. |
| 296 | r.events_acquired.reset(); | 307 | r.events_acquired.reset(); |
| @@ -299,10 +310,10 @@ impl<'d, T: Instance> Spis<'d, T> { | |||
| 299 | // Request acquiring the SPIS semaphore. | 310 | // Request acquiring the SPIS semaphore. |
| 300 | r.tasks_acquire.write(|w| unsafe { w.bits(1) }); | 311 | r.tasks_acquire.write(|w| unsafe { w.bits(1) }); |
| 301 | 312 | ||
| 302 | // Wait for 'acquire' event. | 313 | // Wait until CPU has acquired the semaphore. |
| 303 | poll_fn(|cx| { | 314 | poll_fn(|cx| { |
| 304 | s.acquire_waker.register(cx.waker()); | 315 | s.acquire_waker.register(cx.waker()); |
| 305 | if r.events_acquired.read().bits() != 0 { | 316 | if r.semstat.read().bits() == 1 { |
| 306 | return Poll::Ready(()); | 317 | return Poll::Ready(()); |
| 307 | } | 318 | } |
| 308 | Poll::Pending | 319 | Poll::Pending |
