diff options
| author | xoviat <[email protected]> | 2025-11-23 13:13:11 -0600 |
|---|---|---|
| committer | xoviat <[email protected]> | 2025-11-23 13:13:11 -0600 |
| commit | 849303b82de5e7d28e576f85b65764a84cbc0e1c (patch) | |
| tree | ca485ca52cca0514dc195266a32bbce60e7d7f9e /embassy-stm32-wpan/src | |
| parent | 08125aa919a4dc4de79f91de9a7f3586e51a7739 (diff) | |
| parent | 1573bd6329af67860757f629b22d2c232504b73f (diff) | |
Merge branch 'main' of https://github.com/embassy-rs/embassy into wpan
Diffstat (limited to 'embassy-stm32-wpan/src')
| -rw-r--r-- | embassy-stm32-wpan/src/cmd.rs | 21 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/evt.rs | 1 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/shci.rs | 18 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/sub/sys.rs | 15 |
4 files changed, 36 insertions, 19 deletions
diff --git a/embassy-stm32-wpan/src/cmd.rs b/embassy-stm32-wpan/src/cmd.rs index 5c81a4aa7..787c22c4b 100644 --- a/embassy-stm32-wpan/src/cmd.rs +++ b/embassy-stm32-wpan/src/cmd.rs | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | use core::ptr; | 1 | use core::ptr; |
| 2 | use core::sync::atomic::{Ordering, compiler_fence}; | ||
| 2 | 3 | ||
| 3 | use crate::PacketHeader; | 4 | use crate::PacketHeader; |
| 4 | use crate::consts::TlPacketType; | 5 | use crate::consts::TlPacketType; |
| @@ -45,11 +46,11 @@ pub struct CmdPacket { | |||
| 45 | 46 | ||
| 46 | impl CmdPacket { | 47 | impl CmdPacket { |
| 47 | pub unsafe fn write_into(cmd_buf: *mut CmdPacket, packet_type: TlPacketType, cmd_code: u16, payload: &[u8]) { | 48 | pub unsafe fn write_into(cmd_buf: *mut CmdPacket, packet_type: TlPacketType, cmd_code: u16, payload: &[u8]) { |
| 48 | let p_cmd_serial = &mut (*cmd_buf).cmdserial as *mut _ as *mut CmdSerialStub; | 49 | let p_cmd_serial = (cmd_buf as *mut u8).add(size_of::<PacketHeader>()); |
| 49 | let p_payload = &mut (*cmd_buf).cmdserial.cmd.payload as *mut _; | 50 | let p_payload = p_cmd_serial.add(size_of::<CmdSerialStub>()); |
| 50 | 51 | ||
| 51 | ptr::write_volatile( | 52 | ptr::write_unaligned( |
| 52 | p_cmd_serial, | 53 | p_cmd_serial as *mut _, |
| 53 | CmdSerialStub { | 54 | CmdSerialStub { |
| 54 | ty: packet_type as u8, | 55 | ty: packet_type as u8, |
| 55 | cmd_code, | 56 | cmd_code, |
| @@ -58,6 +59,8 @@ impl CmdPacket { | |||
| 58 | ); | 59 | ); |
| 59 | 60 | ||
| 60 | ptr::copy_nonoverlapping(payload as *const _ as *const u8, p_payload, payload.len()); | 61 | ptr::copy_nonoverlapping(payload as *const _ as *const u8, p_payload, payload.len()); |
| 62 | |||
| 63 | compiler_fence(Ordering::Release); | ||
| 61 | } | 64 | } |
| 62 | } | 65 | } |
| 63 | 66 | ||
| @@ -87,11 +90,11 @@ pub struct AclDataPacket { | |||
| 87 | 90 | ||
| 88 | impl AclDataPacket { | 91 | impl AclDataPacket { |
| 89 | pub unsafe fn write_into(cmd_buf: *mut AclDataPacket, packet_type: TlPacketType, handle: u16, payload: &[u8]) { | 92 | pub unsafe fn write_into(cmd_buf: *mut AclDataPacket, packet_type: TlPacketType, handle: u16, payload: &[u8]) { |
| 90 | let p_cmd_serial = &mut (*cmd_buf).acl_data_serial as *mut _ as *mut AclDataSerialStub; | 93 | let p_cmd_serial = (cmd_buf as *mut u8).add(size_of::<PacketHeader>()); |
| 91 | let p_payload = &mut (*cmd_buf).acl_data_serial.acl_data as *mut _; | 94 | let p_payload = p_cmd_serial.add(size_of::<AclDataSerialStub>()); |
| 92 | 95 | ||
| 93 | ptr::write_volatile( | 96 | ptr::write_unaligned( |
| 94 | p_cmd_serial, | 97 | p_cmd_serial as *mut _, |
| 95 | AclDataSerialStub { | 98 | AclDataSerialStub { |
| 96 | ty: packet_type as u8, | 99 | ty: packet_type as u8, |
| 97 | handle: handle, | 100 | handle: handle, |
| @@ -100,5 +103,7 @@ impl AclDataPacket { | |||
| 100 | ); | 103 | ); |
| 101 | 104 | ||
| 102 | ptr::copy_nonoverlapping(payload as *const _ as *const u8, p_payload, payload.len()); | 105 | ptr::copy_nonoverlapping(payload as *const _ as *const u8, p_payload, payload.len()); |
| 106 | |||
| 107 | compiler_fence(Ordering::Release); | ||
| 103 | } | 108 | } |
| 104 | } | 109 | } |
diff --git a/embassy-stm32-wpan/src/evt.rs b/embassy-stm32-wpan/src/evt.rs index c6528413d..f32821269 100644 --- a/embassy-stm32-wpan/src/evt.rs +++ b/embassy-stm32-wpan/src/evt.rs | |||
| @@ -67,6 +67,7 @@ pub struct EvtSerial { | |||
| 67 | pub struct EvtStub { | 67 | pub struct EvtStub { |
| 68 | pub kind: u8, | 68 | pub kind: u8, |
| 69 | pub evt_code: u8, | 69 | pub evt_code: u8, |
| 70 | pub payload_len: u8, | ||
| 70 | } | 71 | } |
| 71 | 72 | ||
| 72 | /// This format shall be used for all events (asynchronous and command response) reported | 73 | /// This format shall be used for all events (asynchronous and command response) reported |
diff --git a/embassy-stm32-wpan/src/shci.rs b/embassy-stm32-wpan/src/shci.rs index 1946c55fd..2d94a9cda 100644 --- a/embassy-stm32-wpan/src/shci.rs +++ b/embassy-stm32-wpan/src/shci.rs | |||
| @@ -1,6 +1,10 @@ | |||
| 1 | use core::{mem, slice}; | 1 | use core::sync::atomic::{Ordering, compiler_fence}; |
| 2 | use core::{mem, ptr, slice}; | ||
| 2 | 3 | ||
| 4 | use crate::PacketHeader; | ||
| 5 | use crate::cmd::CmdPacket; | ||
| 3 | use crate::consts::{TL_CS_EVT_SIZE, TL_EVT_HEADER_SIZE, TL_PACKET_HEADER_SIZE}; | 6 | use crate::consts::{TL_CS_EVT_SIZE, TL_EVT_HEADER_SIZE, TL_PACKET_HEADER_SIZE}; |
| 7 | use crate::evt::{CcEvt, EvtStub}; | ||
| 4 | 8 | ||
| 5 | const SHCI_OGF: u16 = 0x3F; | 9 | const SHCI_OGF: u16 = 0x3F; |
| 6 | 10 | ||
| @@ -21,6 +25,18 @@ pub enum SchiCommandStatus { | |||
| 21 | ShciFusCmdNotSupported = 0xFF, | 25 | ShciFusCmdNotSupported = 0xFF, |
| 22 | } | 26 | } |
| 23 | 27 | ||
| 28 | impl SchiCommandStatus { | ||
| 29 | pub unsafe fn from_packet(cmd_buf: *const CmdPacket) -> Result<Self, ()> { | ||
| 30 | let p_cmd_serial = (cmd_buf as *mut u8).add(size_of::<PacketHeader>()); | ||
| 31 | let p_evt_payload = p_cmd_serial.add(size_of::<EvtStub>()); | ||
| 32 | |||
| 33 | compiler_fence(Ordering::Acquire); | ||
| 34 | let cc_evt = ptr::read_unaligned(p_evt_payload as *const CcEvt); | ||
| 35 | |||
| 36 | cc_evt.payload[0].try_into() | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 24 | impl TryFrom<u8> for SchiCommandStatus { | 40 | impl TryFrom<u8> for SchiCommandStatus { |
| 25 | type Error = (); | 41 | type Error = (); |
| 26 | 42 | ||
diff --git a/embassy-stm32-wpan/src/sub/sys.rs b/embassy-stm32-wpan/src/sub/sys.rs index dffe9942c..718ccae8b 100644 --- a/embassy-stm32-wpan/src/sub/sys.rs +++ b/embassy-stm32-wpan/src/sub/sys.rs | |||
| @@ -4,9 +4,10 @@ use embassy_stm32::ipcc::{IpccRxChannel, IpccTxChannel}; | |||
| 4 | 4 | ||
| 5 | use crate::cmd::CmdPacket; | 5 | use crate::cmd::CmdPacket; |
| 6 | use crate::consts::TlPacketType; | 6 | use crate::consts::TlPacketType; |
| 7 | use crate::evt::{CcEvt, EvtBox, EvtPacket}; | 7 | use crate::evt::EvtBox; |
| 8 | #[allow(unused_imports)] | 8 | #[cfg(feature = "ble")] |
| 9 | use crate::shci::{SchiCommandStatus, ShciBleInitCmdParam, ShciOpcode}; | 9 | use crate::shci::ShciBleInitCmdParam; |
| 10 | use crate::shci::{SchiCommandStatus, ShciOpcode}; | ||
| 10 | use crate::sub::mm; | 11 | use crate::sub::mm; |
| 11 | use crate::tables::{SysTable, WirelessFwInfoTable}; | 12 | use crate::tables::{SysTable, WirelessFwInfoTable}; |
| 12 | use crate::unsafe_linked_list::LinkedListNode; | 13 | use crate::unsafe_linked_list::LinkedListNode; |
| @@ -64,13 +65,7 @@ impl<'a> Sys<'a> { | |||
| 64 | self.write(opcode, payload).await; | 65 | self.write(opcode, payload).await; |
| 65 | self.ipcc_system_cmd_rsp_channel.flush().await; | 66 | self.ipcc_system_cmd_rsp_channel.flush().await; |
| 66 | 67 | ||
| 67 | unsafe { | 68 | unsafe { SchiCommandStatus::from_packet(SYS_CMD_BUF.as_ptr()) } |
| 68 | let p_event_packet = SYS_CMD_BUF.as_ptr() as *const EvtPacket; | ||
| 69 | let p_command_event = &((*p_event_packet).evt_serial.evt.payload) as *const _ as *const CcEvt; | ||
| 70 | let p_payload = &((*p_command_event).payload) as *const u8; | ||
| 71 | |||
| 72 | ptr::read_volatile(p_payload).try_into() | ||
| 73 | } | ||
| 74 | } | 69 | } |
| 75 | 70 | ||
| 76 | #[cfg(feature = "mac")] | 71 | #[cfg(feature = "mac")] |
