diff options
| -rw-r--r-- | embassy-stm32-wpan/src/ble.rs | 4 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/cmd.rs | 8 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/rc.rs | 7 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/shci.rs | 39 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/sys.rs | 33 | ||||
| -rw-r--r-- | tests/stm32/src/bin/tl_mbox.rs | 3 |
6 files changed, 56 insertions, 38 deletions
diff --git a/embassy-stm32-wpan/src/ble.rs b/embassy-stm32-wpan/src/ble.rs index 57348a925..46a2f41c4 100644 --- a/embassy-stm32-wpan/src/ble.rs +++ b/embassy-stm32-wpan/src/ble.rs | |||
| @@ -48,11 +48,11 @@ impl Ble { | |||
| 48 | // TODO: ACL data ack to the user | 48 | // TODO: ACL data ack to the user |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | pub fn ble_send_cmd(buf: &[u8]) { | 51 | pub fn send_cmd(buf: &[u8]) { |
| 52 | debug!("writing ble cmd"); | 52 | debug!("writing ble cmd"); |
| 53 | 53 | ||
| 54 | unsafe { | 54 | unsafe { |
| 55 | let pcmd_buffer: *mut CmdPacket = (*TL_REF_TABLE.assume_init().ble_table).pcmd_buffer; | 55 | let pcmd_buffer: *mut CmdPacket = BLE_CMD_BUFFER.as_mut_ptr(); |
| 56 | let pcmd_serial: *mut CmdSerial = &mut (*pcmd_buffer).cmdserial; | 56 | let pcmd_serial: *mut CmdSerial = &mut (*pcmd_buffer).cmdserial; |
| 57 | let pcmd_serial_buf: *mut u8 = pcmd_serial.cast(); | 57 | let pcmd_serial_buf: *mut u8 = pcmd_serial.cast(); |
| 58 | 58 | ||
diff --git a/embassy-stm32-wpan/src/cmd.rs b/embassy-stm32-wpan/src/cmd.rs index 1f7dae7f7..a023201ba 100644 --- a/embassy-stm32-wpan/src/cmd.rs +++ b/embassy-stm32-wpan/src/cmd.rs | |||
| @@ -28,6 +28,14 @@ pub struct CmdSerial { | |||
| 28 | 28 | ||
| 29 | #[derive(Copy, Clone, Default)] | 29 | #[derive(Copy, Clone, Default)] |
| 30 | #[repr(C, packed)] | 30 | #[repr(C, packed)] |
| 31 | pub struct CmdSerialStub { | ||
| 32 | pub ty: u8, | ||
| 33 | pub cmd_code: u16, | ||
| 34 | pub payload_len: u8, | ||
| 35 | } | ||
| 36 | |||
| 37 | #[derive(Copy, Clone, Default)] | ||
| 38 | #[repr(C, packed)] | ||
| 31 | pub struct CmdPacket { | 39 | pub struct CmdPacket { |
| 32 | pub header: PacketHeader, | 40 | pub header: PacketHeader, |
| 33 | pub cmdserial: CmdSerial, | 41 | pub cmdserial: CmdSerial, |
diff --git a/embassy-stm32-wpan/src/rc.rs b/embassy-stm32-wpan/src/rc.rs index aae2265ed..a217aa224 100644 --- a/embassy-stm32-wpan/src/rc.rs +++ b/embassy-stm32-wpan/src/rc.rs | |||
| @@ -20,7 +20,7 @@ impl<'d> RadioCoprocessor<'d> { | |||
| 20 | let cmd = TlPacketType::try_from(cmd_code).unwrap(); | 20 | let cmd = TlPacketType::try_from(cmd_code).unwrap(); |
| 21 | 21 | ||
| 22 | match &cmd { | 22 | match &cmd { |
| 23 | TlPacketType::BleCmd => Ble::ble_send_cmd(buf), | 23 | TlPacketType::BleCmd => Ble::send_cmd(buf), |
| 24 | _ => todo!(), | 24 | _ => todo!(), |
| 25 | } | 25 | } |
| 26 | } | 26 | } |
| @@ -33,11 +33,6 @@ impl<'d> RadioCoprocessor<'d> { | |||
| 33 | let event = evt.evt(); | 33 | let event = evt.evt(); |
| 34 | 34 | ||
| 35 | evt.write(&mut self.rx_buf).unwrap(); | 35 | evt.write(&mut self.rx_buf).unwrap(); |
| 36 | |||
| 37 | if event.kind() == 18 { | ||
| 38 | shci::shci_ble_init(Default::default()); | ||
| 39 | self.rx_buf[0] = 0x04; | ||
| 40 | } | ||
| 41 | } | 36 | } |
| 42 | 37 | ||
| 43 | if self.mbox.pop_last_cc_evt().is_some() { | 38 | if self.mbox.pop_last_cc_evt().is_some() { |
diff --git a/embassy-stm32-wpan/src/shci.rs b/embassy-stm32-wpan/src/shci.rs index 8537995ff..6e58a7156 100644 --- a/embassy-stm32-wpan/src/shci.rs +++ b/embassy-stm32-wpan/src/shci.rs | |||
| @@ -1,8 +1,10 @@ | |||
| 1 | use core::{mem, slice}; | ||
| 2 | |||
| 1 | use super::cmd::CmdPacket; | 3 | use super::cmd::CmdPacket; |
| 2 | use super::consts::TlPacketType; | 4 | use super::consts::TlPacketType; |
| 3 | use super::{sys, TL_CS_EVT_SIZE, TL_EVT_HEADER_SIZE, TL_PACKET_HEADER_SIZE, TL_SYS_TABLE}; | 5 | use super::{sys, TL_CS_EVT_SIZE, TL_EVT_HEADER_SIZE, TL_PACKET_HEADER_SIZE, TL_SYS_TABLE}; |
| 4 | 6 | ||
| 5 | const SCHI_OPCODE_BLE_INIT: u16 = 0xfc66; | 7 | pub const SCHI_OPCODE_BLE_INIT: u16 = 0xfc66; |
| 6 | 8 | ||
| 7 | #[derive(Debug, Clone, Copy)] | 9 | #[derive(Debug, Clone, Copy)] |
| 8 | #[repr(C, packed)] | 10 | #[repr(C, packed)] |
| @@ -32,6 +34,12 @@ pub struct ShciBleInitCmdParam { | |||
| 32 | pub hw_version: u8, | 34 | pub hw_version: u8, |
| 33 | } | 35 | } |
| 34 | 36 | ||
| 37 | impl ShciBleInitCmdParam { | ||
| 38 | pub fn payload<'a>(&self) -> &'a [u8] { | ||
| 39 | unsafe { slice::from_raw_parts(self as *const _ as *const u8, mem::size_of::<Self>()) } | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 35 | impl Default for ShciBleInitCmdParam { | 43 | impl Default for ShciBleInitCmdParam { |
| 36 | fn default() -> Self { | 44 | fn default() -> Self { |
| 37 | Self { | 45 | Self { |
| @@ -66,35 +74,10 @@ pub struct ShciHeader { | |||
| 66 | #[derive(Debug, Clone, Copy)] | 74 | #[derive(Debug, Clone, Copy)] |
| 67 | #[repr(C, packed)] | 75 | #[repr(C, packed)] |
| 68 | pub struct ShciBleInitCmdPacket { | 76 | pub struct ShciBleInitCmdPacket { |
| 69 | header: ShciHeader, | 77 | pub header: ShciHeader, |
| 70 | param: ShciBleInitCmdParam, | 78 | pub param: ShciBleInitCmdParam, |
| 71 | } | 79 | } |
| 72 | 80 | ||
| 73 | pub const TL_BLE_EVT_CS_PACKET_SIZE: usize = TL_EVT_HEADER_SIZE + TL_CS_EVT_SIZE; | 81 | pub const TL_BLE_EVT_CS_PACKET_SIZE: usize = TL_EVT_HEADER_SIZE + TL_CS_EVT_SIZE; |
| 74 | #[allow(dead_code)] // Not used currently but reserved | 82 | #[allow(dead_code)] // Not used currently but reserved |
| 75 | const TL_BLE_EVT_CS_BUFFER_SIZE: usize = TL_PACKET_HEADER_SIZE + TL_BLE_EVT_CS_PACKET_SIZE; | 83 | const TL_BLE_EVT_CS_BUFFER_SIZE: usize = TL_PACKET_HEADER_SIZE + TL_BLE_EVT_CS_PACKET_SIZE; |
| 76 | |||
| 77 | pub fn shci_ble_init(param: ShciBleInitCmdParam) { | ||
| 78 | debug!("sending SHCI"); | ||
| 79 | |||
| 80 | let mut packet = ShciBleInitCmdPacket { | ||
| 81 | header: ShciHeader::default(), | ||
| 82 | param, | ||
| 83 | }; | ||
| 84 | |||
| 85 | let packet_ptr: *mut _ = &mut packet; | ||
| 86 | |||
| 87 | unsafe { | ||
| 88 | let cmd_ptr: *mut CmdPacket = packet_ptr.cast(); | ||
| 89 | |||
| 90 | (*cmd_ptr).cmdserial.cmd.cmd_code = SCHI_OPCODE_BLE_INIT; | ||
| 91 | (*cmd_ptr).cmdserial.cmd.payload_len = core::mem::size_of::<ShciBleInitCmdParam>() as u8; | ||
| 92 | |||
| 93 | let p_cmd_buffer = &mut *(*TL_SYS_TABLE.as_mut_ptr()).pcmd_buffer; | ||
| 94 | core::ptr::write(p_cmd_buffer, *cmd_ptr); | ||
| 95 | |||
| 96 | p_cmd_buffer.cmdserial.ty = TlPacketType::SysCmd as u8; | ||
| 97 | |||
| 98 | sys::Sys::send_cmd(); | ||
| 99 | } | ||
| 100 | } | ||
diff --git a/embassy-stm32-wpan/src/sys.rs b/embassy-stm32-wpan/src/sys.rs index 0cff5c746..76f65cbd8 100644 --- a/embassy-stm32-wpan/src/sys.rs +++ b/embassy-stm32-wpan/src/sys.rs | |||
| @@ -1,7 +1,12 @@ | |||
| 1 | use core::ptr; | ||
| 2 | use core::sync::atomic::{compiler_fence, Ordering}; | ||
| 3 | |||
| 1 | use embassy_stm32::ipcc::Ipcc; | 4 | use embassy_stm32::ipcc::Ipcc; |
| 2 | 5 | ||
| 3 | use crate::cmd::{CmdPacket, CmdSerial}; | 6 | use crate::cmd::{CmdPacket, CmdSerial, CmdSerialStub}; |
| 7 | use crate::consts::TlPacketType; | ||
| 4 | use crate::evt::{CcEvt, EvtBox, EvtSerial}; | 8 | use crate::evt::{CcEvt, EvtBox, EvtSerial}; |
| 9 | use crate::shci::{ShciBleInitCmdParam, SCHI_OPCODE_BLE_INIT}; | ||
| 5 | use crate::tables::SysTable; | 10 | use crate::tables::SysTable; |
| 6 | use crate::unsafe_linked_list::LinkedListNode; | 11 | use crate::unsafe_linked_list::LinkedListNode; |
| 7 | use crate::{channels, EVT_CHANNEL, SYSTEM_EVT_QUEUE, SYS_CMD_BUF, TL_SYS_TABLE}; | 12 | use crate::{channels, EVT_CHANNEL, SYSTEM_EVT_QUEUE, SYS_CMD_BUF, TL_SYS_TABLE}; |
| @@ -58,7 +63,31 @@ impl Sys { | |||
| 58 | Ipcc::c1_clear_flag_channel(channels::cpu2::IPCC_SYSTEM_EVENT_CHANNEL); | 63 | Ipcc::c1_clear_flag_channel(channels::cpu2::IPCC_SYSTEM_EVENT_CHANNEL); |
| 59 | } | 64 | } |
| 60 | 65 | ||
| 61 | pub fn send_cmd() { | 66 | pub fn shci_ble_init(param: ShciBleInitCmdParam) { |
| 67 | debug!("sending SHCI"); | ||
| 68 | |||
| 69 | Self::send_cmd(SCHI_OPCODE_BLE_INIT, param.payload()); | ||
| 70 | } | ||
| 71 | |||
| 72 | pub fn send_cmd(opcode: u16, payload: &[u8]) { | ||
| 73 | unsafe { | ||
| 74 | let p_cmd_serial = &mut (*SYS_CMD_BUF.as_mut_ptr()).cmdserial as *mut _ as *mut CmdSerialStub; | ||
| 75 | let p_payload = &mut (*SYS_CMD_BUF.as_mut_ptr()).cmdserial.cmd.payload as *mut _; | ||
| 76 | |||
| 77 | ptr::write_volatile( | ||
| 78 | p_cmd_serial, | ||
| 79 | CmdSerialStub { | ||
| 80 | ty: TlPacketType::SysCmd as u8, | ||
| 81 | cmd_code: opcode, | ||
| 82 | payload_len: payload.len() as u8, | ||
| 83 | }, | ||
| 84 | ); | ||
| 85 | |||
| 86 | ptr::copy_nonoverlapping(payload as *const _ as *const u8, p_payload, payload.len()); | ||
| 87 | } | ||
| 88 | |||
| 89 | compiler_fence(Ordering::SeqCst); | ||
| 90 | |||
| 62 | Ipcc::c1_set_flag_channel(channels::cpu1::IPCC_SYSTEM_CMD_RSP_CHANNEL); | 91 | Ipcc::c1_set_flag_channel(channels::cpu1::IPCC_SYSTEM_CMD_RSP_CHANNEL); |
| 63 | Ipcc::c1_set_tx_channel(channels::cpu1::IPCC_SYSTEM_CMD_RSP_CHANNEL, true); | 92 | Ipcc::c1_set_tx_channel(channels::cpu1::IPCC_SYSTEM_CMD_RSP_CHANNEL, true); |
| 64 | } | 93 | } |
diff --git a/tests/stm32/src/bin/tl_mbox.rs b/tests/stm32/src/bin/tl_mbox.rs index 4669cbc62..5e7d11ef5 100644 --- a/tests/stm32/src/bin/tl_mbox.rs +++ b/tests/stm32/src/bin/tl_mbox.rs | |||
| @@ -11,6 +11,7 @@ use embassy_executor::Spawner; | |||
| 11 | use embassy_stm32::bind_interrupts; | 11 | use embassy_stm32::bind_interrupts; |
| 12 | use embassy_stm32::ipcc::Config; | 12 | use embassy_stm32::ipcc::Config; |
| 13 | use embassy_stm32_wpan::rc::RadioCoprocessor; | 13 | use embassy_stm32_wpan::rc::RadioCoprocessor; |
| 14 | use embassy_stm32_wpan::sys::Sys; | ||
| 14 | use embassy_stm32_wpan::TlMbox; | 15 | use embassy_stm32_wpan::TlMbox; |
| 15 | use embassy_time::{Duration, Timer}; | 16 | use embassy_time::{Duration, Timer}; |
| 16 | 17 | ||
| @@ -56,6 +57,8 @@ async fn main(_spawner: Spawner) { | |||
| 56 | let response = rc.read().await; | 57 | let response = rc.read().await; |
| 57 | info!("coprocessor ready {}", response); | 58 | info!("coprocessor ready {}", response); |
| 58 | 59 | ||
| 60 | Sys::shci_ble_init(Default::default()); | ||
| 61 | |||
| 59 | rc.write(&[0x01, 0x03, 0x0c, 0x00, 0x00]); | 62 | rc.write(&[0x01, 0x03, 0x0c, 0x00, 0x00]); |
| 60 | let response = rc.read().await; | 63 | let response = rc.read().await; |
| 61 | info!("ble reset rsp {}", response); | 64 | info!("ble reset rsp {}", response); |
