aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32-wpan/src/wb55/shci.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-stm32-wpan/src/wb55/shci.rs')
-rw-r--r--embassy-stm32-wpan/src/wb55/shci.rs122
1 files changed, 96 insertions, 26 deletions
diff --git a/embassy-stm32-wpan/src/wb55/shci.rs b/embassy-stm32-wpan/src/wb55/shci.rs
index 3faa79209..3eb9525d3 100644
--- a/embassy-stm32-wpan/src/wb55/shci.rs
+++ b/embassy-stm32-wpan/src/wb55/shci.rs
@@ -12,6 +12,28 @@ const fn opcode(ogf: u16, ocf: u16) -> isize {
12 ((ogf << 10) + ocf) as isize 12 ((ogf << 10) + ocf) as isize
13} 13}
14 14
15pub(crate) trait SealedSchiFromPacket: Sized {
16 unsafe fn from_packet(cmd_buf: *const CmdPacket) -> Result<Self, ()>;
17}
18
19#[allow(private_bounds)]
20pub trait SchiFromPacket: SealedSchiFromPacket {}
21impl<T: SealedSchiFromPacket> SchiFromPacket for T {}
22
23trait ShciFromEventSerial: TryFrom<u8, Error = ()> {}
24
25impl<T: ShciFromEventSerial> SealedSchiFromPacket for T {
26 unsafe fn from_packet(cmd_buf: *const CmdPacket) -> Result<Self, ()> {
27 let p_cmd_serial = (cmd_buf as *mut u8).add(size_of::<PacketHeader>());
28 let p_evt_payload = p_cmd_serial.add(size_of::<EvtStub>());
29
30 compiler_fence(Ordering::Acquire);
31 let cc_evt = ptr::read_unaligned(p_evt_payload as *const CcEvt);
32
33 cc_evt.payload[0].try_into()
34 }
35}
36
15#[allow(dead_code)] 37#[allow(dead_code)]
16#[cfg_attr(feature = "defmt", derive(defmt::Format))] 38#[cfg_attr(feature = "defmt", derive(defmt::Format))]
17pub enum SchiCommandStatus { 39pub enum SchiCommandStatus {
@@ -25,37 +47,20 @@ pub enum SchiCommandStatus {
25 ShciFusCmdNotSupported = 0xFF, 47 ShciFusCmdNotSupported = 0xFF,
26} 48}
27 49
28impl SchiCommandStatus { 50impl ShciFromEventSerial for 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
40impl TryFrom<u8> for SchiCommandStatus { 51impl TryFrom<u8> for SchiCommandStatus {
41 type Error = (); 52 type Error = ();
42 53
43 fn try_from(v: u8) -> Result<Self, Self::Error> { 54 fn try_from(v: u8) -> Result<Self, Self::Error> {
44 match v { 55 match v {
45 x if x == SchiCommandStatus::ShciSuccess as u8 => Ok(SchiCommandStatus::ShciSuccess), 56 0x00 => Ok(Self::ShciSuccess),
46 x if x == SchiCommandStatus::ShciUnknownCmd as u8 => Ok(SchiCommandStatus::ShciUnknownCmd), 57 0x01 => Ok(Self::ShciUnknownCmd),
47 x if x == SchiCommandStatus::ShciMemoryCapacityExceededErrCode as u8 => { 58 0x07 => Ok(Self::ShciMemoryCapacityExceededErrCode),
48 Ok(SchiCommandStatus::ShciMemoryCapacityExceededErrCode) 59 0x11 => Ok(Self::ShciErrUnsupportedFeature),
49 } 60 0x12 => Ok(Self::ShciErrInvalidHciCmdParams),
50 x if x == SchiCommandStatus::ShciErrUnsupportedFeature as u8 => { 61 0x42 => Ok(Self::ShciErrInvalidParams), /* only used for release < v1.13.0 */
51 Ok(SchiCommandStatus::ShciErrUnsupportedFeature) 62 0x92 => Ok(Self::ShciErrInvalidParamsV2), /* available for release >= v1.13.0 */
52 } 63 0xFF => Ok(Self::ShciFusCmdNotSupported),
53 x if x == SchiCommandStatus::ShciErrInvalidHciCmdParams as u8 => {
54 Ok(SchiCommandStatus::ShciErrInvalidHciCmdParams)
55 }
56 x if x == SchiCommandStatus::ShciErrInvalidParams as u8 => Ok(SchiCommandStatus::ShciErrInvalidParams), /* only used for release < v1.13.0 */
57 x if x == SchiCommandStatus::ShciErrInvalidParamsV2 as u8 => Ok(SchiCommandStatus::ShciErrInvalidParamsV2), /* available for release >= v1.13.0 */
58 x if x == SchiCommandStatus::ShciFusCmdNotSupported as u8 => Ok(SchiCommandStatus::ShciFusCmdNotSupported),
59 _ => Err(()), 64 _ => Err(()),
60 } 65 }
61 } 66 }
@@ -107,6 +112,71 @@ pub enum ShciOpcode {
107 Mac802_15_4DeInit = opcode(SHCI_OGF, 0x78), 112 Mac802_15_4DeInit = opcode(SHCI_OGF, 0x78),
108} 113}
109 114
115#[cfg_attr(feature = "defmt", derive(defmt::Format))]
116pub enum ShciFusGetStateErrorCode {
117 FusStateErrorNoError = 0x00,
118 FusStateErrorImgNotFound = 0x01,
119 FusStateErrorImgCorrupt = 0x02,
120 FusStateErrorImgNotAuthentic = 0x03,
121 FusStateErrorImgNotEnoughSpace = 0x04,
122 FusStateErrorImageUsrAbort = 0x05,
123 FusStateErrorImageErsError = 0x06,
124 FusStateErrorImageWrtError = 0x07,
125 FusStateErrorAuthTagStNotFound = 0x08,
126 FusStateErrorAuthTagCustNotFound = 0x09,
127 FusStateErrorAuthKeyLocked = 0x0A,
128 FusStateErrorFwRollbackError = 0x11,
129 FusStateErrorStateNotRunning = 0xFE,
130 FusStateErrorErrUnknown = 0xFF,
131}
132
133impl ShciFromEventSerial for ShciFusGetStateErrorCode {}
134impl TryFrom<u8> for ShciFusGetStateErrorCode {
135 type Error = ();
136
137 fn try_from(v: u8) -> Result<Self, Self::Error> {
138 match v {
139 0x00 => Ok(Self::FusStateErrorNoError),
140 0x01 => Ok(Self::FusStateErrorImgNotFound),
141 0x02 => Ok(Self::FusStateErrorImgCorrupt),
142 0x03 => Ok(Self::FusStateErrorImgNotAuthentic),
143 0x04 => Ok(Self::FusStateErrorImgNotEnoughSpace),
144 0x05 => Ok(Self::FusStateErrorImageUsrAbort),
145 0x06 => Ok(Self::FusStateErrorImageErsError),
146 0x07 => Ok(Self::FusStateErrorImageWrtError),
147 0x08 => Ok(Self::FusStateErrorAuthTagStNotFound),
148 0x09 => Ok(Self::FusStateErrorAuthTagCustNotFound),
149 0x0A => Ok(Self::FusStateErrorAuthKeyLocked),
150 0x11 => Ok(Self::FusStateErrorFwRollbackError),
151 0xFE => Ok(Self::FusStateErrorStateNotRunning),
152 0xFF => Ok(Self::FusStateErrorErrUnknown),
153 _ => Err(()),
154 }
155 }
156}
157
158#[cfg_attr(feature = "defmt", derive(defmt::Format))]
159pub enum SchiSysEventReady {
160 WirelessFwRunning = 0x00,
161 FusFwRunning = 0x01,
162 NvmBackupRunning = 0x10,
163 NvmRestoreRunning = 0x11,
164}
165
166impl TryFrom<u8> for SchiSysEventReady {
167 type Error = ();
168
169 fn try_from(v: u8) -> Result<Self, Self::Error> {
170 match v {
171 0x00 => Ok(Self::WirelessFwRunning),
172 0x01 => Ok(Self::FusFwRunning),
173 0x10 => Ok(Self::NvmBackupRunning),
174 0x11 => Ok(Self::NvmRestoreRunning),
175 _ => Err(()),
176 }
177 }
178}
179
110pub const SHCI_C2_CONFIG_EVTMASK1_BIT0_ERROR_NOTIF_ENABLE: u8 = 1 << 0; 180pub const SHCI_C2_CONFIG_EVTMASK1_BIT0_ERROR_NOTIF_ENABLE: u8 = 1 << 0;
111pub const SHCI_C2_CONFIG_EVTMASK1_BIT1_BLE_NVM_RAM_UPDATE_ENABLE: u8 = 1 << 1; 181pub const SHCI_C2_CONFIG_EVTMASK1_BIT1_BLE_NVM_RAM_UPDATE_ENABLE: u8 = 1 << 1;
112pub const SHCI_C2_CONFIG_EVTMASK1_BIT2_THREAD_NVM_RAM_UPDATE_ENABLE: u8 = 1 << 2; 182pub const SHCI_C2_CONFIG_EVTMASK1_BIT2_THREAD_NVM_RAM_UPDATE_ENABLE: u8 = 1 << 2;