diff --git a/embassy-stm32-wpan/src/mac/control.rs b/embassy-stm32-wpan/src/mac/control.rs index fd8c22b26..ded419203 100644 --- a/embassy-stm32-wpan/src/mac/control.rs +++ b/embassy-stm32-wpan/src/mac/control.rs @@ -1,5 +1,6 @@ use core::future::Future; use core::task; +use core::task::Poll; use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; use embassy_sync::mutex::MutexGuard; @@ -7,6 +8,7 @@ use embassy_sync::signal::Signal; use futures::FutureExt; use super::commands::MacCommand; +use super::event::MacEvent; use super::typedefs::MacError; use crate::mac::runner::Runner; @@ -62,10 +64,9 @@ impl<'a> EventToken<'a> { } impl<'a> Future for EventToken<'a> { - // TODO: output something - type Output = (); + type Output = MacEvent<'a>; - fn poll(self: core::pin::Pin<&mut Self>, cx: &mut task::Context<'_>) -> task::Poll { + fn poll(self: core::pin::Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll { self.get_mut().runner.rx_event_channel.lock(|s| { let signal = s.borrow_mut(); let signal = match &*signal { @@ -73,10 +74,13 @@ impl<'a> Future for EventToken<'a> { _ => unreachable!(), }; - let _ = signal.wait().poll_unpin(cx); - }); + let result = match signal.wait().poll_unpin(cx) { + Poll::Ready(mac_event) => Poll::Ready(mac_event), + Poll::Pending => Poll::Pending, + }; - todo!() + result + }) } } diff --git a/embassy-stm32-wpan/src/mac/runner.rs b/embassy-stm32-wpan/src/mac/runner.rs index f964d6b3d..482321b95 100644 --- a/embassy-stm32-wpan/src/mac/runner.rs +++ b/embassy-stm32-wpan/src/mac/runner.rs @@ -13,12 +13,13 @@ use crate::mac::typedefs::{AddressMode, MacAddress, PanId, SecurityLevel}; use crate::mac::MTU; use crate::sub::mac::Mac; +type ZeroCopyPubSub = blocking_mutex::Mutex>>>; + pub struct Runner<'a> { pub(crate) mac_subsystem: Mac, - // rx event backpressure is already provided through the MacEvent drop mechanism - pub(crate) rx_event_channel: - blocking_mutex::Mutex>>>>, + // therefore, we don't need to worry about overwriting events + pub(crate) rx_event_channel: ZeroCopyPubSub>, pub(crate) read_mutex: Mutex, pub(crate) write_mutex: Mutex, pub(crate) rx_channel: Channel, 1>,