stm32/ipcc: support for MAC 802.15.4
This commit is contained in:
parent
6efcc9acaa
commit
abbaaeee37
8 changed files with 306 additions and 102 deletions
|
@ -110,6 +110,16 @@ unstable-pac = []
|
|||
# Implement embedded-hal-async traits if `nightly` is set as well.
|
||||
unstable-traits = ["embedded-hal-1", "dep:embedded-hal-nb"]
|
||||
|
||||
# stm32wb specific
|
||||
# support for wireless stacks
|
||||
ble = []
|
||||
thread = []
|
||||
lld-tests = []
|
||||
ble-lld = []
|
||||
mac-802_15_4 = []
|
||||
zigbee = []
|
||||
traces = []
|
||||
|
||||
# Chip-selection features
|
||||
stm32c011d6 = [ "stm32-metapac/stm32c011d6" ]
|
||||
stm32c011f4 = [ "stm32-metapac/stm32c011f4" ]
|
||||
|
|
|
@ -16,7 +16,7 @@ use crate::tl_mbox::cmd::CmdPacket;
|
|||
pub struct Ble;
|
||||
|
||||
impl Ble {
|
||||
pub(crate) fn new(ipcc: &mut Ipcc) -> Self {
|
||||
pub(crate) fn init(ipcc: &mut Ipcc) -> Self {
|
||||
unsafe {
|
||||
LinkedListNode::init_head(EVT_QUEUE.as_mut_ptr());
|
||||
|
||||
|
@ -28,7 +28,7 @@ impl Ble {
|
|||
});
|
||||
}
|
||||
|
||||
ipcc.c1_set_rx_channel(channels::cpu2::IPCC_BLE_EVENT_CHANNEL, true);
|
||||
ipcc.c1_set_rx_channel(channels::Cpu2Channel::BleEvent.into(), true);
|
||||
|
||||
Ble
|
||||
}
|
||||
|
@ -48,7 +48,11 @@ impl Ble {
|
|||
}
|
||||
}
|
||||
|
||||
ipcc.c1_clear_flag_channel(channels::cpu2::IPCC_BLE_EVENT_CHANNEL);
|
||||
ipcc.c1_clear_flag_channel(channels::Cpu2Channel::BleEvent.into());
|
||||
}
|
||||
|
||||
pub(crate) fn acl_data_evt_handler(ipcc: &mut Ipcc) {
|
||||
ipcc.c1_set_tx_channel(channels::Cpu1Channel::HciAclData.into(), false);
|
||||
}
|
||||
|
||||
pub(crate) fn send_cmd(ipcc: &mut Ipcc, buf: &[u8]) {
|
||||
|
@ -63,6 +67,17 @@ impl Ble {
|
|||
cmd_packet.cmd_serial.ty = TlPacketType::BleCmd as u8;
|
||||
}
|
||||
|
||||
ipcc.c1_set_flag_channel(channels::cpu1::IPCC_BLE_CMD_CHANNEL);
|
||||
ipcc.c1_set_flag_channel(channels::Cpu1Channel::BleCmd.into());
|
||||
}
|
||||
|
||||
pub(crate) fn send_acl_data(ipcc: &mut Ipcc) {
|
||||
unsafe {
|
||||
(*(*TL_REF_TABLE.assume_init().ble_table).phci_acl_data_buffer)
|
||||
.acl_data_serial
|
||||
.ty = TlPacketType::AclData as u8;
|
||||
}
|
||||
|
||||
ipcc.c1_set_flag_channel(channels::Cpu1Channel::HciAclData.into());
|
||||
ipcc.c1_set_tx_channel(channels::Cpu1Channel::HciAclData.into(), true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,56 +49,104 @@
|
|||
//! | |
|
||||
//!
|
||||
|
||||
pub mod cpu1 {
|
||||
use crate::ipcc::IpccChannel;
|
||||
use crate::ipcc::IpccChannel;
|
||||
|
||||
// Not used currently but reserved
|
||||
pub const IPCC_BLE_CMD_CHANNEL: IpccChannel = IpccChannel::Channel1;
|
||||
// Not used currently but reserved
|
||||
pub const IPCC_SYSTEM_CMD_RSP_CHANNEL: IpccChannel = IpccChannel::Channel2;
|
||||
#[allow(dead_code)] // Not used currently but reserved
|
||||
pub const IPCC_THREAD_OT_CMD_RSP_CHANNEL: IpccChannel = IpccChannel::Channel3;
|
||||
#[allow(dead_code)] // Not used currently but reserved
|
||||
pub const IPCC_ZIGBEE_CMD_APPLI_CHANNEL: IpccChannel = IpccChannel::Channel3;
|
||||
#[allow(dead_code)] // Not used currently but reserved
|
||||
pub const IPCC_MAC_802_15_4_CMD_RSP_CHANNEL: IpccChannel = IpccChannel::Channel3;
|
||||
// Not used currently but reserved
|
||||
pub const IPCC_MM_RELEASE_BUFFER_CHANNEL: IpccChannel = IpccChannel::Channel4;
|
||||
#[allow(dead_code)] // Not used currently but reserved
|
||||
pub const IPCC_THREAD_CLI_CMD_CHANNEL: IpccChannel = IpccChannel::Channel5;
|
||||
#[allow(dead_code)] // Not used currently but reserved
|
||||
pub const IPCC_LLDTESTS_CLI_CMD_CHANNEL: IpccChannel = IpccChannel::Channel5;
|
||||
#[allow(dead_code)] // Not used currently but reserved
|
||||
pub const IPCC_BLE_LLD_CMD_CHANNEL: IpccChannel = IpccChannel::Channel5;
|
||||
#[allow(dead_code)] // Not used currently but reserved
|
||||
pub const IPCC_HCI_ACL_DATA_CHANNEL: IpccChannel = IpccChannel::Channel6;
|
||||
pub enum Cpu1Channel {
|
||||
BleCmd,
|
||||
SystemCmdRsp,
|
||||
#[cfg(feature = "thread")]
|
||||
ThreadOtCmdRsp,
|
||||
#[cfg(feature = "zigbee")]
|
||||
ZigbeeCmdAppli,
|
||||
MmReleaseBuffer,
|
||||
#[cfg(feature = "mac-802_15_4")]
|
||||
Mac802_15_4cmdRsp,
|
||||
#[cfg(feature = "thread")]
|
||||
ThreadCliCmd,
|
||||
#[cfg(feature = "lld-tests")]
|
||||
LldTestsCliCmd,
|
||||
#[cfg(feature = "ble-lld")]
|
||||
BleLldCmd,
|
||||
HciAclData,
|
||||
}
|
||||
|
||||
pub mod cpu2 {
|
||||
use crate::ipcc::IpccChannel;
|
||||
|
||||
pub const IPCC_BLE_EVENT_CHANNEL: IpccChannel = IpccChannel::Channel1;
|
||||
pub const IPCC_SYSTEM_EVENT_CHANNEL: IpccChannel = IpccChannel::Channel2;
|
||||
#[allow(dead_code)] // Not used currently but reserved
|
||||
pub const IPCC_THREAD_NOTIFICATION_ACK_CHANNEL: IpccChannel = IpccChannel::Channel3;
|
||||
#[allow(dead_code)] // Not used currently but reserved
|
||||
pub const IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL: IpccChannel = IpccChannel::Channel3;
|
||||
#[allow(dead_code)] // Not used currently but reserved
|
||||
pub const IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL: IpccChannel = IpccChannel::Channel3;
|
||||
#[allow(dead_code)] // Not used currently but reserved
|
||||
pub const IPCC_LDDTESTS_M0_CMD_CHANNEL: IpccChannel = IpccChannel::Channel3;
|
||||
#[allow(dead_code)] // Not used currently but reserved
|
||||
pub const IPCC_BLE_LLD_M0_CMD_CHANNEL: IpccChannel = IpccChannel::Channel3;
|
||||
#[allow(dead_code)] // Not used currently but reserved
|
||||
pub const IPCC_TRACES_CHANNEL: IpccChannel = IpccChannel::Channel4;
|
||||
#[allow(dead_code)] // Not used currently but reserved
|
||||
pub const IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL: IpccChannel = IpccChannel::Channel5;
|
||||
#[allow(dead_code)] // Not used currently but reserved
|
||||
pub const IPCC_LLDTESTS_CLI_RSP_CHANNEL: IpccChannel = IpccChannel::Channel5;
|
||||
#[allow(dead_code)] // Not used currently but reserved
|
||||
pub const IPCC_BLE_LLD_CLI_RSP_CHANNEL: IpccChannel = IpccChannel::Channel5;
|
||||
#[allow(dead_code)] // Not used currently but reserved
|
||||
pub const IPCC_BLE_LLD_RSP_CHANNEL: IpccChannel = IpccChannel::Channel5;
|
||||
#[allow(dead_code)] // Not used currently but reserved
|
||||
pub const IPCC_ZIGBEE_M0_REQUEST_CHANNEL: IpccChannel = IpccChannel::Channel5;
|
||||
impl From<Cpu1Channel> for IpccChannel {
|
||||
fn from(value: Cpu1Channel) -> Self {
|
||||
match value {
|
||||
Cpu1Channel::BleCmd => IpccChannel::Channel1,
|
||||
Cpu1Channel::SystemCmdRsp => IpccChannel::Channel2,
|
||||
#[cfg(feature = "thread")]
|
||||
Cpu1Channel::ThreadOtCmdRsp => IpccChannel::Channel3,
|
||||
#[cfg(feature = "zigbee")]
|
||||
Cpu1Channel::ZigbeeCmdAppli => IpccChannel::Channel3,
|
||||
#[cfg(feature = "mac-802_15_4")]
|
||||
Cpu1Channel::Mac802_15_4cmdRsp => IpccChannel::Channel3,
|
||||
Cpu1Channel::MmReleaseBuffer => IpccChannel::Channel4,
|
||||
#[cfg(feature = "thread")]
|
||||
Cpu1Channel::ThreadCliCmd => IpccChannel::Channel5,
|
||||
#[cfg(feature = "lld-tests")]
|
||||
Cpu1Channel::LldTestsCliCmd => IpccChannel::Channel5,
|
||||
#[cfg(feature = "ble-lld")]
|
||||
Cpu1Channel::BleLldCmd => IpccChannel::Channel5,
|
||||
Cpu1Channel::HciAclData => IpccChannel::Channel6,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum Cpu2Channel {
|
||||
BleEvent,
|
||||
SystemEvent,
|
||||
#[cfg(feature = "thread")]
|
||||
ThreadNotifAck,
|
||||
#[cfg(feature = "zigbee")]
|
||||
ZigbeeAppliNotifAck,
|
||||
#[cfg(feature = "mac-802_15_4")]
|
||||
Mac802_15_4NotifAck,
|
||||
#[cfg(feature = "lld-tests")]
|
||||
LldTestsM0Cmd,
|
||||
#[cfg(feature = "ble-lld")]
|
||||
BleLldM0Cmd,
|
||||
#[cfg(feature = "traces")]
|
||||
Traces,
|
||||
#[cfg(feature = "thread")]
|
||||
ThreadCliNotifAck,
|
||||
#[cfg(feature = "lld-tests")]
|
||||
LldTestsCliRsp,
|
||||
#[cfg(feature = "ble-lld")]
|
||||
BleLldCliRsp,
|
||||
#[cfg(feature = "ble-lld")]
|
||||
BleLldRsp,
|
||||
#[cfg(feature = "zigbee")]
|
||||
ZigbeeM0Request,
|
||||
}
|
||||
|
||||
impl From<Cpu2Channel> for IpccChannel {
|
||||
fn from(value: Cpu2Channel) -> Self {
|
||||
match value {
|
||||
Cpu2Channel::BleEvent => IpccChannel::Channel1,
|
||||
Cpu2Channel::SystemEvent => IpccChannel::Channel2,
|
||||
#[cfg(feature = "thread")]
|
||||
Cpu2Channel::ThreadNotifAck => IpccChannel::Channel3,
|
||||
#[cfg(feature = "zigbee")]
|
||||
Cpu2Channel::ZigbeeAppliNotifAck => IpccChannel::Channel3,
|
||||
#[cfg(feature = "mac-802_15_4")]
|
||||
Cpu2Channel::Mac802_15_4NotifAck => IpccChannel::Channel3,
|
||||
#[cfg(feature = "lld-tests")]
|
||||
Cpu2Channel::LldTestsM0Cmd => IpccChannel::Channel3,
|
||||
#[cfg(feature = "ble-lld")]
|
||||
Cpu2Channel::BleLldM0Cmd => IpccChannel::Channel3,
|
||||
#[cfg(feature = "traces")]
|
||||
Cpu2Channel::Traces => IpccChannel::Channel4,
|
||||
#[cfg(feature = "thread")]
|
||||
Cpu2Channel::ThreadCliNotifAck => IpccChannel::Channel5,
|
||||
#[cfg(feature = "lld-tests")]
|
||||
Cpu2Channel::LldTestsCliRsp => IpccChannel::Channel5,
|
||||
#[cfg(feature = "ble-lld")]
|
||||
Cpu2Channel::BleLldCliRsp => IpccChannel::Channel5,
|
||||
#[cfg(feature = "ble-lld")]
|
||||
Cpu2Channel::BleLldRsp => IpccChannel::Channel5,
|
||||
#[cfg(feature = "zigbee")]
|
||||
Cpu2Channel::ZigbeeM0Request => IpccChannel::Channel5,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
82
embassy-stm32/src/tl_mbox/mac_802_15_4.rs
Normal file
82
embassy-stm32/src/tl_mbox/mac_802_15_4.rs
Normal file
|
@ -0,0 +1,82 @@
|
|||
use core::mem::MaybeUninit;
|
||||
|
||||
use embassy_futures::block_on;
|
||||
|
||||
use super::cmd::{CmdPacket, CmdSerial};
|
||||
use super::consts::TlPacketType;
|
||||
use super::evt::{EvtBox, EvtPacket};
|
||||
use super::unsafe_linked_list::LinkedListNode;
|
||||
use super::{
|
||||
channels, Mac802_15_4Table, EVT_QUEUE, MAC_802_15_4_CMD_BUFFER, MAC_802_15_4_NOTIF_RSP_EVT_BUFFER, TL_CHANNEL,
|
||||
TL_MAC_802_15_4_TABLE, TL_REF_TABLE,
|
||||
};
|
||||
use crate::ipcc::Ipcc;
|
||||
|
||||
pub struct Mac802_15_4;
|
||||
|
||||
impl Mac802_15_4 {
|
||||
pub(crate) fn init(ipcc: &mut Ipcc) -> Self {
|
||||
unsafe {
|
||||
LinkedListNode::init_head(EVT_QUEUE.as_mut_ptr());
|
||||
|
||||
TL_MAC_802_15_4_TABLE = MaybeUninit::new(Mac802_15_4Table {
|
||||
pcmd_rsp_buffer: MAC_802_15_4_CMD_BUFFER.as_mut_ptr().cast(),
|
||||
pnotack_buffer: MAC_802_15_4_NOTIF_RSP_EVT_BUFFER.as_mut_ptr().cast(),
|
||||
evt_queue: EVT_QUEUE.as_ptr().cast(),
|
||||
});
|
||||
}
|
||||
|
||||
ipcc.c1_set_rx_channel(channels::Cpu2Channel::Mac802_15_4NotifAck.into(), true);
|
||||
|
||||
Self
|
||||
}
|
||||
|
||||
pub(crate) fn notif_evt_handler(ipcc: &mut Ipcc) {
|
||||
unsafe {
|
||||
let notif_buffer: *mut EvtPacket = (*TL_REF_TABLE.assume_init().mac_802_15_4_table).pnotack_buffer.cast();
|
||||
let event = EvtBox::new(notif_buffer);
|
||||
|
||||
block_on(TL_CHANNEL.send(event));
|
||||
}
|
||||
|
||||
ipcc.c1_set_rx_channel(channels::Cpu2Channel::Mac802_15_4NotifAck.into(), false);
|
||||
}
|
||||
|
||||
pub(crate) fn cmd_evt_handler(ipcc: &mut Ipcc) {
|
||||
unsafe {
|
||||
let _notif_buffer = (*TL_REF_TABLE.assume_init().mac_802_15_4_table).pcmd_rsp_buffer;
|
||||
|
||||
// NOTE: ST's HAL does nothing with this buffer, ??????
|
||||
}
|
||||
|
||||
ipcc.c1_set_tx_channel(channels::Cpu1Channel::Mac802_15_4cmdRsp.into(), false);
|
||||
}
|
||||
|
||||
pub(crate) fn send_cmd(ipcc: &mut Ipcc, buf: &[u8]) {
|
||||
unsafe {
|
||||
let pcmd_buffer: *mut CmdPacket = (*TL_REF_TABLE.assume_init().mac_802_15_4_table).pcmd_rsp_buffer.cast();
|
||||
let pcmd_serial: *mut CmdSerial = &mut (*pcmd_buffer).cmd_serial;
|
||||
let pcmd_serial_buf: *mut u8 = pcmd_serial.cast();
|
||||
|
||||
core::ptr::copy(buf.as_ptr(), pcmd_serial_buf, buf.len());
|
||||
|
||||
let cmd_packet: &mut CmdPacket =
|
||||
&mut *(*TL_REF_TABLE.assume_init().mac_802_15_4_table).pcmd_rsp_buffer.cast();
|
||||
cmd_packet.cmd_serial.ty = TlPacketType::OtCmd as u8;
|
||||
}
|
||||
|
||||
ipcc.c1_set_flag_channel(channels::Cpu1Channel::Mac802_15_4cmdRsp.into());
|
||||
ipcc.c1_set_tx_channel(channels::Cpu1Channel::Mac802_15_4cmdRsp.into(), true);
|
||||
}
|
||||
|
||||
pub(crate) fn send_ack(ipcc: &mut Ipcc) {
|
||||
// TODO
|
||||
unsafe {
|
||||
let packet: &mut CmdPacket = &mut *(*TL_REF_TABLE.assume_init().mac_802_15_4_table).pnotack_buffer.cast();
|
||||
packet.cmd_serial.ty = TlPacketType::OtAck as u8;
|
||||
}
|
||||
|
||||
ipcc.c1_clear_flag_channel(channels::Cpu2Channel::Mac802_15_4NotifAck.into());
|
||||
ipcc.c1_set_rx_channel(channels::Cpu2Channel::Mac802_15_4NotifAck.into(), true);
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@ use crate::ipcc::Ipcc;
|
|||
pub struct MemoryManager;
|
||||
|
||||
impl MemoryManager {
|
||||
pub fn new() -> Self {
|
||||
pub fn init() -> Self {
|
||||
unsafe {
|
||||
LinkedListNode::init_head(FREE_BUFF_QUEUE.as_mut_ptr());
|
||||
LinkedListNode::init_head(LOCAL_FREE_BUF_QUEUE.as_mut_ptr());
|
||||
|
@ -31,9 +31,9 @@ impl MemoryManager {
|
|||
}
|
||||
|
||||
pub fn evt_handler(ipcc: &mut Ipcc) {
|
||||
ipcc.c1_set_tx_channel(channels::cpu1::IPCC_MM_RELEASE_BUFFER_CHANNEL, false);
|
||||
ipcc.c1_set_tx_channel(channels::Cpu1Channel::MmReleaseBuffer.into(), false);
|
||||
Self::send_free_buf();
|
||||
ipcc.c1_set_flag_channel(channels::cpu1::IPCC_MM_RELEASE_BUFFER_CHANNEL);
|
||||
ipcc.c1_set_flag_channel(channels::Cpu1Channel::MmReleaseBuffer.into());
|
||||
}
|
||||
|
||||
pub fn evt_drop(evt: *mut EvtPacket, ipcc: &mut Ipcc) {
|
||||
|
@ -43,14 +43,14 @@ impl MemoryManager {
|
|||
LinkedListNode::remove_tail(LOCAL_FREE_BUF_QUEUE.as_mut_ptr(), list_node);
|
||||
}
|
||||
|
||||
let channel_is_busy = ipcc.c1_is_active_flag(channels::cpu1::IPCC_MM_RELEASE_BUFFER_CHANNEL);
|
||||
let channel_is_busy = ipcc.c1_is_active_flag(channels::Cpu1Channel::MmReleaseBuffer.into());
|
||||
|
||||
// postpone event buffer freeing to IPCC interrupt handler
|
||||
if channel_is_busy {
|
||||
ipcc.c1_set_tx_channel(channels::cpu1::IPCC_MM_RELEASE_BUFFER_CHANNEL, true);
|
||||
ipcc.c1_set_tx_channel(channels::Cpu1Channel::MmReleaseBuffer.into(), true);
|
||||
} else {
|
||||
Self::send_free_buf();
|
||||
ipcc.c1_set_flag_channel(channels::cpu1::IPCC_MM_RELEASE_BUFFER_CHANNEL);
|
||||
ipcc.c1_set_flag_channel(channels::Cpu1Channel::MmReleaseBuffer.into());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,9 +4,12 @@ use bit_field::BitField;
|
|||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||
use embassy_sync::channel::Channel;
|
||||
|
||||
#[cfg(feature = "ble")]
|
||||
use self::ble::Ble;
|
||||
use self::cmd::{AclDataPacket, CmdPacket};
|
||||
use self::evt::{CsEvt, EvtBox};
|
||||
#[cfg(feature = "mac-802_15_4")]
|
||||
use self::mac_802_15_4::Mac802_15_4;
|
||||
use self::mm::MemoryManager;
|
||||
use self::shci::{shci_ble_init, ShciBleInitCmdParam};
|
||||
use self::sys::Sys;
|
||||
|
@ -14,7 +17,6 @@ use self::unsafe_linked_list::LinkedListNode;
|
|||
use crate::interrupt;
|
||||
use crate::ipcc::Ipcc;
|
||||
|
||||
mod ble;
|
||||
mod channels;
|
||||
mod cmd;
|
||||
mod consts;
|
||||
|
@ -24,6 +26,11 @@ mod shci;
|
|||
mod sys;
|
||||
mod unsafe_linked_list;
|
||||
|
||||
#[cfg(feature = "ble")]
|
||||
mod ble;
|
||||
#[cfg(feature = "mac-802_15_4")]
|
||||
mod mac_802_15_4;
|
||||
|
||||
pub type PacketHeader = LinkedListNode;
|
||||
|
||||
const TL_PACKET_HEADER_SIZE: usize = core::mem::size_of::<PacketHeader>();
|
||||
|
@ -194,8 +201,8 @@ struct TracesTable {
|
|||
|
||||
#[repr(C, packed)]
|
||||
struct Mac802_15_4Table {
|
||||
pcmd_rsp_buffer: *const u8,
|
||||
pnotack_buffer: *const u8,
|
||||
pcmd_rsp_buffer: *mut u8,
|
||||
pnotack_buffer: *mut u8,
|
||||
evt_queue: *const u8,
|
||||
}
|
||||
|
||||
|
@ -215,6 +222,7 @@ pub struct RefTable {
|
|||
ble_lld_table: *const BleLldTable,
|
||||
}
|
||||
|
||||
// -------------------- reference table --------------------
|
||||
#[link_section = "TL_REF_TABLE"]
|
||||
pub static mut TL_REF_TABLE: MaybeUninit<RefTable> = MaybeUninit::uninit();
|
||||
|
||||
|
@ -248,38 +256,50 @@ static mut TL_MAC_802_15_4_TABLE: MaybeUninit<Mac802_15_4Table> = MaybeUninit::u
|
|||
#[link_section = "MB_MEM1"]
|
||||
static mut TL_ZIGBEE_TABLE: MaybeUninit<ZigbeeTable> = MaybeUninit::uninit();
|
||||
|
||||
#[allow(dead_code)] // Not used currently but reserved
|
||||
// -------------------- tables --------------------
|
||||
#[link_section = "MB_MEM1"]
|
||||
static mut FREE_BUFF_QUEUE: MaybeUninit<LinkedListNode> = MaybeUninit::uninit();
|
||||
|
||||
// not in shared RAM
|
||||
static mut LOCAL_FREE_BUF_QUEUE: MaybeUninit<LinkedListNode> = MaybeUninit::uninit();
|
||||
|
||||
#[link_section = "MB_MEM2"]
|
||||
static mut CS_BUFFER: MaybeUninit<[u8; TL_PACKET_HEADER_SIZE + TL_EVT_HEADER_SIZE + TL_CS_EVT_SIZE]> =
|
||||
MaybeUninit::uninit();
|
||||
|
||||
#[link_section = "MB_MEM2"]
|
||||
#[link_section = "MB_MEM1"]
|
||||
static mut EVT_QUEUE: MaybeUninit<LinkedListNode> = MaybeUninit::uninit();
|
||||
|
||||
#[link_section = "MB_MEM2"]
|
||||
static mut SYSTEM_EVT_QUEUE: MaybeUninit<LinkedListNode> = MaybeUninit::uninit();
|
||||
|
||||
#[link_section = "MB_MEM2"]
|
||||
static mut SYS_CMD_BUF: MaybeUninit<CmdPacket> = MaybeUninit::uninit();
|
||||
// not in shared RAM
|
||||
static mut LOCAL_FREE_BUF_QUEUE: MaybeUninit<LinkedListNode> = MaybeUninit::uninit();
|
||||
|
||||
// -------------------- app tables --------------------
|
||||
#[link_section = "MB_MEM2"]
|
||||
static mut EVT_POOL: MaybeUninit<[u8; POOL_SIZE]> = MaybeUninit::uninit();
|
||||
|
||||
#[link_section = "MB_MEM2"]
|
||||
static mut SYS_CMD_BUF: MaybeUninit<CmdPacket> = MaybeUninit::uninit();
|
||||
|
||||
#[link_section = "MB_MEM2"]
|
||||
static mut SYS_SPARE_EVT_BUF: MaybeUninit<[u8; TL_PACKET_HEADER_SIZE + TL_EVT_HEADER_SIZE + 255]> =
|
||||
MaybeUninit::uninit();
|
||||
|
||||
#[cfg(feature = "mac-802_15_4")]
|
||||
#[link_section = "MB_MEM2"]
|
||||
static mut MAC_802_15_4_CMD_BUFFER: MaybeUninit<CmdPacket> = MaybeUninit::uninit();
|
||||
|
||||
#[cfg(feature = "mac-802_15_4")]
|
||||
#[link_section = "MB_MEM2"]
|
||||
static mut MAC_802_15_4_NOTIF_RSP_EVT_BUFFER: MaybeUninit<[u8; TL_PACKET_HEADER_SIZE + TL_EVT_HEADER_SIZE + 255]> =
|
||||
MaybeUninit::uninit();
|
||||
|
||||
#[cfg(feature = "ble")]
|
||||
#[link_section = "MB_MEM2"]
|
||||
static mut BLE_SPARE_EVT_BUF: MaybeUninit<[u8; TL_PACKET_HEADER_SIZE + TL_EVT_HEADER_SIZE + 255]> =
|
||||
MaybeUninit::uninit();
|
||||
|
||||
#[link_section = "MB_MEM2"]
|
||||
#[cfg(feature = "ble")]
|
||||
#[link_section = "MB_MEM1"]
|
||||
static mut BLE_CMD_BUFFER: MaybeUninit<CmdPacket> = MaybeUninit::uninit();
|
||||
|
||||
#[link_section = "MB_MEM2"]
|
||||
|
@ -289,10 +309,14 @@ static mut HCI_ACL_DATA_BUFFER: MaybeUninit<[u8; TL_PACKET_HEADER_SIZE + 5 + 251
|
|||
// TODO: get a better size, this is a placeholder
|
||||
pub(crate) static TL_CHANNEL: Channel<CriticalSectionRawMutex, EvtBox, 5> = Channel::new();
|
||||
|
||||
pub struct TlMbox {
|
||||
_sys: Sys,
|
||||
_ble: Ble,
|
||||
_mm: MemoryManager,
|
||||
pub struct TlMbox;
|
||||
|
||||
pub enum MailboxTarget {
|
||||
Sys,
|
||||
#[cfg(feature = "ble")]
|
||||
Ble,
|
||||
#[cfg(feature = "mac-802_15_4")]
|
||||
Mac802_15_4,
|
||||
}
|
||||
|
||||
impl TlMbox {
|
||||
|
@ -338,9 +362,14 @@ impl TlMbox {
|
|||
|
||||
ipcc.init();
|
||||
|
||||
let _sys = Sys::new(ipcc);
|
||||
let _ble = Ble::new(ipcc);
|
||||
let _mm = MemoryManager::new();
|
||||
Sys::init(ipcc);
|
||||
MemoryManager::init();
|
||||
|
||||
#[cfg(feature = "ble")]
|
||||
Ble::init(ipcc);
|
||||
|
||||
#[cfg(feature = "mac-802_15_4")]
|
||||
Mac802_15_4::init(ipcc);
|
||||
|
||||
// rx_irq.disable();
|
||||
// tx_irq.disable();
|
||||
|
@ -360,7 +389,7 @@ impl TlMbox {
|
|||
// rx_irq.enable();
|
||||
// tx_irq.enable();
|
||||
|
||||
TlMbox { _sys, _ble, _mm }
|
||||
Self
|
||||
}
|
||||
|
||||
pub fn wireless_fw_info(&self) -> Option<WirelessFwInfoTable> {
|
||||
|
@ -374,17 +403,30 @@ impl TlMbox {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "ble")]
|
||||
pub fn shci_ble_init(&self, ipcc: &mut Ipcc, param: ShciBleInitCmdParam) {
|
||||
shci_ble_init(ipcc, param);
|
||||
}
|
||||
|
||||
pub fn send_ble_cmd(&self, ipcc: &mut Ipcc, buf: &[u8]) {
|
||||
ble::Ble::send_cmd(ipcc, buf);
|
||||
pub fn send_cmd(&self, ipcc: &mut Ipcc, buf: &[u8], target: MailboxTarget) {
|
||||
match target {
|
||||
MailboxTarget::Sys => Sys::send_cmd(ipcc, buf),
|
||||
#[cfg(feature = "ble")]
|
||||
MailboxTarget::Ble => Ble::send_cmd(ipcc, buf),
|
||||
#[cfg(feature = "mac-802_15_4")]
|
||||
MailboxTarget::Mac802_15_4 => Mac802_15_4::send_cmd(ipcc, buf),
|
||||
}
|
||||
}
|
||||
|
||||
// pub fn send_sys_cmd(&self, ipcc: &mut Ipcc, buf: &[u8]) {
|
||||
// sys::Sys::send_cmd(ipcc, buf);
|
||||
// }
|
||||
pub fn send_ack(&self, ipcc: &mut Ipcc, target: MailboxTarget) {
|
||||
match target {
|
||||
#[cfg(feature = "ble")]
|
||||
MailboxTarget::Ble => Ble::send_acl_data(ipcc),
|
||||
#[cfg(feature = "mac-802_15_4")]
|
||||
MailboxTarget::Mac802_15_4 => Mac802_15_4::send_ack(ipcc),
|
||||
MailboxTarget::Sys => { /* does nothing */ }
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn read(&self) -> EvtBox {
|
||||
TL_CHANNEL.recv().await
|
||||
|
@ -392,10 +434,14 @@ impl TlMbox {
|
|||
|
||||
#[allow(dead_code)]
|
||||
fn interrupt_ipcc_rx_handler(ipcc: &mut Ipcc) {
|
||||
if ipcc.is_rx_pending(channels::cpu2::IPCC_SYSTEM_EVENT_CHANNEL) {
|
||||
sys::Sys::evt_handler(ipcc);
|
||||
} else if ipcc.is_rx_pending(channels::cpu2::IPCC_BLE_EVENT_CHANNEL) {
|
||||
ble::Ble::evt_handler(ipcc);
|
||||
if ipcc.is_rx_pending(channels::Cpu2Channel::SystemEvent.into()) {
|
||||
Sys::evt_handler(ipcc);
|
||||
} else if cfg!(feature = "ble") && ipcc.is_rx_pending(channels::Cpu2Channel::BleEvent.into()) {
|
||||
Ble::evt_handler(ipcc);
|
||||
} else if cfg!(feature = "mac-802_15_4")
|
||||
&& ipcc.is_rx_pending(channels::Cpu2Channel::Mac802_15_4NotifAck.into())
|
||||
{
|
||||
Mac802_15_4::notif_evt_handler(ipcc);
|
||||
} else {
|
||||
todo!()
|
||||
}
|
||||
|
@ -403,11 +449,16 @@ impl TlMbox {
|
|||
|
||||
#[allow(dead_code)]
|
||||
fn interrupt_ipcc_tx_handler(ipcc: &mut Ipcc) {
|
||||
if ipcc.is_tx_pending(channels::cpu1::IPCC_SYSTEM_CMD_RSP_CHANNEL) {
|
||||
if ipcc.is_tx_pending(channels::Cpu1Channel::SystemCmdRsp.into()) {
|
||||
// TODO: handle this case
|
||||
let _ = sys::Sys::cmd_evt_handler(ipcc);
|
||||
} else if ipcc.is_tx_pending(channels::cpu1::IPCC_MM_RELEASE_BUFFER_CHANNEL) {
|
||||
mm::MemoryManager::evt_handler(ipcc);
|
||||
let _ = Sys::cmd_evt_handler(ipcc);
|
||||
} else if ipcc.is_tx_pending(channels::Cpu1Channel::MmReleaseBuffer.into()) {
|
||||
MemoryManager::evt_handler(ipcc);
|
||||
} else if cfg!(feature = "ble") && ipcc.is_tx_pending(channels::Cpu1Channel::HciAclData.into()) {
|
||||
Ble::acl_data_evt_handler(ipcc);
|
||||
} else if cfg!(feature = "mac-802_15_4") && ipcc.is_tx_pending(channels::Cpu1Channel::Mac802_15_4cmdRsp.into())
|
||||
{
|
||||
Mac802_15_4::cmd_evt_handler(ipcc)
|
||||
} else {
|
||||
todo!()
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ pub fn shci_ble_init(ipcc: &mut Ipcc, param: ShciBleInitCmdParam) {
|
|||
|
||||
cmd_buf.cmd_serial.ty = TlPacketType::SysCmd as u8;
|
||||
|
||||
ipcc.c1_set_flag_channel(channels::cpu1::IPCC_SYSTEM_CMD_RSP_CHANNEL);
|
||||
ipcc.c1_set_tx_channel(channels::cpu1::IPCC_SYSTEM_CMD_RSP_CHANNEL, true);
|
||||
ipcc.c1_set_flag_channel(channels::Cpu1Channel::SystemCmdRsp.into());
|
||||
ipcc.c1_set_tx_channel(channels::Cpu1Channel::SystemCmdRsp.into(), true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use crate::ipcc::Ipcc;
|
|||
pub struct Sys;
|
||||
|
||||
impl Sys {
|
||||
pub(crate) fn new(ipcc: &mut Ipcc) -> Self {
|
||||
pub(crate) fn init(ipcc: &mut Ipcc) -> Self {
|
||||
unsafe {
|
||||
LinkedListNode::init_head(SYSTEM_EVT_QUEUE.as_mut_ptr());
|
||||
|
||||
|
@ -22,7 +22,7 @@ impl Sys {
|
|||
});
|
||||
}
|
||||
|
||||
ipcc.c1_set_rx_channel(channels::cpu2::IPCC_SYSTEM_EVENT_CHANNEL, true);
|
||||
ipcc.c1_set_rx_channel(channels::Cpu2Channel::SystemEvent.into(), true);
|
||||
|
||||
Sys
|
||||
}
|
||||
|
@ -43,11 +43,11 @@ impl Sys {
|
|||
}
|
||||
}
|
||||
|
||||
ipcc.c1_clear_flag_channel(channels::cpu2::IPCC_SYSTEM_EVENT_CHANNEL);
|
||||
ipcc.c1_clear_flag_channel(channels::Cpu2Channel::SystemEvent.into());
|
||||
}
|
||||
|
||||
pub(crate) fn cmd_evt_handler(ipcc: &mut Ipcc) -> CcEvt {
|
||||
ipcc.c1_set_tx_channel(channels::cpu1::IPCC_SYSTEM_CMD_RSP_CHANNEL, false);
|
||||
ipcc.c1_set_tx_channel(channels::Cpu1Channel::SystemCmdRsp.into(), false);
|
||||
|
||||
// ST's command response data structure is really convoluted.
|
||||
//
|
||||
|
@ -67,12 +67,10 @@ impl Sys {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn send_cmd(ipcc: &mut Ipcc, buf: &[u8]) {
|
||||
unsafe {
|
||||
// TODO: check this
|
||||
let cmd_buffer = &mut *(*TL_REF_TABLE.assume_init().sys_table).pcmd_buffer;
|
||||
let cmd_serial: *mut CmdSerial = &mut (*cmd_buffer).cmd_serial;
|
||||
let cmd_serial: *mut CmdSerial = &mut cmd_buffer.cmd_serial;
|
||||
let cmd_serial_buf = cmd_serial.cast();
|
||||
|
||||
core::ptr::copy(buf.as_ptr(), cmd_serial_buf, buf.len());
|
||||
|
@ -80,8 +78,8 @@ impl Sys {
|
|||
let cmd_packet = &mut *(*TL_REF_TABLE.assume_init().sys_table).pcmd_buffer;
|
||||
cmd_packet.cmd_serial.ty = TlPacketType::SysCmd as u8;
|
||||
|
||||
ipcc.c1_set_flag_channel(channels::cpu1::IPCC_SYSTEM_CMD_RSP_CHANNEL);
|
||||
ipcc.c1_set_tx_channel(channels::cpu1::IPCC_SYSTEM_CMD_RSP_CHANNEL, true);
|
||||
ipcc.c1_set_flag_channel(channels::Cpu1Channel::SystemCmdRsp.into());
|
||||
ipcc.c1_set_tx_channel(channels::Cpu1Channel::SystemCmdRsp.into(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue