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

140 lines
4.7 KiB
Rust
Raw Normal View History

#![no_std]
2023-06-22 16:21:14 +02:00
#![cfg_attr(feature = "ble", feature(async_fn_in_trait))]
// This must go FIRST so that all the other modules see its macros.
pub mod fmt;
use core::mem::MaybeUninit;
2023-06-14 00:12:34 +02:00
use core::sync::atomic::{compiler_fence, Ordering};
2023-05-27 22:05:23 +02:00
use embassy_hal_common::{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-17 22:37:34 +02:00
use mm::MemoryManager;
use sys::Sys;
2023-06-18 17:11:36 +02:00
use tables::*;
use unsafe_linked_list::LinkedListNode;
2023-06-19 01:51:14 +02:00
#[cfg(feature = "ble")]
2023-06-08 17:26:47 +02:00
pub mod ble;
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-19 01:51:14 +02:00
#[cfg(feature = "mac")]
pub mod mac;
2023-06-08 17:26:47 +02:00
pub mod mm;
pub mod shci;
pub mod sys;
pub mod tables;
2023-06-08 17:26:47 +02:00
pub mod unsafe_linked_list;
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")]
pub ble_subsystem: ble::Ble,
#[cfg(feature = "mac")]
pub mac_subsystem: 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-06-14 00:12:34 +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-06-14 00:17:10 +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());
BLE_SPARE_EVT_BUF
.as_mut_ptr()
.write_volatile(MaybeUninit::zeroed().assume_init());
{
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());
CS_BUFFER
.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,
sys_subsystem: sys::Sys::new(),
2023-06-19 01:51:14 +02:00
#[cfg(feature = "ble")]
ble_subsystem: ble::Ble::new(),
2023-06-19 01:51:14 +02:00
#[cfg(feature = "mac")]
mac_subsystem: mac::Mac::new(),
mm_subsystem: mm::MemoryManager::new(),
}
}
}