- optimize event to parse opcode only once

- optimze channels
- return mut ref for smoltcp rx
This commit is contained in:
xoviat 2023-07-19 17:49:08 -05:00
parent ca1d4179a7
commit 28254842db
12 changed files with 178 additions and 133 deletions

View File

@ -17,7 +17,6 @@ embassy-time = { version = "0.1.2", path = "../embassy-time", optional = true }
embassy-futures = { version = "0.1.0", path = "../embassy-futures" } embassy-futures = { version = "0.1.0", path = "../embassy-futures" }
embassy-hal-common = { version = "0.1.0", path = "../embassy-hal-common" } embassy-hal-common = { version = "0.1.0", path = "../embassy-hal-common" }
embassy-embedded-hal = { version = "0.1.0", path = "../embassy-embedded-hal" } embassy-embedded-hal = { version = "0.1.0", path = "../embassy-embedded-hal" }
embassy-net-driver-channel = { version = "0.1.0", path = "../embassy-net-driver-channel", optional=true }
embassy-net-driver = { version = "0.1.0", path = "../embassy-net-driver", optional=true } embassy-net-driver = { version = "0.1.0", path = "../embassy-net-driver", optional=true }
defmt = { version = "0.3", optional = true } defmt = { version = "0.3", optional = true }
@ -35,7 +34,7 @@ bitflags = { version = "2.3.3", optional = true }
defmt = ["dep:defmt", "embassy-sync/defmt", "embassy-embedded-hal/defmt", "embassy-hal-common/defmt", "stm32wb-hci?/defmt"] defmt = ["dep:defmt", "embassy-sync/defmt", "embassy-embedded-hal/defmt", "embassy-hal-common/defmt", "stm32wb-hci?/defmt"]
ble = ["dep:stm32wb-hci"] ble = ["dep:stm32wb-hci"]
mac = ["dep:bitflags", "dep:embassy-net-driver-channel", "dep:embassy-net-driver"] mac = ["dep:bitflags", "dep:embassy-net-driver" ]
stm32wb10cc = [ "embassy-stm32/stm32wb10cc" ] stm32wb10cc = [ "embassy-stm32/stm32wb10cc" ]
stm32wb15cc = [ "embassy-stm32/stm32wb15cc" ] stm32wb15cc = [ "embassy-stm32/stm32wb15cc" ]

View File

@ -6,6 +6,7 @@ pub struct Error {
} }
pub struct Control<'a> { pub struct Control<'a> {
#[allow(dead_code)]
runner: &'a Runner<'a>, runner: &'a Runner<'a>,
} }

View File

@ -7,8 +7,7 @@ use embassy_net_driver::{Capabilities, LinkState, Medium};
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
use embassy_sync::channel::Channel; use embassy_sync::channel::Channel;
use super::event::MacEvent; use crate::mac::event::{Event, MacEvent};
use crate::mac::event::Event;
use crate::mac::runner::Runner; use crate::mac::runner::Runner;
use crate::mac::MTU; use crate::mac::MTU;
@ -64,7 +63,7 @@ impl<'d> embassy_net_driver::Driver for Driver<'d> {
caps caps
} }
fn link_state(&mut self, cx: &mut Context) -> LinkState { fn link_state(&mut self, _cx: &mut Context) -> LinkState {
// if self.phy.poll_link(&mut self.station_management, cx) { // if self.phy.poll_link(&mut self.station_management, cx) {
// LinkState::Up // LinkState::Up
// } else { // } else {
@ -82,7 +81,7 @@ impl<'d> embassy_net_driver::Driver for Driver<'d> {
} }
pub struct RxToken<'d> { pub struct RxToken<'d> {
rx: &'d Channel<CriticalSectionRawMutex, Event, 1>, rx: &'d Channel<CriticalSectionRawMutex, Event<'d>, 1>,
} }
impl<'d> embassy_net_driver::RxToken for RxToken<'d> { impl<'d> embassy_net_driver::RxToken for RxToken<'d> {
@ -92,24 +91,18 @@ impl<'d> embassy_net_driver::RxToken for RxToken<'d> {
{ {
// Only valid data events should be put into the queue // Only valid data events should be put into the queue
let event = self.rx.try_recv().unwrap(); let data_event = match *self.rx.try_recv().unwrap() {
let mac_event = event.mac_event().unwrap();
let data_event = match mac_event {
MacEvent::McpsDataInd(data_event) => data_event, MacEvent::McpsDataInd(data_event) => data_event,
_ => unreachable!(), _ => unreachable!(),
}; };
let pkt = &mut []; f(&mut data_event.payload())
let r = f(&mut pkt[0..]);
// let r = f(&mut data_event.payload());
r
} }
} }
pub struct TxToken<'d> { pub struct TxToken<'d> {
tx: &'d Channel<CriticalSectionRawMutex, &'d mut [u8], 5>, tx: &'d Channel<CriticalSectionRawMutex, (&'d mut [u8; MTU], usize), 5>,
tx_buf: &'d Channel<CriticalSectionRawMutex, &'d mut [u8], 5>, tx_buf: &'d Channel<CriticalSectionRawMutex, &'d mut [u8; MTU], 5>,
} }
impl<'d> embassy_net_driver::TxToken for TxToken<'d> { impl<'d> embassy_net_driver::TxToken for TxToken<'d> {
@ -122,7 +115,7 @@ impl<'d> embassy_net_driver::TxToken for TxToken<'d> {
let r = f(&mut buf[..len]); let r = f(&mut buf[..len]);
// The tx channel should always be of equal capacity to the tx_buf channel // The tx channel should always be of equal capacity to the tx_buf channel
self.tx.try_send(buf).unwrap(); self.tx.try_send((buf, len)).unwrap();
r r
} }

View File

@ -1,4 +1,4 @@
use core::mem; use core::{mem, ops};
use super::indications::{ use super::indications::{
AssociateIndication, BeaconNotifyIndication, CommStatusIndication, DataIndication, DisassociateIndication, AssociateIndication, BeaconNotifyIndication, CommStatusIndication, DataIndication, DisassociateIndication,
@ -22,55 +22,104 @@ pub(crate) trait ParseableMacEvent: Sized {
} }
} }
pub struct Event { pub struct Event<'a> {
#[allow(dead_code)]
event_box: EvtBox<Mac>, event_box: EvtBox<Mac>,
mac_event: MacEvent<'a>,
} }
impl Event { impl<'a> Event<'a> {
pub(crate) fn new(event_box: EvtBox<Mac>) -> Self { pub(crate) fn new(event_box: EvtBox<Mac>) -> Result<Self, ()> {
Self { event_box } let payload = event_box.payload();
}
pub fn mac_event<'a>(&'a self) -> Result<MacEvent<'a>, ()> {
let payload = self.event_box.payload();
let opcode = u16::from_le_bytes(payload[0..2].try_into().unwrap()); let opcode = u16::from_le_bytes(payload[0..2].try_into().unwrap());
let opcode = OpcodeM0ToM4::try_from(opcode)?; let opcode = OpcodeM0ToM4::try_from(opcode)?;
let buf = &payload[2..]; let buf = &payload[2..];
match opcode { // To avoid re-parsing the opcode, we store the result of the parse
OpcodeM0ToM4::MlmeAssociateCnf => Ok(MacEvent::MlmeAssociateCnf(AssociateConfirm::from_buffer(buf)?)), // this requires use of unsafe because rust cannot assume that a reference will become
OpcodeM0ToM4::MlmeDisassociateCnf => { // invalid when the underlying result is moved. However, because we refer to a "heap"
Ok(MacEvent::MlmeDisassociateCnf(DisassociateConfirm::from_buffer(buf)?)) // allocation, the underlying reference will not move until the struct is dropped.
let mac_event = match opcode {
OpcodeM0ToM4::MlmeAssociateCnf => {
MacEvent::MlmeAssociateCnf(unsafe { &*(AssociateConfirm::from_buffer(buf)? as *const _) })
}
OpcodeM0ToM4::MlmeDisassociateCnf => {
MacEvent::MlmeDisassociateCnf(unsafe { &*(DisassociateConfirm::from_buffer(buf)? as *const _) })
}
OpcodeM0ToM4::MlmeGetCnf => MacEvent::MlmeGetCnf(unsafe { &*(GetConfirm::from_buffer(buf)? as *const _) }),
OpcodeM0ToM4::MlmeGtsCnf => MacEvent::MlmeGtsCnf(unsafe { &*(GtsConfirm::from_buffer(buf)? as *const _) }),
OpcodeM0ToM4::MlmeResetCnf => {
MacEvent::MlmeResetCnf(unsafe { &*(ResetConfirm::from_buffer(buf)? as *const _) })
}
OpcodeM0ToM4::MlmeRxEnableCnf => {
MacEvent::MlmeRxEnableCnf(unsafe { &*(RxEnableConfirm::from_buffer(buf)? as *const _) })
}
OpcodeM0ToM4::MlmeScanCnf => {
MacEvent::MlmeScanCnf(unsafe { &*(ScanConfirm::from_buffer(buf)? as *const _) })
}
OpcodeM0ToM4::MlmeSetCnf => MacEvent::MlmeSetCnf(unsafe { &*(SetConfirm::from_buffer(buf)? as *const _) }),
OpcodeM0ToM4::MlmeStartCnf => {
MacEvent::MlmeStartCnf(unsafe { &*(StartConfirm::from_buffer(buf)? as *const _) })
}
OpcodeM0ToM4::MlmePollCnf => {
MacEvent::MlmePollCnf(unsafe { &*(PollConfirm::from_buffer(buf)? as *const _) })
}
OpcodeM0ToM4::MlmeDpsCnf => MacEvent::MlmeDpsCnf(unsafe { &*(DpsConfirm::from_buffer(buf)? as *const _) }),
OpcodeM0ToM4::MlmeSoundingCnf => {
MacEvent::MlmeSoundingCnf(unsafe { &*(SoundingConfirm::from_buffer(buf)? as *const _) })
}
OpcodeM0ToM4::MlmeCalibrateCnf => {
MacEvent::MlmeCalibrateCnf(unsafe { &*(CalibrateConfirm::from_buffer(buf)? as *const _) })
}
OpcodeM0ToM4::McpsDataCnf => {
MacEvent::McpsDataCnf(unsafe { &*(DataConfirm::from_buffer(buf)? as *const _) })
}
OpcodeM0ToM4::McpsPurgeCnf => {
MacEvent::McpsPurgeCnf(unsafe { &*(PurgeConfirm::from_buffer(buf)? as *const _) })
}
OpcodeM0ToM4::MlmeAssociateInd => {
MacEvent::MlmeAssociateInd(unsafe { &*(AssociateIndication::from_buffer(buf)? as *const _) })
} }
OpcodeM0ToM4::MlmeGetCnf => Ok(MacEvent::MlmeGetCnf(GetConfirm::from_buffer(buf)?)),
OpcodeM0ToM4::MlmeGtsCnf => Ok(MacEvent::MlmeGtsCnf(GtsConfirm::from_buffer(buf)?)),
OpcodeM0ToM4::MlmeResetCnf => Ok(MacEvent::MlmeResetCnf(ResetConfirm::from_buffer(buf)?)),
OpcodeM0ToM4::MlmeRxEnableCnf => Ok(MacEvent::MlmeRxEnableCnf(RxEnableConfirm::from_buffer(buf)?)),
OpcodeM0ToM4::MlmeScanCnf => Ok(MacEvent::MlmeScanCnf(ScanConfirm::from_buffer(buf)?)),
OpcodeM0ToM4::MlmeSetCnf => Ok(MacEvent::MlmeSetCnf(SetConfirm::from_buffer(buf)?)),
OpcodeM0ToM4::MlmeStartCnf => Ok(MacEvent::MlmeStartCnf(StartConfirm::from_buffer(buf)?)),
OpcodeM0ToM4::MlmePollCnf => Ok(MacEvent::MlmePollCnf(PollConfirm::from_buffer(buf)?)),
OpcodeM0ToM4::MlmeDpsCnf => Ok(MacEvent::MlmeDpsCnf(DpsConfirm::from_buffer(buf)?)),
OpcodeM0ToM4::MlmeSoundingCnf => Ok(MacEvent::MlmeSoundingCnf(SoundingConfirm::from_buffer(buf)?)),
OpcodeM0ToM4::MlmeCalibrateCnf => Ok(MacEvent::MlmeCalibrateCnf(CalibrateConfirm::from_buffer(buf)?)),
OpcodeM0ToM4::McpsDataCnf => Ok(MacEvent::McpsDataCnf(DataConfirm::from_buffer(buf)?)),
OpcodeM0ToM4::McpsPurgeCnf => Ok(MacEvent::McpsPurgeCnf(PurgeConfirm::from_buffer(buf)?)),
OpcodeM0ToM4::MlmeAssociateInd => Ok(MacEvent::MlmeAssociateInd(AssociateIndication::from_buffer(buf)?)),
OpcodeM0ToM4::MlmeDisassociateInd => { OpcodeM0ToM4::MlmeDisassociateInd => {
Ok(MacEvent::MlmeDisassociateInd(DisassociateIndication::from_buffer(buf)?)) MacEvent::MlmeDisassociateInd(unsafe { &*(DisassociateIndication::from_buffer(buf)? as *const _) })
} }
OpcodeM0ToM4::MlmeBeaconNotifyInd => { OpcodeM0ToM4::MlmeBeaconNotifyInd => {
Ok(MacEvent::MlmeBeaconNotifyInd(BeaconNotifyIndication::from_buffer(buf)?)) MacEvent::MlmeBeaconNotifyInd(unsafe { &*(BeaconNotifyIndication::from_buffer(buf)? as *const _) })
} }
OpcodeM0ToM4::MlmeCommStatusInd => Ok(MacEvent::MlmeCommStatusInd(CommStatusIndication::from_buffer(buf)?)), OpcodeM0ToM4::MlmeCommStatusInd => {
OpcodeM0ToM4::MlmeGtsInd => Ok(MacEvent::MlmeGtsInd(GtsIndication::from_buffer(buf)?)), MacEvent::MlmeCommStatusInd(unsafe { &*(CommStatusIndication::from_buffer(buf)? as *const _) })
OpcodeM0ToM4::MlmeOrphanInd => Ok(MacEvent::MlmeOrphanInd(OrphanIndication::from_buffer(buf)?)),
OpcodeM0ToM4::MlmeSyncLossInd => Ok(MacEvent::MlmeSyncLossInd(SyncLossIndication::from_buffer(buf)?)),
OpcodeM0ToM4::MlmeDpsInd => Ok(MacEvent::MlmeDpsInd(DpsIndication::from_buffer(buf)?)),
OpcodeM0ToM4::McpsDataInd => Ok(MacEvent::McpsDataInd(DataIndication::from_buffer(buf)?)),
OpcodeM0ToM4::MlmePollInd => Ok(MacEvent::MlmePollInd(PollIndication::from_buffer(buf)?)),
} }
OpcodeM0ToM4::MlmeGtsInd => {
MacEvent::MlmeGtsInd(unsafe { &*(GtsIndication::from_buffer(buf)? as *const _) })
}
OpcodeM0ToM4::MlmeOrphanInd => {
MacEvent::MlmeOrphanInd(unsafe { &*(OrphanIndication::from_buffer(buf)? as *const _) })
}
OpcodeM0ToM4::MlmeSyncLossInd => {
MacEvent::MlmeSyncLossInd(unsafe { &*(SyncLossIndication::from_buffer(buf)? as *const _) })
}
OpcodeM0ToM4::MlmeDpsInd => {
MacEvent::MlmeDpsInd(unsafe { &*(DpsIndication::from_buffer(buf)? as *const _) })
}
OpcodeM0ToM4::McpsDataInd => {
MacEvent::McpsDataInd(unsafe { &*(DataIndication::from_buffer(buf)? as *const _) })
}
OpcodeM0ToM4::MlmePollInd => {
MacEvent::MlmePollInd(unsafe { &*(PollIndication::from_buffer(buf)? as *const _) })
}
};
Ok(Self { event_box, mac_event })
}
}
impl<'a> ops::Deref for Event<'a> {
type Target = MacEvent<'a>;
fn deref(&self) -> &Self::Target {
&self.mac_event
} }
} }

View File

@ -236,8 +236,8 @@ pub struct DataIndication {
impl ParseableMacEvent for DataIndication {} impl ParseableMacEvent for DataIndication {}
impl DataIndication { impl DataIndication {
pub fn payload<'a>(&'a self) -> &'a [u8] { pub fn payload<'a>(&'a self) -> &'a mut [u8] {
unsafe { slice::from_raw_parts(self.msdu_ptr, self.msdu_length as usize) } unsafe { slice::from_raw_parts_mut(self.msdu_ptr as *mut _, self.msdu_length as usize) }
} }
} }

View File

@ -10,8 +10,6 @@ pub mod responses;
pub mod runner; pub mod runner;
pub mod typedefs; pub mod typedefs;
use core::slice;
pub use crate::mac::control::{Control, Error as ControlError}; pub use crate::mac::control::{Control, Error as ControlError};
use crate::mac::driver::Driver; use crate::mac::driver::Driver;
pub use crate::mac::runner::Runner; pub use crate::mac::runner::Runner;
@ -21,8 +19,3 @@ const MTU: usize = 127;
pub async fn new<'a>(runner: &'a Runner<'a>) -> (Control<'a>, Driver<'a>) { pub async fn new<'a>(runner: &'a Runner<'a>) -> (Control<'a>, Driver<'a>) {
(Control::new(runner), Driver::new(runner)) (Control::new(runner), Driver::new(runner))
} }
fn slice8_mut(x: &mut [u32]) -> &mut [u8] {
let len = x.len() * 4;
unsafe { slice::from_raw_parts_mut(x.as_mut_ptr() as _, len) }
}

View File

@ -10,9 +10,9 @@ use crate::sub::mac::Mac;
pub struct Runner<'a> { pub struct Runner<'a> {
mac_subsystem: Mac, mac_subsystem: Mac,
pub(crate) rx_channel: Channel<CriticalSectionRawMutex, Event, 1>, pub(crate) rx_channel: Channel<CriticalSectionRawMutex, Event<'a>, 1>,
pub(crate) tx_channel: Channel<CriticalSectionRawMutex, &'a mut [u8], 5>, pub(crate) tx_channel: Channel<CriticalSectionRawMutex, (&'a mut [u8; MTU], usize), 5>,
pub(crate) tx_buf_channel: Channel<CriticalSectionRawMutex, &'a mut [u8], 5>, pub(crate) tx_buf_channel: Channel<CriticalSectionRawMutex, &'a mut [u8; MTU], 5>,
} }
impl<'a> Runner<'a> { impl<'a> Runner<'a> {
@ -31,15 +31,14 @@ impl<'a> Runner<'a> {
this this
} }
pub async fn run(&self) -> ! { pub async fn run(&'a self) -> ! {
join::join( join::join(
async { async {
loop { loop {
let event = self.mac_subsystem.read().await; if let Ok(mac_event) = self.mac_subsystem.read().await {
if let Ok(evt) = event.mac_event() { match *mac_event {
match evt {
MacEvent::McpsDataInd(_) => { MacEvent::McpsDataInd(_) => {
self.rx_channel.send(event).await; self.rx_channel.send(mac_event).await;
} }
_ => {} _ => {}
} }
@ -48,7 +47,7 @@ impl<'a> Runner<'a> {
}, },
async { async {
loop { loop {
let buf = self.tx_channel.recv().await; let (buf, len) = self.tx_channel.recv().await;
self.mac_subsystem self.mac_subsystem
.send_command( .send_command(
@ -63,7 +62,7 @@ impl<'a> Runner<'a> {
security_level: SecurityLevel::Unsecure, security_level: SecurityLevel::Unsecure,
..Default::default() ..Default::default()
} }
.set_buffer(&buf), .set_buffer(&buf[..len]),
) )
.await .await
.unwrap(); .unwrap();

View File

@ -94,7 +94,7 @@ impl Mac {
} }
} }
pub async fn read(&self) -> Event { pub async fn read(&self) -> Result<Event<'_>, ()> {
Event::new(self.tl_read().await) Event::new(self.tl_read().await)
} }
} }

View File

@ -74,8 +74,8 @@ async fn main(spawner: Spawner) {
.await .await
.unwrap(); .unwrap();
{ {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await.unwrap();
defmt::info!("{:#x}", evt.mac_event()); defmt::info!("{:#x}", *evt);
} }
info!("setting extended address"); info!("setting extended address");
@ -88,8 +88,8 @@ async fn main(spawner: Spawner) {
.await .await
.unwrap(); .unwrap();
{ {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await.unwrap();
defmt::info!("{:#x}", evt.mac_event()); defmt::info!("{:#x}", *evt);
} }
info!("setting short address"); info!("setting short address");
@ -102,8 +102,8 @@ async fn main(spawner: Spawner) {
.await .await
.unwrap(); .unwrap();
{ {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await.unwrap();
defmt::info!("{:#x}", evt.mac_event()); defmt::info!("{:#x}", *evt);
} }
info!("setting association permit"); info!("setting association permit");
@ -116,8 +116,8 @@ async fn main(spawner: Spawner) {
.await .await
.unwrap(); .unwrap();
{ {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await.unwrap();
defmt::info!("{:#x}", evt.mac_event()); defmt::info!("{:#x}", *evt);
} }
info!("setting TX power"); info!("setting TX power");
@ -130,8 +130,8 @@ async fn main(spawner: Spawner) {
.await .await
.unwrap(); .unwrap();
{ {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await.unwrap();
defmt::info!("{:#x}", evt.mac_event()); defmt::info!("{:#x}", *evt);
} }
info!("starting FFD device"); info!("starting FFD device");
@ -148,8 +148,8 @@ async fn main(spawner: Spawner) {
.await .await
.unwrap(); .unwrap();
{ {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await.unwrap();
defmt::info!("{:#x}", evt.mac_event()); defmt::info!("{:#x}", *evt);
} }
info!("setting RX on when idle"); info!("setting RX on when idle");
@ -162,17 +162,17 @@ async fn main(spawner: Spawner) {
.await .await
.unwrap(); .unwrap();
{ {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await.unwrap();
defmt::info!("{:#x}", evt.mac_event()); defmt::info!("{:#x}", *evt);
} }
loop { loop {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await;
if let Ok(evt) = evt.mac_event() { if let Ok(evt) = evt {
defmt::info!("parsed mac event"); defmt::info!("parsed mac event");
defmt::info!("{:#x}", evt); defmt::info!("{:#x}", *evt);
match evt { match *evt {
MacEvent::MlmeAssociateInd(association) => mbox MacEvent::MlmeAssociateInd(association) => mbox
.mac_subsystem .mac_subsystem
.send_command(&AssociateResponse { .send_command(&AssociateResponse {

View File

@ -80,8 +80,8 @@ async fn main(spawner: Spawner) {
.await .await
.unwrap(); .unwrap();
{ {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await.unwrap();
defmt::info!("{:#x}", evt.mac_event()); defmt::info!("{:#x}", *evt);
} }
info!("setting extended address"); info!("setting extended address");
@ -94,8 +94,8 @@ async fn main(spawner: Spawner) {
.await .await
.unwrap(); .unwrap();
{ {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await.unwrap();
defmt::info!("{:#x}", evt.mac_event()); defmt::info!("{:#x}", *evt);
} }
info!("setting short address"); info!("setting short address");
@ -108,8 +108,8 @@ async fn main(spawner: Spawner) {
.await .await
.unwrap(); .unwrap();
{ {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await.unwrap();
defmt::info!("{:#x}", evt.mac_event()); defmt::info!("{:#x}", *evt);
} }
info!("setting association permit"); info!("setting association permit");
@ -122,8 +122,8 @@ async fn main(spawner: Spawner) {
.await .await
.unwrap(); .unwrap();
{ {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await.unwrap();
defmt::info!("{:#x}", evt.mac_event()); defmt::info!("{:#x}", *evt);
} }
info!("setting TX power"); info!("setting TX power");
@ -136,8 +136,8 @@ async fn main(spawner: Spawner) {
.await .await
.unwrap(); .unwrap();
{ {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await.unwrap();
defmt::info!("{:#x}", evt.mac_event()); defmt::info!("{:#x}", *evt);
} }
info!("starting FFD device"); info!("starting FFD device");
@ -154,8 +154,8 @@ async fn main(spawner: Spawner) {
.await .await
.unwrap(); .unwrap();
{ {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await.unwrap();
defmt::info!("{:#x}", evt.mac_event()); defmt::info!("{:#x}", *evt);
} }
info!("setting RX on when idle"); info!("setting RX on when idle");
@ -168,8 +168,8 @@ async fn main(spawner: Spawner) {
.await .await
.unwrap(); .unwrap();
{ {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await.unwrap();
defmt::info!("{:#x}", evt.mac_event()); defmt::info!("{:#x}", *evt);
} }
let tx_queue = [ let tx_queue = [

View File

@ -76,8 +76,8 @@ async fn main(spawner: Spawner) {
.await .await
.unwrap(); .unwrap();
{ {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await.unwrap();
defmt::info!("{:#x}", evt.mac_event()); defmt::info!("{:#x}", *evt);
} }
info!("setting extended address"); info!("setting extended address");
@ -90,8 +90,8 @@ async fn main(spawner: Spawner) {
.await .await
.unwrap(); .unwrap();
{ {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await.unwrap();
defmt::info!("{:#x}", evt.mac_event()); defmt::info!("{:#x}", *evt);
} }
info!("getting extended address"); info!("getting extended address");
@ -104,10 +104,10 @@ async fn main(spawner: Spawner) {
.unwrap(); .unwrap();
{ {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await.unwrap();
info!("{:#x}", evt.mac_event()); info!("{:#x}", *evt);
if let Ok(MacEvent::MlmeGetCnf(evt)) = evt.mac_event() { if let MacEvent::MlmeGetCnf(evt) = *evt {
if evt.pib_attribute_value_len == 8 { if evt.pib_attribute_value_len == 8 {
let value = unsafe { core::ptr::read_unaligned(evt.pib_attribute_value_ptr as *const u64) }; let value = unsafe { core::ptr::read_unaligned(evt.pib_attribute_value_ptr as *const u64) };
@ -132,10 +132,10 @@ async fn main(spawner: Spawner) {
info!("{}", a); info!("{}", a);
mbox.mac_subsystem.send_command(&a).await.unwrap(); mbox.mac_subsystem.send_command(&a).await.unwrap();
let short_addr = { let short_addr = {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await.unwrap();
info!("{:#x}", evt.mac_event()); info!("{:#x}", *evt);
if let Ok(MacEvent::MlmeAssociateCnf(conf)) = evt.mac_event() { if let MacEvent::MlmeAssociateCnf(conf) = *evt {
conf.assoc_short_address conf.assoc_short_address
} else { } else {
defmt::panic!() defmt::panic!()
@ -151,8 +151,8 @@ async fn main(spawner: Spawner) {
.await .await
.unwrap(); .unwrap();
{ {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await.unwrap();
info!("{:#x}", evt.mac_event()); info!("{:#x}", *evt);
} }
info!("sending data"); info!("sending data");
@ -175,12 +175,14 @@ async fn main(spawner: Spawner) {
.await .await
.unwrap(); .unwrap();
{ {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await.unwrap();
info!("{:#x}", evt.mac_event()); info!("{:#x}", *evt);
} }
loop { loop {
let evt = mbox.mac_subsystem.read().await; match mbox.mac_subsystem.read().await {
info!("{:#x}", evt.mac_event()); Ok(evt) => info!("{:#x}", *evt),
_ => continue,
};
} }
} }

View File

@ -56,8 +56,8 @@ async fn main(spawner: Spawner) {
.await .await
.unwrap(); .unwrap();
{ {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await.unwrap();
info!("{:#x}", evt.mac_event()); info!("{:#x}", *evt);
} }
info!("setting extended address"); info!("setting extended address");
@ -70,8 +70,8 @@ async fn main(spawner: Spawner) {
.await .await
.unwrap(); .unwrap();
{ {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await.unwrap();
info!("{:#x}", evt.mac_event()); info!("{:#x}", *evt);
} }
info!("getting extended address"); info!("getting extended address");
@ -82,11 +82,12 @@ async fn main(spawner: Spawner) {
}) })
.await .await
.unwrap(); .unwrap();
{
let evt = mbox.mac_subsystem.read().await;
info!("{:#x}", evt.mac_event());
if let Ok(MacEvent::MlmeGetCnf(evt)) = evt.mac_event() { {
let evt = mbox.mac_subsystem.read().await.unwrap();
info!("{:#x}", *evt);
if let MacEvent::MlmeGetCnf(evt) = *evt {
if evt.pib_attribute_value_len == 8 { if evt.pib_attribute_value_len == 8 {
let value = unsafe { core::ptr::read_unaligned(evt.pib_attribute_value_ptr as *const u64) }; let value = unsafe { core::ptr::read_unaligned(evt.pib_attribute_value_ptr as *const u64) };
@ -110,10 +111,18 @@ async fn main(spawner: Spawner) {
}; };
info!("{}", a); info!("{}", a);
mbox.mac_subsystem.send_command(&a).await.unwrap(); mbox.mac_subsystem.send_command(&a).await.unwrap();
{ let short_addr = {
let evt = mbox.mac_subsystem.read().await; let evt = mbox.mac_subsystem.read().await.unwrap();
info!("{:#x}", evt.mac_event()); info!("{:#x}", *evt);
if let MacEvent::MlmeAssociateCnf(conf) = *evt {
conf.assoc_short_address
} else {
defmt::panic!()
} }
};
_ = short_addr;
info!("Test OK"); info!("Test OK");
cortex_m::asm::bkpt(); cortex_m::asm::bkpt();