wpan: add mac test

This commit is contained in:
xoviat 2023-07-15 14:28:42 -05:00
parent d6dd5ea5d3
commit d11a94e2a7
4 changed files with 124 additions and 8 deletions

View File

@ -12,14 +12,15 @@ stm32g071rb = ["embassy-stm32/stm32g071rb", "not-gpdma"] # Nucleo
stm32c031c6 = ["embassy-stm32/stm32c031c6", "not-gpdma"] # Nucleo
stm32g491re = ["embassy-stm32/stm32g491re", "not-gpdma"] # Nucleo
stm32h755zi = ["embassy-stm32/stm32h755zi-cm7", "not-gpdma"] # Nucleo
stm32wb55rg = ["embassy-stm32/stm32wb55rg", "not-gpdma", "ble" ] # Nucleo
stm32wb55rg = ["embassy-stm32/stm32wb55rg", "not-gpdma", "ble", "mac" ] # Nucleo
stm32h563zi = ["embassy-stm32/stm32h563zi"] # Nucleo
stm32u585ai = ["embassy-stm32/stm32u585ai"] # IoT board
sdmmc = []
chrono = ["embassy-stm32/chrono", "dep:chrono"]
can = []
ble = ["dep:embassy-stm32-wpan"]
ble = ["dep:embassy-stm32-wpan", "embassy-stm32-wpan/ble"]
mac = ["dep:embassy-stm32-wpan", "embassy-stm32-wpan/mac"]
not-gpdma = []
[dependencies]
@ -48,11 +49,6 @@ chrono = { version = "^0.4", default-features = false, optional = true}
# BEGIN TESTS
# Generated by gen_test.py. DO NOT EDIT.
[[bin]]
name = "tl_mbox"
path = "src/bin/tl_mbox.rs"
required-features = [ "ble",]
[[bin]]
name = "can"
path = "src/bin/can.rs"
@ -103,6 +99,16 @@ name = "usart_rx_ringbuffered"
path = "src/bin/usart_rx_ringbuffered.rs"
required-features = [ "not-gpdma",]
[[bin]]
name = "wpan_ble"
path = "src/bin/wpan_ble.rs"
required-features = [ "ble",]
[[bin]]
name = "wpan_mac"
path = "src/bin/wpan_mac.rs"
required-features = [ "mac",]
# END TESTS
[profile.dev]

View File

@ -1,3 +1,5 @@
// required-features: chrono
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]

View File

@ -64,7 +64,7 @@ async fn main(spawner: Spawner) {
version_major, version_minor, subversion, sram2a_size, sram2b_size
);
mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await;
let _ = mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await;
info!("resetting BLE...");
mbox.ble_subsystem.reset().await;

View File

@ -0,0 +1,108 @@
// required-features: mac
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
#[path = "../common.rs"]
mod common;
use common::*;
use embassy_executor::Spawner;
use embassy_stm32::bind_interrupts;
use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
use embassy_stm32_wpan::sub::mac::commands::{AssociateRequest, GetRequest, ResetRequest, SetRequest};
use embassy_stm32_wpan::sub::mac::event::MacEvent;
use embassy_stm32_wpan::sub::mac::typedefs::{
AddressMode, Capabilities, KeyIdMode, MacAddress, MacChannel, PanId, PibId, SecurityLevel,
};
use embassy_stm32_wpan::sub::mm;
use embassy_stm32_wpan::TlMbox;
use {defmt_rtt as _, panic_probe as _};
bind_interrupts!(struct Irqs{
IPCC_C1_RX => ReceiveInterruptHandler;
IPCC_C1_TX => TransmitInterruptHandler;
});
#[embassy_executor::task]
async fn run_mm_queue(memory_manager: mm::MemoryManager) {
memory_manager.run_queue().await;
}
#[embassy_executor::main]
async fn main(spawner: Spawner) {
let p = embassy_stm32::init(config());
info!("Hello World!");
let config = Config::default();
let mbox = TlMbox::init(p.IPCC, Irqs, config);
spawner.spawn(run_mm_queue(mbox.mm_subsystem)).unwrap();
let sys_event = mbox.sys_subsystem.read().await;
info!("sys event: {}", sys_event.payload());
core::mem::drop(sys_event);
let result = mbox.sys_subsystem.shci_c2_mac_802_15_4_init().await;
info!("initialized mac: {}", result);
info!("resetting");
mbox.mac_subsystem
.send_command(&ResetRequest { set_default_pib: true })
.await
.unwrap();
let evt = mbox.mac_subsystem.read().await;
info!("{:#x}", evt);
info!("setting extended address");
let extended_address: u64 = 0xACDE480000000002;
mbox.mac_subsystem
.send_command(&SetRequest {
pib_attribute_ptr: &extended_address as *const _ as *const u8,
pib_attribute: PibId::ExtendedAddress,
})
.await
.unwrap();
let evt = mbox.mac_subsystem.read().await;
info!("{:#x}", evt);
info!("getting extended address");
mbox.mac_subsystem
.send_command(&GetRequest {
pib_attribute: PibId::ExtendedAddress,
})
.await
.unwrap();
let evt = mbox.mac_subsystem.read().await;
info!("{:#x}", evt);
if let Ok(MacEvent::MlmeGetCnf(evt)) = evt {
if evt.pib_attribute_value_len == 8 {
let value = unsafe { core::ptr::read_unaligned(evt.pib_attribute_value_ptr as *const u64) };
info!("value {:#x}", value)
}
}
info!("assocation request");
let a = AssociateRequest {
channel_number: MacChannel::Channel16,
channel_page: 0,
coord_addr_mode: AddressMode::Short,
coord_address: MacAddress { short: [34, 17] },
capability_information: Capabilities::ALLOCATE_ADDRESS,
coord_pan_id: PanId([0x1A, 0xAA]),
security_level: SecurityLevel::Unsecure,
key_id_mode: KeyIdMode::Implicite,
key_source: [0; 8],
key_index: 152,
};
info!("{}", a);
mbox.mac_subsystem.send_command(&a).await.unwrap();
let evt = mbox.mac_subsystem.read().await;
info!("{:#x}", evt);
info!("Test OK");
cortex_m::asm::bkpt();
}