diff options
Diffstat (limited to 'embassy-stm32-wpan/src/wb55/consts.rs')
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/consts.rs | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/embassy-stm32-wpan/src/wb55/consts.rs b/embassy-stm32-wpan/src/wb55/consts.rs new file mode 100644 index 000000000..659e74e69 --- /dev/null +++ b/embassy-stm32-wpan/src/wb55/consts.rs | |||
| @@ -0,0 +1,94 @@ | |||
| 1 | use crate::evt::CsEvt; | ||
| 2 | use crate::wb55::PacketHeader; | ||
| 3 | |||
| 4 | #[derive(Debug)] | ||
| 5 | #[repr(C)] | ||
| 6 | pub enum TlPacketType { | ||
| 7 | MacCmd = 0x00, | ||
| 8 | |||
| 9 | BleCmd = 0x01, | ||
| 10 | AclData = 0x02, | ||
| 11 | BleEvt = 0x04, | ||
| 12 | |||
| 13 | OtCmd = 0x08, | ||
| 14 | OtRsp = 0x09, | ||
| 15 | CliCmd = 0x0A, | ||
| 16 | OtNot = 0x0C, | ||
| 17 | OtAck = 0x0D, | ||
| 18 | CliNot = 0x0E, | ||
| 19 | CliAck = 0x0F, | ||
| 20 | |||
| 21 | SysCmd = 0x10, | ||
| 22 | SysRsp = 0x11, | ||
| 23 | SysEvt = 0x12, | ||
| 24 | |||
| 25 | LocCmd = 0x20, | ||
| 26 | LocRsp = 0x21, | ||
| 27 | |||
| 28 | TracesApp = 0x40, | ||
| 29 | TracesWl = 0x41, | ||
| 30 | } | ||
| 31 | |||
| 32 | impl TryFrom<u8> for TlPacketType { | ||
| 33 | type Error = (); | ||
| 34 | |||
| 35 | fn try_from(value: u8) -> Result<Self, Self::Error> { | ||
| 36 | match value { | ||
| 37 | 0x01 => Ok(TlPacketType::BleCmd), | ||
| 38 | 0x02 => Ok(TlPacketType::AclData), | ||
| 39 | 0x04 => Ok(TlPacketType::BleEvt), | ||
| 40 | 0x08 => Ok(TlPacketType::OtCmd), | ||
| 41 | 0x09 => Ok(TlPacketType::OtRsp), | ||
| 42 | 0x0A => Ok(TlPacketType::CliCmd), | ||
| 43 | 0x0C => Ok(TlPacketType::OtNot), | ||
| 44 | 0x0D => Ok(TlPacketType::OtAck), | ||
| 45 | 0x0E => Ok(TlPacketType::CliNot), | ||
| 46 | 0x0F => Ok(TlPacketType::CliAck), | ||
| 47 | 0x10 => Ok(TlPacketType::SysCmd), | ||
| 48 | 0x11 => Ok(TlPacketType::SysRsp), | ||
| 49 | 0x12 => Ok(TlPacketType::SysEvt), | ||
| 50 | 0x20 => Ok(TlPacketType::LocCmd), | ||
| 51 | 0x21 => Ok(TlPacketType::LocRsp), | ||
| 52 | 0x40 => Ok(TlPacketType::TracesApp), | ||
| 53 | 0x41 => Ok(TlPacketType::TracesWl), | ||
| 54 | |||
| 55 | _ => Err(()), | ||
| 56 | } | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | pub const TL_PACKET_HEADER_SIZE: usize = core::mem::size_of::<PacketHeader>(); | ||
| 61 | pub const TL_EVT_HEADER_SIZE: usize = 3; | ||
| 62 | pub const TL_CS_EVT_SIZE: usize = core::mem::size_of::<CsEvt>(); | ||
| 63 | |||
| 64 | /** | ||
| 65 | * Queue length of BLE Event | ||
| 66 | * This parameter defines the number of asynchronous events that can be stored in the HCI layer before | ||
| 67 | * being reported to the application. When a command is sent to the BLE core coprocessor, the HCI layer | ||
| 68 | * is waiting for the event with the Num_HCI_Command_Packets set to 1. The receive queue shall be large | ||
| 69 | * enough to store all asynchronous events received in between. | ||
| 70 | * When CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE is set to 27, this allow to store three 255 bytes long asynchronous events | ||
| 71 | * between the HCI command and its event. | ||
| 72 | * This parameter depends on the value given to CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE. When the queue size is too small, | ||
| 73 | * the system may hang if the queue is full with asynchronous events and the HCI layer is still waiting | ||
| 74 | * for a CC/CS event, In that case, the notification TL_BLE_HCI_ToNot() is called to indicate | ||
| 75 | * to the application a HCI command did not receive its command event within 30s (Default HCI Timeout). | ||
| 76 | */ | ||
| 77 | pub const CFG_TL_BLE_EVT_QUEUE_LENGTH: usize = 5; | ||
| 78 | pub const CFG_TL_BLE_MOST_EVENT_PAYLOAD_SIZE: usize = 255; | ||
| 79 | pub const TL_BLE_EVENT_FRAME_SIZE: usize = TL_EVT_HEADER_SIZE + CFG_TL_BLE_MOST_EVENT_PAYLOAD_SIZE; | ||
| 80 | |||
| 81 | pub const POOL_SIZE: usize = CFG_TL_BLE_EVT_QUEUE_LENGTH * 4 * divc(TL_PACKET_HEADER_SIZE + TL_BLE_EVENT_FRAME_SIZE, 4); | ||
| 82 | pub const C_SIZE_CMD_STRING: usize = 256; | ||
| 83 | |||
| 84 | pub const fn divc(x: usize, y: usize) -> usize { | ||
| 85 | (x + y - 1) / y | ||
| 86 | } | ||
| 87 | |||
| 88 | pub const TL_BLE_EVT_CS_PACKET_SIZE: usize = TL_EVT_HEADER_SIZE + TL_CS_EVT_SIZE; | ||
| 89 | #[allow(dead_code)] | ||
| 90 | pub const TL_BLE_EVT_CS_BUFFER_SIZE: usize = TL_PACKET_HEADER_SIZE + TL_BLE_EVT_CS_PACKET_SIZE; | ||
| 91 | |||
| 92 | pub const TL_BLEEVT_CC_OPCODE: u8 = 0x0E; | ||
| 93 | pub const TL_BLEEVT_CS_OPCODE: u8 = 0x0F; | ||
| 94 | pub const TL_BLEEVT_VS_OPCODE: u8 = 0xFF; | ||
