diff options
Diffstat (limited to 'examples/stm32wb/src/bin/mac_ffd.rs')
| -rw-r--r-- | examples/stm32wb/src/bin/mac_ffd.rs | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/examples/stm32wb/src/bin/mac_ffd.rs b/examples/stm32wb/src/bin/mac_ffd.rs index ede6cf4b9..4bab6ea9f 100644 --- a/examples/stm32wb/src/bin/mac_ffd.rs +++ b/examples/stm32wb/src/bin/mac_ffd.rs | |||
| @@ -6,11 +6,11 @@ use embassy_executor::Spawner; | |||
| 6 | use embassy_stm32::bind_interrupts; | 6 | use embassy_stm32::bind_interrupts; |
| 7 | use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; | 7 | use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; |
| 8 | use embassy_stm32::rcc::WPAN_DEFAULT; | 8 | use embassy_stm32::rcc::WPAN_DEFAULT; |
| 9 | use embassy_stm32_wpan::TlMbox; | ||
| 9 | use embassy_stm32_wpan::mac::commands::{AssociateResponse, ResetRequest, SetRequest, StartRequest}; | 10 | use embassy_stm32_wpan::mac::commands::{AssociateResponse, ResetRequest, SetRequest, StartRequest}; |
| 10 | use embassy_stm32_wpan::mac::event::MacEvent; | 11 | use embassy_stm32_wpan::mac::event::MacEvent; |
| 11 | use embassy_stm32_wpan::mac::typedefs::{MacChannel, MacStatus, PanId, PibId, SecurityLevel}; | 12 | use embassy_stm32_wpan::mac::typedefs::{MacChannel, MacStatus, PanId, PibId, SecurityLevel}; |
| 12 | use embassy_stm32_wpan::sub::mm; | 13 | use embassy_stm32_wpan::sub::mm; |
| 13 | use embassy_stm32_wpan::TlMbox; | ||
| 14 | use {defmt_rtt as _, panic_probe as _}; | 14 | use {defmt_rtt as _, panic_probe as _}; |
| 15 | 15 | ||
| 16 | bind_interrupts!(struct Irqs{ | 16 | bind_interrupts!(struct Irqs{ |
| @@ -19,7 +19,7 @@ bind_interrupts!(struct Irqs{ | |||
| 19 | }); | 19 | }); |
| 20 | 20 | ||
| 21 | #[embassy_executor::task] | 21 | #[embassy_executor::task] |
| 22 | async fn run_mm_queue(memory_manager: mm::MemoryManager) { | 22 | async fn run_mm_queue(mut memory_manager: mm::MemoryManager<'static>) { |
| 23 | memory_manager.run_queue().await; | 23 | memory_manager.run_queue().await; |
| 24 | } | 24 | } |
| 25 | 25 | ||
| @@ -54,74 +54,72 @@ async fn main(spawner: Spawner) { | |||
| 54 | info!("Hello World!"); | 54 | info!("Hello World!"); |
| 55 | 55 | ||
| 56 | let config = Config::default(); | 56 | let config = Config::default(); |
| 57 | let mbox = TlMbox::init(p.IPCC, Irqs, config); | 57 | let mbox = TlMbox::init(p.IPCC, Irqs, config).await; |
| 58 | let mut sys = mbox.sys_subsystem; | ||
| 58 | 59 | ||
| 59 | spawner.spawn(run_mm_queue(mbox.mm_subsystem).unwrap()); | 60 | spawner.spawn(run_mm_queue(mbox.mm_subsystem).unwrap()); |
| 60 | 61 | ||
| 61 | let sys_event = mbox.sys_subsystem.read().await; | 62 | let result = sys.shci_c2_mac_802_15_4_init().await; |
| 62 | info!("sys event: {}", sys_event.payload()); | ||
| 63 | |||
| 64 | core::mem::drop(sys_event); | ||
| 65 | |||
| 66 | let result = mbox.sys_subsystem.shci_c2_mac_802_15_4_init().await; | ||
| 67 | info!("initialized mac: {}", result); | 63 | info!("initialized mac: {}", result); |
| 68 | 64 | ||
| 65 | let (mut mac_rx, mut mac_tx) = mbox.mac_subsystem.split(); | ||
| 66 | |||
| 69 | info!("resetting"); | 67 | info!("resetting"); |
| 70 | mbox.mac_subsystem | 68 | mac_tx |
| 71 | .send_command(&ResetRequest { | 69 | .send_command(&ResetRequest { |
| 72 | set_default_pib: true, | 70 | set_default_pib: true, |
| 73 | ..Default::default() | 71 | ..Default::default() |
| 74 | }) | 72 | }) |
| 75 | .await | 73 | .await |
| 76 | .unwrap(); | 74 | .unwrap(); |
| 77 | defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap()); | 75 | defmt::info!("{:#x}", mac_rx.read().await.unwrap()); |
| 78 | 76 | ||
| 79 | info!("setting extended address"); | 77 | info!("setting extended address"); |
| 80 | let extended_address: u64 = 0xACDE480000000001; | 78 | let extended_address: u64 = 0xACDE480000000001; |
| 81 | mbox.mac_subsystem | 79 | mac_tx |
| 82 | .send_command(&SetRequest { | 80 | .send_command(&SetRequest { |
| 83 | pib_attribute_ptr: &extended_address as *const _ as *const u8, | 81 | pib_attribute_ptr: &extended_address as *const _ as *const u8, |
| 84 | pib_attribute: PibId::ExtendedAddress, | 82 | pib_attribute: PibId::ExtendedAddress, |
| 85 | }) | 83 | }) |
| 86 | .await | 84 | .await |
| 87 | .unwrap(); | 85 | .unwrap(); |
| 88 | defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap()); | 86 | defmt::info!("{:#x}", mac_rx.read().await.unwrap()); |
| 89 | 87 | ||
| 90 | info!("setting short address"); | 88 | info!("setting short address"); |
| 91 | let short_address: u16 = 0x1122; | 89 | let short_address: u16 = 0x1122; |
| 92 | mbox.mac_subsystem | 90 | mac_tx |
| 93 | .send_command(&SetRequest { | 91 | .send_command(&SetRequest { |
| 94 | pib_attribute_ptr: &short_address as *const _ as *const u8, | 92 | pib_attribute_ptr: &short_address as *const _ as *const u8, |
| 95 | pib_attribute: PibId::ShortAddress, | 93 | pib_attribute: PibId::ShortAddress, |
| 96 | }) | 94 | }) |
| 97 | .await | 95 | .await |
| 98 | .unwrap(); | 96 | .unwrap(); |
| 99 | defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap()); | 97 | defmt::info!("{:#x}", mac_rx.read().await.unwrap()); |
| 100 | 98 | ||
| 101 | info!("setting association permit"); | 99 | info!("setting association permit"); |
| 102 | let association_permit: bool = true; | 100 | let association_permit: bool = true; |
| 103 | mbox.mac_subsystem | 101 | mac_tx |
| 104 | .send_command(&SetRequest { | 102 | .send_command(&SetRequest { |
| 105 | pib_attribute_ptr: &association_permit as *const _ as *const u8, | 103 | pib_attribute_ptr: &association_permit as *const _ as *const u8, |
| 106 | pib_attribute: PibId::AssociationPermit, | 104 | pib_attribute: PibId::AssociationPermit, |
| 107 | }) | 105 | }) |
| 108 | .await | 106 | .await |
| 109 | .unwrap(); | 107 | .unwrap(); |
| 110 | defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap()); | 108 | defmt::info!("{:#x}", mac_rx.read().await.unwrap()); |
| 111 | 109 | ||
| 112 | info!("setting TX power"); | 110 | info!("setting TX power"); |
| 113 | let transmit_power: i8 = 2; | 111 | let transmit_power: i8 = 2; |
| 114 | mbox.mac_subsystem | 112 | mac_tx |
| 115 | .send_command(&SetRequest { | 113 | .send_command(&SetRequest { |
| 116 | pib_attribute_ptr: &transmit_power as *const _ as *const u8, | 114 | pib_attribute_ptr: &transmit_power as *const _ as *const u8, |
| 117 | pib_attribute: PibId::TransmitPower, | 115 | pib_attribute: PibId::TransmitPower, |
| 118 | }) | 116 | }) |
| 119 | .await | 117 | .await |
| 120 | .unwrap(); | 118 | .unwrap(); |
| 121 | defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap()); | 119 | defmt::info!("{:#x}", mac_rx.read().await.unwrap()); |
| 122 | 120 | ||
| 123 | info!("starting FFD device"); | 121 | info!("starting FFD device"); |
| 124 | mbox.mac_subsystem | 122 | mac_tx |
| 125 | .send_command(&StartRequest { | 123 | .send_command(&StartRequest { |
| 126 | pan_id: PanId([0x1A, 0xAA]), | 124 | pan_id: PanId([0x1A, 0xAA]), |
| 127 | channel_number: MacChannel::Channel16, | 125 | channel_number: MacChannel::Channel16, |
| @@ -133,28 +131,27 @@ async fn main(spawner: Spawner) { | |||
| 133 | }) | 131 | }) |
| 134 | .await | 132 | .await |
| 135 | .unwrap(); | 133 | .unwrap(); |
| 136 | defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap()); | 134 | defmt::info!("{:#x}", mac_rx.read().await.unwrap()); |
| 137 | 135 | ||
| 138 | info!("setting RX on when idle"); | 136 | info!("setting RX on when idle"); |
| 139 | let rx_on_while_idle: bool = true; | 137 | let rx_on_while_idle: bool = true; |
| 140 | mbox.mac_subsystem | 138 | mac_tx |
| 141 | .send_command(&SetRequest { | 139 | .send_command(&SetRequest { |
| 142 | pib_attribute_ptr: &rx_on_while_idle as *const _ as *const u8, | 140 | pib_attribute_ptr: &rx_on_while_idle as *const _ as *const u8, |
| 143 | pib_attribute: PibId::RxOnWhenIdle, | 141 | pib_attribute: PibId::RxOnWhenIdle, |
| 144 | }) | 142 | }) |
| 145 | .await | 143 | .await |
| 146 | .unwrap(); | 144 | .unwrap(); |
| 147 | defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap()); | 145 | defmt::info!("{:#x}", mac_rx.read().await.unwrap()); |
| 148 | 146 | ||
| 149 | loop { | 147 | loop { |
| 150 | let evt = mbox.mac_subsystem.read().await; | 148 | let evt = mac_rx.read().await; |
| 151 | if let Ok(evt) = evt { | 149 | if let Ok(evt) = evt { |
| 152 | defmt::info!("parsed mac event"); | 150 | defmt::info!("parsed mac event"); |
| 153 | defmt::info!("{:#x}", evt); | 151 | defmt::info!("{:#x}", evt); |
| 154 | 152 | ||
| 155 | match evt { | 153 | match evt { |
| 156 | MacEvent::MlmeAssociateInd(association) => mbox | 154 | MacEvent::MlmeAssociateInd(association) => mac_tx |
| 157 | .mac_subsystem | ||
| 158 | .send_command(&AssociateResponse { | 155 | .send_command(&AssociateResponse { |
| 159 | device_address: association.device_address, | 156 | device_address: association.device_address, |
| 160 | assoc_short_address: [0x33, 0x44], | 157 | assoc_short_address: [0x33, 0x44], |
