aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-03-27 02:08:01 +0100
committerDario Nieuwenhuis <[email protected]>2021-03-29 00:58:58 +0200
commit1c9f98e1b63296602da2aac0103bea917dcbdcd9 (patch)
tree77587d34004dfb8e845fad283d8dff02b467d8c8 /embassy-nrf/src
parent4ce46df1603697b14f2446b33663a122dda4a468 (diff)
nrf/gpiote: fix irq race condition
The interrupt could fire between checking if sense=disabled and registering the waker, in which case the future would get stuck.
Diffstat (limited to 'embassy-nrf/src')
-rw-r--r--embassy-nrf/src/gpiote.rs22
1 files changed, 8 insertions, 14 deletions
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs
index 920d69236..9ea008f01 100644
--- a/embassy-nrf/src/gpiote.rs
+++ b/embassy-nrf/src/gpiote.rs
@@ -395,9 +395,8 @@ pub struct PortInputFuture<'a> {
395 395
396impl<'a> Drop for PortInputFuture<'a> { 396impl<'a> Drop for PortInputFuture<'a> {
397 fn drop(&mut self) { 397 fn drop(&mut self) {
398 unsafe { AnyPin::steal(self.pin_port) } 398 let pin = unsafe { AnyPin::steal(self.pin_port) };
399 .conf() 399 pin.conf().modify(|_, w| w.sense().disabled());
400 .modify(|_, w| w.sense().disabled());
401 } 400 }
402} 401}
403 402
@@ -405,18 +404,13 @@ impl<'a> Future for PortInputFuture<'a> {
405 type Output = (); 404 type Output = ();
406 405
407 fn poll(self: core::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { 406 fn poll(self: core::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
408 let dis = unsafe { AnyPin::steal(self.pin_port) }
409 .conf()
410 .read()
411 .sense()
412 .is_disabled();
413
414 if dis {
415 return Poll::Ready(());
416 }
417
418 PORT_WAKERS[self.pin_port as usize].register(cx.waker()); 407 PORT_WAKERS[self.pin_port as usize].register(cx.waker());
419 408
420 Poll::Pending 409 let pin = unsafe { AnyPin::steal(self.pin_port) };
410 if pin.conf().read().sense().is_disabled() {
411 Poll::Ready(())
412 } else {
413 Poll::Pending
414 }
421 } 415 }
422} 416}