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

64 lines
2.0 KiB
Rust
Raw Normal View History

2023-06-17 19:06:00 +02:00
use crate::cmd::CmdPacket;
2023-06-16 04:02:10 +02:00
use crate::consts::TlPacketType;
2023-06-17 19:06:00 +02:00
use crate::evt::EvtBox;
use crate::shci::{ShciBleInitCmdParam, SCHI_OPCODE_BLE_INIT};
use crate::tables::SysTable;
use crate::unsafe_linked_list::LinkedListNode;
2023-06-17 19:06:00 +02:00
use crate::{channels, Ipcc, SYSTEM_EVT_QUEUE, SYS_CMD_BUF, TL_SYS_TABLE};
pub struct Sys;
impl Sys {
2023-06-17 19:00:33 +02:00
/// TL_Sys_Init
pub fn enable() {
unsafe {
2023-05-20 17:11:29 +02:00
LinkedListNode::init_head(SYSTEM_EVT_QUEUE.as_mut_ptr());
2023-06-14 00:12:34 +02:00
TL_SYS_TABLE.as_mut_ptr().write_volatile(SysTable {
pcmd_buffer: SYS_CMD_BUF.as_mut_ptr(),
sys_queue: SYSTEM_EVT_QUEUE.as_ptr(),
2023-06-17 19:00:33 +02:00
});
}
2023-05-15 11:25:02 +02:00
}
2023-06-17 19:00:33 +02:00
// pub async fn shci_c2_ble_init(&mut self, param: ShciBleInitCmdParam) -> SchiCommandStatus {
// let command_event = self
// .write_and_get_response(TlPacketType::SysCmd, ShciOpcode::BleInit as u16, param.payload())
// .await;
//
// let payload = command_event.payload[0];
// // info!("payload: {:x}", payload);
//
// payload.try_into().unwrap()
// }
pub fn write(opcode: u16, payload: &[u8]) {
2023-05-15 11:25:02 +02:00
unsafe {
2023-06-17 19:00:33 +02:00
CmdPacket::write_into(SYS_CMD_BUF.as_mut_ptr(), TlPacketType::SysCmd, opcode, payload);
2023-05-15 11:25:02 +02:00
}
}
2023-06-08 17:26:47 +02:00
2023-06-17 19:00:33 +02:00
pub async fn shci_c2_ble_init(param: ShciBleInitCmdParam) {
2023-06-16 04:02:10 +02:00
debug!("sending SHCI");
2023-06-17 19:00:33 +02:00
Ipcc::send(channels::cpu1::IPCC_SYSTEM_CMD_RSP_CHANNEL, || {
Self::write(SCHI_OPCODE_BLE_INIT, param.payload());
})
.await;
2023-06-16 04:02:10 +02:00
2023-06-17 19:00:33 +02:00
Ipcc::flush(channels::cpu1::IPCC_SYSTEM_CMD_RSP_CHANNEL).await;
}
2023-06-16 04:02:10 +02:00
2023-06-17 19:00:33 +02:00
/// `HW_IPCC_SYS_EvtNot`
pub async fn read() -> EvtBox {
Ipcc::receive(channels::cpu2::IPCC_SYSTEM_EVENT_CHANNEL, || unsafe {
if let Some(node_ptr) = LinkedListNode::remove_head(SYSTEM_EVT_QUEUE.as_mut_ptr()) {
Some(EvtBox::new(node_ptr.cast()))
} else {
None
}
})
.await
}
2023-06-08 17:26:47 +02:00
}