diff options
Diffstat (limited to 'embassy-stm32-wpan/src/wb55/tables.rs')
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/tables.rs | 283 |
1 files changed, 283 insertions, 0 deletions
diff --git a/embassy-stm32-wpan/src/wb55/tables.rs b/embassy-stm32-wpan/src/wb55/tables.rs new file mode 100644 index 000000000..2e6a9199b --- /dev/null +++ b/embassy-stm32-wpan/src/wb55/tables.rs | |||
| @@ -0,0 +1,283 @@ | |||
| 1 | use core::mem::MaybeUninit; | ||
| 2 | |||
| 3 | use aligned::{A4, Aligned}; | ||
| 4 | use bit_field::BitField; | ||
| 5 | |||
| 6 | use crate::cmd::{AclDataPacket, CmdPacket}; | ||
| 7 | #[cfg(feature = "wb55_mac")] | ||
| 8 | use crate::consts::C_SIZE_CMD_STRING; | ||
| 9 | use crate::consts::{POOL_SIZE, TL_CS_EVT_SIZE, TL_EVT_HEADER_SIZE, TL_PACKET_HEADER_SIZE}; | ||
| 10 | use crate::unsafe_linked_list::LinkedListNode; | ||
| 11 | |||
| 12 | #[derive(Debug, Copy, Clone)] | ||
| 13 | #[repr(C, packed)] | ||
| 14 | pub struct SafeBootInfoTable { | ||
| 15 | version: u32, | ||
| 16 | } | ||
| 17 | |||
| 18 | #[derive(Debug, Copy, Clone)] | ||
| 19 | #[repr(C, packed)] | ||
| 20 | pub struct RssInfoTable { | ||
| 21 | pub version: u32, | ||
| 22 | pub memory_size: u32, | ||
| 23 | pub rss_info: u32, | ||
| 24 | } | ||
| 25 | |||
| 26 | /** | ||
| 27 | * Version | ||
| 28 | * \[0:3\] = Build - 0: Untracked - 15:Released - x: Tracked version | ||
| 29 | * \[4:7\] = branch - 0: Mass Market - x: ... | ||
| 30 | * \[8:15\] = Subversion | ||
| 31 | * \[16:23\] = Version minor | ||
| 32 | * \[24:31\] = Version major | ||
| 33 | * | ||
| 34 | * Memory Size | ||
| 35 | * \[0:7\] = Flash ( Number of 4k sector) | ||
| 36 | * \[8:15\] = Reserved ( Shall be set to 0 - may be used as flash extension ) | ||
| 37 | * \[16:23\] = SRAM2b ( Number of 1k sector) | ||
| 38 | * \[24:31\] = SRAM2a ( Number of 1k sector) | ||
| 39 | */ | ||
| 40 | #[derive(Debug, Copy, Clone)] | ||
| 41 | #[repr(C, packed)] | ||
| 42 | pub struct WirelessFwInfoTable { | ||
| 43 | pub version: u32, | ||
| 44 | pub memory_size: u32, | ||
| 45 | pub thread_info: u32, | ||
| 46 | pub ble_info: u32, | ||
| 47 | } | ||
| 48 | |||
| 49 | impl WirelessFwInfoTable { | ||
| 50 | pub fn version_major(&self) -> u8 { | ||
| 51 | let version = self.version; | ||
| 52 | (version.get_bits(24..31) & 0xff) as u8 | ||
| 53 | } | ||
| 54 | |||
| 55 | pub fn version_minor(&self) -> u8 { | ||
| 56 | let version = self.version; | ||
| 57 | (version.clone().get_bits(16..23) & 0xff) as u8 | ||
| 58 | } | ||
| 59 | |||
| 60 | pub fn subversion(&self) -> u8 { | ||
| 61 | let version = self.version; | ||
| 62 | (version.clone().get_bits(8..15) & 0xff) as u8 | ||
| 63 | } | ||
| 64 | |||
| 65 | /// Size of FLASH, expressed in number of 4K sectors. | ||
| 66 | pub fn flash_size(&self) -> u8 { | ||
| 67 | let memory_size = self.memory_size; | ||
| 68 | (memory_size.clone().get_bits(0..7) & 0xff) as u8 | ||
| 69 | } | ||
| 70 | |||
| 71 | /// Size of SRAM2a, expressed in number of 1K sectors. | ||
| 72 | pub fn sram2a_size(&self) -> u8 { | ||
| 73 | let memory_size = self.memory_size; | ||
| 74 | (memory_size.clone().get_bits(24..31) & 0xff) as u8 | ||
| 75 | } | ||
| 76 | |||
| 77 | /// Size of SRAM2b, expressed in number of 1K sectors. | ||
| 78 | pub fn sram2b_size(&self) -> u8 { | ||
| 79 | let memory_size = self.memory_size; | ||
| 80 | (memory_size.clone().get_bits(16..23) & 0xff) as u8 | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | #[derive(Debug, Clone)] | ||
| 85 | #[repr(C)] | ||
| 86 | pub struct DeviceInfoTable { | ||
| 87 | pub safe_boot_info_table: SafeBootInfoTable, | ||
| 88 | pub rss_info_table: RssInfoTable, | ||
| 89 | pub wireless_fw_info_table: WirelessFwInfoTable, | ||
| 90 | } | ||
| 91 | |||
| 92 | /// The bluetooth reference table, as defined in figure 67 of STM32WX AN5289. | ||
| 93 | #[derive(Debug)] | ||
| 94 | #[repr(C)] | ||
| 95 | pub struct BleTable { | ||
| 96 | /// A pointer to the buffer that is used for sending BLE commands. | ||
| 97 | pub pcmd_buffer: *mut CmdPacket, | ||
| 98 | /// A pointer to the buffer used for storing Command statuses. | ||
| 99 | pub pcs_buffer: *const u8, | ||
| 100 | /// A pointer to the event queue, over which IPCC BLE events are sent. This may be accessed via | ||
| 101 | /// [crate::sub::ble::Ble::tl_read]. | ||
| 102 | pub pevt_queue: *const u8, | ||
| 103 | /// A pointer to the buffer that is used for sending HCI (Host-Controller Interface) ACL | ||
| 104 | /// (Asynchronous Connection-oriented Logical transport) commands (unused). | ||
| 105 | pub phci_acl_data_buffer: *mut AclDataPacket, | ||
| 106 | } | ||
| 107 | |||
| 108 | #[derive(Debug)] | ||
| 109 | #[repr(C)] | ||
| 110 | pub struct ThreadTable { | ||
| 111 | pub nostack_buffer: *const u8, | ||
| 112 | pub clicmdrsp_buffer: *const u8, | ||
| 113 | pub otcmdrsp_buffer: *const u8, | ||
| 114 | } | ||
| 115 | |||
| 116 | #[derive(Debug)] | ||
| 117 | #[repr(C)] | ||
| 118 | pub struct LldTestsTable { | ||
| 119 | pub clicmdrsp_buffer: *const u8, | ||
| 120 | pub m0cmd_buffer: *const u8, | ||
| 121 | } | ||
| 122 | |||
| 123 | // TODO: use later | ||
| 124 | #[derive(Debug)] | ||
| 125 | #[repr(C)] | ||
| 126 | pub struct BleLldTable { | ||
| 127 | pub cmdrsp_buffer: *const u8, | ||
| 128 | pub m0cmd_buffer: *const u8, | ||
| 129 | } | ||
| 130 | |||
| 131 | // TODO: use later | ||
| 132 | #[derive(Debug)] | ||
| 133 | #[repr(C)] | ||
| 134 | pub struct ZigbeeTable { | ||
| 135 | pub notif_m0_to_m4_buffer: *const u8, | ||
| 136 | pub appli_cmd_m4_to_m0_bufer: *const u8, | ||
| 137 | pub request_m0_to_m4_buffer: *const u8, | ||
| 138 | } | ||
| 139 | |||
| 140 | #[derive(Debug)] | ||
| 141 | #[repr(C)] | ||
| 142 | pub struct SysTable { | ||
| 143 | pub pcmd_buffer: *mut CmdPacket, | ||
| 144 | pub sys_queue: *const LinkedListNode, | ||
| 145 | } | ||
| 146 | |||
| 147 | #[derive(Debug)] | ||
| 148 | #[repr(C)] | ||
| 149 | pub struct MemManagerTable { | ||
| 150 | pub spare_ble_buffer: *const u8, | ||
| 151 | pub spare_sys_buffer: *const u8, | ||
| 152 | |||
| 153 | pub blepool: *const u8, | ||
| 154 | pub blepoolsize: u32, | ||
| 155 | |||
| 156 | pub pevt_free_buffer_queue: *mut LinkedListNode, | ||
| 157 | |||
| 158 | pub traces_evt_pool: *const u8, | ||
| 159 | pub tracespoolsize: u32, | ||
| 160 | } | ||
| 161 | |||
| 162 | #[derive(Debug)] | ||
| 163 | #[repr(C)] | ||
| 164 | pub struct TracesTable { | ||
| 165 | pub traces_queue: *const u8, | ||
| 166 | } | ||
| 167 | |||
| 168 | #[derive(Debug)] | ||
| 169 | #[repr(C)] | ||
| 170 | pub struct Mac802_15_4Table { | ||
| 171 | pub p_cmdrsp_buffer: *const u8, | ||
| 172 | pub p_notack_buffer: *const u8, | ||
| 173 | pub evt_queue: *const u8, | ||
| 174 | } | ||
| 175 | |||
| 176 | /// Reference table. Contains pointers to all other tables. | ||
| 177 | #[derive(Debug, Copy, Clone)] | ||
| 178 | #[repr(C)] | ||
| 179 | pub struct RefTable { | ||
| 180 | pub device_info_table: *const DeviceInfoTable, | ||
| 181 | pub ble_table: *const BleTable, | ||
| 182 | pub thread_table: *const ThreadTable, | ||
| 183 | pub sys_table: *const SysTable, | ||
| 184 | pub mem_manager_table: *const MemManagerTable, | ||
| 185 | pub traces_table: *const TracesTable, | ||
| 186 | pub mac_802_15_4_table: *const Mac802_15_4Table, | ||
| 187 | pub zigbee_table: *const ZigbeeTable, | ||
| 188 | pub lld_tests_table: *const LldTestsTable, | ||
| 189 | pub ble_lld_table: *const BleLldTable, | ||
| 190 | } | ||
| 191 | |||
| 192 | // --------------------- ref table --------------------- | ||
| 193 | #[unsafe(link_section = "TL_REF_TABLE")] | ||
| 194 | pub static mut TL_REF_TABLE: MaybeUninit<RefTable> = MaybeUninit::zeroed(); | ||
| 195 | |||
| 196 | #[unsafe(link_section = "MB_MEM1")] | ||
| 197 | pub static mut TL_DEVICE_INFO_TABLE: Aligned<A4, MaybeUninit<DeviceInfoTable>> = Aligned(MaybeUninit::zeroed()); | ||
| 198 | |||
| 199 | #[unsafe(link_section = "MB_MEM1")] | ||
| 200 | pub static mut TL_BLE_TABLE: Aligned<A4, MaybeUninit<BleTable>> = Aligned(MaybeUninit::zeroed()); | ||
| 201 | |||
| 202 | #[unsafe(link_section = "MB_MEM1")] | ||
| 203 | pub static mut TL_THREAD_TABLE: Aligned<A4, MaybeUninit<ThreadTable>> = Aligned(MaybeUninit::zeroed()); | ||
| 204 | |||
| 205 | #[unsafe(link_section = "MB_MEM1")] | ||
| 206 | pub static mut TL_LLD_TESTS_TABLE: Aligned<A4, MaybeUninit<LldTestsTable>> = Aligned(MaybeUninit::zeroed()); | ||
| 207 | |||
| 208 | #[unsafe(link_section = "MB_MEM1")] | ||
| 209 | pub static mut TL_BLE_LLD_TABLE: Aligned<A4, MaybeUninit<BleLldTable>> = Aligned(MaybeUninit::zeroed()); | ||
| 210 | |||
| 211 | #[unsafe(link_section = "MB_MEM1")] | ||
| 212 | pub static mut TL_SYS_TABLE: Aligned<A4, MaybeUninit<SysTable>> = Aligned(MaybeUninit::zeroed()); | ||
| 213 | |||
| 214 | #[unsafe(link_section = "MB_MEM1")] | ||
| 215 | pub static mut TL_MEM_MANAGER_TABLE: Aligned<A4, MaybeUninit<MemManagerTable>> = Aligned(MaybeUninit::zeroed()); | ||
| 216 | |||
| 217 | #[unsafe(link_section = "MB_MEM1")] | ||
| 218 | pub static mut TL_TRACES_TABLE: Aligned<A4, MaybeUninit<TracesTable>> = Aligned(MaybeUninit::zeroed()); | ||
| 219 | |||
| 220 | #[unsafe(link_section = "MB_MEM1")] | ||
| 221 | pub static mut TL_MAC_802_15_4_TABLE: Aligned<A4, MaybeUninit<Mac802_15_4Table>> = Aligned(MaybeUninit::zeroed()); | ||
| 222 | |||
| 223 | #[unsafe(link_section = "MB_MEM1")] | ||
| 224 | pub static mut TL_ZIGBEE_TABLE: Aligned<A4, MaybeUninit<ZigbeeTable>> = Aligned(MaybeUninit::zeroed()); | ||
| 225 | |||
| 226 | // --------------------- tables --------------------- | ||
| 227 | #[unsafe(link_section = "MB_MEM1")] | ||
| 228 | pub static mut FREE_BUF_QUEUE: Aligned<A4, MaybeUninit<LinkedListNode>> = Aligned(MaybeUninit::zeroed()); | ||
| 229 | |||
| 230 | #[allow(dead_code)] | ||
| 231 | #[unsafe(link_section = "MB_MEM1")] | ||
| 232 | pub static mut TRACES_EVT_QUEUE: Aligned<A4, MaybeUninit<LinkedListNode>> = Aligned(MaybeUninit::zeroed()); | ||
| 233 | |||
| 234 | #[unsafe(link_section = "MB_MEM2")] | ||
| 235 | pub static mut CS_BUFFER: Aligned<A4, MaybeUninit<[u8; TL_PACKET_HEADER_SIZE + TL_EVT_HEADER_SIZE + TL_CS_EVT_SIZE]>> = | ||
| 236 | Aligned(MaybeUninit::zeroed()); | ||
| 237 | |||
| 238 | #[unsafe(link_section = "MB_MEM2")] | ||
| 239 | pub static mut EVT_QUEUE: Aligned<A4, MaybeUninit<LinkedListNode>> = Aligned(MaybeUninit::zeroed()); | ||
| 240 | |||
| 241 | #[unsafe(link_section = "MB_MEM2")] | ||
| 242 | pub static mut SYSTEM_EVT_QUEUE: Aligned<A4, MaybeUninit<LinkedListNode>> = Aligned(MaybeUninit::zeroed()); | ||
| 243 | |||
| 244 | // --------------------- app tables --------------------- | ||
| 245 | #[cfg(feature = "wb55_mac")] | ||
| 246 | #[unsafe(link_section = "MB_MEM2")] | ||
| 247 | pub static mut MAC_802_15_4_CMD_BUFFER: Aligned<A4, MaybeUninit<CmdPacket>> = Aligned(MaybeUninit::zeroed()); | ||
| 248 | |||
| 249 | #[cfg(feature = "wb55_mac")] | ||
| 250 | #[unsafe(link_section = "MB_MEM2")] | ||
| 251 | pub static mut MAC_802_15_4_NOTIF_RSP_EVT_BUFFER: MaybeUninit< | ||
| 252 | Aligned<A4, [u8; TL_PACKET_HEADER_SIZE + TL_EVT_HEADER_SIZE + 255]>, | ||
| 253 | > = MaybeUninit::zeroed(); | ||
| 254 | |||
| 255 | #[unsafe(link_section = "MB_MEM2")] | ||
| 256 | pub static mut EVT_POOL: Aligned<A4, MaybeUninit<[u8; POOL_SIZE]>> = Aligned(MaybeUninit::zeroed()); | ||
| 257 | |||
| 258 | #[unsafe(link_section = "MB_MEM2")] | ||
| 259 | pub static mut SYS_CMD_BUF: Aligned<A4, MaybeUninit<CmdPacket>> = Aligned(MaybeUninit::zeroed()); | ||
| 260 | |||
| 261 | #[unsafe(link_section = "MB_MEM2")] | ||
| 262 | pub static mut SYS_SPARE_EVT_BUF: Aligned<A4, MaybeUninit<[u8; TL_PACKET_HEADER_SIZE + TL_EVT_HEADER_SIZE + 255]>> = | ||
| 263 | Aligned(MaybeUninit::zeroed()); | ||
| 264 | |||
| 265 | #[cfg(feature = "wb55_mac")] | ||
| 266 | #[unsafe(link_section = "MB_MEM2")] | ||
| 267 | pub static mut MAC_802_15_4_CNFINDNOT: Aligned<A4, MaybeUninit<[u8; C_SIZE_CMD_STRING]>> = | ||
| 268 | Aligned(MaybeUninit::zeroed()); | ||
| 269 | |||
| 270 | #[cfg(feature = "wb55_ble")] | ||
| 271 | #[unsafe(link_section = "MB_MEM1")] | ||
| 272 | pub static mut BLE_CMD_BUFFER: Aligned<A4, MaybeUninit<CmdPacket>> = Aligned(MaybeUninit::zeroed()); | ||
| 273 | |||
| 274 | #[cfg(feature = "wb55_ble")] | ||
| 275 | #[unsafe(link_section = "MB_MEM2")] | ||
| 276 | pub static mut BLE_SPARE_EVT_BUF: Aligned<A4, MaybeUninit<[u8; TL_PACKET_HEADER_SIZE + TL_EVT_HEADER_SIZE + 255]>> = | ||
| 277 | Aligned(MaybeUninit::zeroed()); | ||
| 278 | |||
| 279 | #[cfg(feature = "wb55_ble")] | ||
| 280 | #[unsafe(link_section = "MB_MEM2")] | ||
| 281 | // fuck these "magic" numbers from ST ---v---v | ||
| 282 | pub static mut HCI_ACL_DATA_BUFFER: Aligned<A4, MaybeUninit<[u8; TL_PACKET_HEADER_SIZE + 5 + 251]>> = | ||
| 283 | Aligned(MaybeUninit::zeroed()); | ||
