diff options
| -rw-r--r-- | embassy-stm32-wpan/src/mac/control.rs | 16 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/mac/runner.rs | 7 |
2 files changed, 14 insertions, 9 deletions
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 @@ | |||
| 1 | use core::future::Future; | 1 | use core::future::Future; |
| 2 | use core::task; | 2 | use core::task; |
| 3 | use core::task::Poll; | ||
| 3 | 4 | ||
| 4 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | 5 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; |
| 5 | use embassy_sync::mutex::MutexGuard; | 6 | use embassy_sync::mutex::MutexGuard; |
| @@ -7,6 +8,7 @@ use embassy_sync::signal::Signal; | |||
| 7 | use futures::FutureExt; | 8 | use futures::FutureExt; |
| 8 | 9 | ||
| 9 | use super::commands::MacCommand; | 10 | use super::commands::MacCommand; |
| 11 | use super::event::MacEvent; | ||
| 10 | use super::typedefs::MacError; | 12 | use super::typedefs::MacError; |
| 11 | use crate::mac::runner::Runner; | 13 | use crate::mac::runner::Runner; |
| 12 | 14 | ||
| @@ -62,10 +64,9 @@ impl<'a> EventToken<'a> { | |||
| 62 | } | 64 | } |
| 63 | 65 | ||
| 64 | impl<'a> Future for EventToken<'a> { | 66 | impl<'a> Future for EventToken<'a> { |
| 65 | // TODO: output something | 67 | type Output = MacEvent<'a>; |
| 66 | type Output = (); | ||
| 67 | 68 | ||
| 68 | fn poll(self: core::pin::Pin<&mut Self>, cx: &mut task::Context<'_>) -> task::Poll<Self::Output> { | 69 | fn poll(self: core::pin::Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> { |
| 69 | self.get_mut().runner.rx_event_channel.lock(|s| { | 70 | self.get_mut().runner.rx_event_channel.lock(|s| { |
| 70 | let signal = s.borrow_mut(); | 71 | let signal = s.borrow_mut(); |
| 71 | let signal = match &*signal { | 72 | let signal = match &*signal { |
| @@ -73,10 +74,13 @@ impl<'a> Future for EventToken<'a> { | |||
| 73 | _ => unreachable!(), | 74 | _ => unreachable!(), |
| 74 | }; | 75 | }; |
| 75 | 76 | ||
| 76 | let _ = signal.wait().poll_unpin(cx); | 77 | let result = match signal.wait().poll_unpin(cx) { |
| 77 | }); | 78 | Poll::Ready(mac_event) => Poll::Ready(mac_event), |
| 79 | Poll::Pending => Poll::Pending, | ||
| 80 | }; | ||
| 78 | 81 | ||
| 79 | todo!() | 82 | result |
| 83 | }) | ||
| 80 | } | 84 | } |
| 81 | } | 85 | } |
| 82 | 86 | ||
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}; | |||
| 13 | use crate::mac::MTU; | 13 | use crate::mac::MTU; |
| 14 | use crate::sub::mac::Mac; | 14 | use crate::sub::mac::Mac; |
| 15 | 15 | ||
| 16 | type ZeroCopyPubSub<M, T> = blocking_mutex::Mutex<M, RefCell<Option<Signal<NoopRawMutex, T>>>>; | ||
| 17 | |||
| 16 | pub struct Runner<'a> { | 18 | pub struct Runner<'a> { |
| 17 | pub(crate) mac_subsystem: Mac, | 19 | pub(crate) mac_subsystem: Mac, |
| 18 | |||
| 19 | // rx event backpressure is already provided through the MacEvent drop mechanism | 20 | // rx event backpressure is already provided through the MacEvent drop mechanism |
| 20 | pub(crate) rx_event_channel: | 21 | // therefore, we don't need to worry about overwriting events |
| 21 | blocking_mutex::Mutex<CriticalSectionRawMutex, RefCell<Option<Signal<NoopRawMutex, MacEvent<'a>>>>>, | 22 | pub(crate) rx_event_channel: ZeroCopyPubSub<CriticalSectionRawMutex, MacEvent<'a>>, |
| 22 | pub(crate) read_mutex: Mutex<CriticalSectionRawMutex, ()>, | 23 | pub(crate) read_mutex: Mutex<CriticalSectionRawMutex, ()>, |
| 23 | pub(crate) write_mutex: Mutex<CriticalSectionRawMutex, ()>, | 24 | pub(crate) write_mutex: Mutex<CriticalSectionRawMutex, ()>, |
| 24 | pub(crate) rx_channel: Channel<CriticalSectionRawMutex, MacEvent<'a>, 1>, | 25 | pub(crate) rx_channel: Channel<CriticalSectionRawMutex, MacEvent<'a>, 1>, |
