wpan: complete prelim. command impl.

This commit is contained in:
xoviat 2023-07-21 16:10:34 -05:00
parent 899a68325c
commit c675208b8a
2 changed files with 14 additions and 9 deletions

View file

@ -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<Self::Output> {
fn poll(self: core::pin::Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
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
})
}
}

View file

@ -13,12 +13,13 @@ use crate::mac::typedefs::{AddressMode, MacAddress, PanId, SecurityLevel};
use crate::mac::MTU;
use crate::sub::mac::Mac;
type ZeroCopyPubSub<M, T> = blocking_mutex::Mutex<M, RefCell<Option<Signal<NoopRawMutex, T>>>>;
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<CriticalSectionRawMutex, RefCell<Option<Signal<NoopRawMutex, MacEvent<'a>>>>>,
// therefore, we don't need to worry about overwriting events
pub(crate) rx_event_channel: ZeroCopyPubSub<CriticalSectionRawMutex, MacEvent<'a>>,
pub(crate) read_mutex: Mutex<CriticalSectionRawMutex, ()>,
pub(crate) write_mutex: Mutex<CriticalSectionRawMutex, ()>,
pub(crate) rx_channel: Channel<CriticalSectionRawMutex, MacEvent<'a>, 1>,