embassy/embassy-stm32-wpan/src/lib.rs

154 lines
5.1 KiB
Rust
Raw Normal View History

#![no_std]
2023-07-16 02:15:01 +02:00
#![cfg_attr(any(feature = "ble", feature = "mac"), feature(async_fn_in_trait))]
#![cfg_attr(feature = "mac", feature(type_alias_impl_trait, concat_bytes))]
// This must go FIRST so that all the other modules see its macros.
2023-08-09 18:33:20 +02:00
mod fmt;
use core::mem::MaybeUninit;
2023-06-14 00:12:34 +02:00
use core::sync::atomic::{compiler_fence, Ordering};
use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef};
use embassy_stm32::interrupt;
2023-06-17 19:00:33 +02:00
use embassy_stm32::ipcc::{Config, Ipcc, ReceiveInterruptHandler, TransmitInterruptHandler};
use embassy_stm32::peripherals::IPCC;
2023-06-24 00:54:06 +02:00
use sub::mm::MemoryManager;
use sub::sys::Sys;
2023-06-18 17:11:36 +02:00
use tables::*;
use unsafe_linked_list::LinkedListNode;
2023-06-08 17:26:47 +02:00
pub mod channels;
pub mod cmd;
pub mod consts;
pub mod evt;
2023-06-22 16:21:14 +02:00
pub mod lhci;
2023-06-08 17:26:47 +02:00
pub mod shci;
2023-06-24 00:54:06 +02:00
pub mod sub;
pub mod tables;
2023-06-08 17:26:47 +02:00
pub mod unsafe_linked_list;
2023-07-15 21:47:34 +02:00
#[cfg(feature = "mac")]
pub mod mac;
2023-06-24 00:54:06 +02:00
#[cfg(feature = "ble")]
pub use crate::sub::ble::hci;
2023-06-08 17:26:47 +02:00
type PacketHeader = LinkedListNode;
pub struct TlMbox<'d> {
2023-05-27 22:05:23 +02:00
_ipcc: PeripheralRef<'d, IPCC>,
2023-06-17 22:37:34 +02:00
pub sys_subsystem: Sys,
pub mm_subsystem: MemoryManager,
2023-06-19 01:51:14 +02:00
#[cfg(feature = "ble")]
2023-06-24 00:54:06 +02:00
pub ble_subsystem: sub::ble::Ble,
2023-06-19 01:51:14 +02:00
#[cfg(feature = "mac")]
2023-06-24 00:54:06 +02:00
pub mac_subsystem: sub::mac::Mac,
}
2023-05-27 22:05:23 +02:00
impl<'d> TlMbox<'d> {
pub fn init(
2023-05-27 22:05:23 +02:00
ipcc: impl Peripheral<P = IPCC> + 'd,
2023-06-12 15:44:30 +02:00
_irqs: impl interrupt::typelevel::Binding<interrupt::typelevel::IPCC_C1_RX, ReceiveInterruptHandler>
+ interrupt::typelevel::Binding<interrupt::typelevel::IPCC_C1_TX, TransmitInterruptHandler>,
2023-05-26 10:56:55 +02:00
config: Config,
2023-05-27 22:05:23 +02:00
) -> Self {
into_ref!(ipcc);
unsafe {
2023-06-14 00:12:34 +02:00
TL_REF_TABLE.as_mut_ptr().write_volatile(RefTable {
device_info_table: TL_DEVICE_INFO_TABLE.as_ptr(),
ble_table: TL_BLE_TABLE.as_ptr(),
thread_table: TL_THREAD_TABLE.as_ptr(),
sys_table: TL_SYS_TABLE.as_ptr(),
mem_manager_table: TL_MEM_MANAGER_TABLE.as_ptr(),
traces_table: TL_TRACES_TABLE.as_ptr(),
mac_802_15_4_table: TL_MAC_802_15_4_TABLE.as_ptr(),
2023-07-09 22:50:01 +02:00
zigbee_table: TL_ZIGBEE_TABLE.as_ptr(),
lld_tests_table: TL_LLD_TESTS_TABLE.as_ptr(),
ble_lld_table: TL_BLE_LLD_TABLE.as_ptr(),
});
2023-06-14 00:12:34 +02:00
TL_SYS_TABLE
.as_mut_ptr()
.write_volatile(MaybeUninit::zeroed().assume_init());
TL_DEVICE_INFO_TABLE
.as_mut_ptr()
.write_volatile(MaybeUninit::zeroed().assume_init());
TL_BLE_TABLE
.as_mut_ptr()
.write_volatile(MaybeUninit::zeroed().assume_init());
TL_THREAD_TABLE
.as_mut_ptr()
.write_volatile(MaybeUninit::zeroed().assume_init());
TL_MEM_MANAGER_TABLE
.as_mut_ptr()
.write_volatile(MaybeUninit::zeroed().assume_init());
TL_TRACES_TABLE
.as_mut_ptr()
.write_volatile(MaybeUninit::zeroed().assume_init());
TL_MAC_802_15_4_TABLE
.as_mut_ptr()
.write_volatile(MaybeUninit::zeroed().assume_init());
2023-07-09 22:50:01 +02:00
TL_ZIGBEE_TABLE
.as_mut_ptr()
.write_volatile(MaybeUninit::zeroed().assume_init());
TL_LLD_TESTS_TABLE
.as_mut_ptr()
.write_volatile(MaybeUninit::zeroed().assume_init());
TL_BLE_LLD_TABLE
.as_mut_ptr()
.write_volatile(MaybeUninit::zeroed().assume_init());
2023-06-14 00:12:34 +02:00
EVT_POOL
.as_mut_ptr()
.write_volatile(MaybeUninit::zeroed().assume_init());
SYS_SPARE_EVT_BUF
.as_mut_ptr()
.write_volatile(MaybeUninit::zeroed().assume_init());
2023-07-09 22:50:01 +02:00
CS_BUFFER
2023-06-14 00:12:34 +02:00
.as_mut_ptr()
.write_volatile(MaybeUninit::zeroed().assume_init());
2023-07-09 22:50:01 +02:00
#[cfg(feature = "ble")]
2023-06-14 00:12:34 +02:00
{
2023-07-09 22:50:01 +02:00
BLE_SPARE_EVT_BUF
.as_mut_ptr()
.write_volatile(MaybeUninit::zeroed().assume_init());
2023-06-14 00:12:34 +02:00
BLE_CMD_BUFFER
.as_mut_ptr()
.write_volatile(MaybeUninit::zeroed().assume_init());
HCI_ACL_DATA_BUFFER
.as_mut_ptr()
.write_volatile(MaybeUninit::zeroed().assume_init());
2023-07-09 22:50:01 +02:00
}
#[cfg(feature = "mac")]
{
MAC_802_15_4_CMD_BUFFER
.as_mut_ptr()
.write_volatile(MaybeUninit::zeroed().assume_init());
MAC_802_15_4_NOTIF_RSP_EVT_BUFFER
2023-06-14 00:12:34 +02:00
.as_mut_ptr()
.write_volatile(MaybeUninit::zeroed().assume_init());
}
}
2023-06-14 00:12:34 +02:00
compiler_fence(Ordering::SeqCst);
2023-05-27 22:05:23 +02:00
Ipcc::enable(config);
2023-06-17 22:37:34 +02:00
Self {
_ipcc: ipcc,
2023-06-24 00:54:06 +02:00
sys_subsystem: sub::sys::Sys::new(),
2023-06-19 01:51:14 +02:00
#[cfg(feature = "ble")]
2023-06-24 00:54:06 +02:00
ble_subsystem: sub::ble::Ble::new(),
2023-06-19 01:51:14 +02:00
#[cfg(feature = "mac")]
2023-06-24 00:54:06 +02:00
mac_subsystem: sub::mac::Mac::new(),
mm_subsystem: sub::mm::MemoryManager::new(),
}
}
}