aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxoviat <[email protected]>2023-06-18 10:11:36 -0500
committerxoviat <[email protected]>2023-06-18 10:11:36 -0500
commit9f63158aad81486b4bd0ffe6f8d7103458ba360f (patch)
tree0991b5765a5f16efed7e1cf3954f295a651a9377
parent748d1ea89da160df927ea3dd597704ba236e0fb6 (diff)
stm32/wpan: reorg modules
-rw-r--r--embassy-stm32-wpan/src/consts.rs34
-rw-r--r--embassy-stm32-wpan/src/lib.rs97
-rw-r--r--embassy-stm32-wpan/src/mm.rs13
-rw-r--r--embassy-stm32-wpan/src/shci.rs2
-rw-r--r--embassy-stm32-wpan/src/tables.rs77
5 files changed, 120 insertions, 103 deletions
diff --git a/embassy-stm32-wpan/src/consts.rs b/embassy-stm32-wpan/src/consts.rs
index caf26c06b..9a107306c 100644
--- a/embassy-stm32-wpan/src/consts.rs
+++ b/embassy-stm32-wpan/src/consts.rs
@@ -1,5 +1,8 @@
1use core::convert::TryFrom; 1use core::convert::TryFrom;
2 2
3use crate::evt::CsEvt;
4use crate::PacketHeader;
5
3#[derive(Debug)] 6#[derive(Debug)]
4#[repr(C)] 7#[repr(C)]
5pub enum TlPacketType { 8pub enum TlPacketType {
@@ -53,3 +56,34 @@ impl TryFrom<u8> for TlPacketType {
53 } 56 }
54 } 57 }
55} 58}
59
60pub const TL_PACKET_HEADER_SIZE: usize = core::mem::size_of::<PacketHeader>();
61pub const TL_EVT_HEADER_SIZE: usize = 3;
62pub 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 to 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 */
77pub const CFG_TL_BLE_EVT_QUEUE_LENGTH: usize = 5;
78pub const CFG_TL_BLE_MOST_EVENT_PAYLOAD_SIZE: usize = 255;
79pub const TL_BLE_EVENT_FRAME_SIZE: usize = TL_EVT_HEADER_SIZE + CFG_TL_BLE_MOST_EVENT_PAYLOAD_SIZE;
80
81pub const POOL_SIZE: usize = CFG_TL_BLE_EVT_QUEUE_LENGTH * 4 * divc(TL_PACKET_HEADER_SIZE + TL_BLE_EVENT_FRAME_SIZE, 4);
82
83pub const fn divc(x: usize, y: usize) -> usize {
84 (x + y - 1) / y
85}
86
87pub const TL_BLE_EVT_CS_PACKET_SIZE: usize = TL_EVT_HEADER_SIZE + TL_CS_EVT_SIZE;
88#[allow(dead_code)]
89pub const TL_BLE_EVT_CS_BUFFER_SIZE: usize = TL_PACKET_HEADER_SIZE + TL_BLE_EVT_CS_PACKET_SIZE;
diff --git a/embassy-stm32-wpan/src/lib.rs b/embassy-stm32-wpan/src/lib.rs
index 035b130c8..1ddb3f2e0 100644
--- a/embassy-stm32-wpan/src/lib.rs
+++ b/embassy-stm32-wpan/src/lib.rs
@@ -7,16 +7,13 @@ use core::mem::MaybeUninit;
7use core::sync::atomic::{compiler_fence, Ordering}; 7use core::sync::atomic::{compiler_fence, Ordering};
8 8
9use ble::Ble; 9use ble::Ble;
10use cmd::CmdPacket;
11use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; 10use embassy_hal_common::{into_ref, Peripheral, PeripheralRef};
12use embassy_stm32::interrupt; 11use embassy_stm32::interrupt;
13use embassy_stm32::ipcc::{Config, Ipcc, ReceiveInterruptHandler, TransmitInterruptHandler}; 12use embassy_stm32::ipcc::{Config, Ipcc, ReceiveInterruptHandler, TransmitInterruptHandler};
14use embassy_stm32::peripherals::IPCC; 13use embassy_stm32::peripherals::IPCC;
15use mm::MemoryManager; 14use mm::MemoryManager;
16use sys::Sys; 15use sys::Sys;
17use tables::{ 16use tables::*;
18 BleTable, DeviceInfoTable, Mac802_15_4Table, MemManagerTable, RefTable, SysTable, ThreadTable, TracesTable,
19};
20use unsafe_linked_list::LinkedListNode; 17use unsafe_linked_list::LinkedListNode;
21 18
22pub mod ble; 19pub mod ble;
@@ -30,100 +27,8 @@ pub mod sys;
30pub mod tables; 27pub mod tables;
31pub mod unsafe_linked_list; 28pub mod unsafe_linked_list;
32 29
33#[link_section = "TL_REF_TABLE"]
34pub static mut TL_REF_TABLE: MaybeUninit<RefTable> = MaybeUninit::uninit();
35
36#[link_section = "MB_MEM1"]
37static mut TL_DEVICE_INFO_TABLE: MaybeUninit<DeviceInfoTable> = MaybeUninit::uninit();
38
39#[link_section = "MB_MEM1"]
40static mut TL_BLE_TABLE: MaybeUninit<BleTable> = MaybeUninit::uninit();
41
42#[link_section = "MB_MEM1"]
43static mut TL_THREAD_TABLE: MaybeUninit<ThreadTable> = MaybeUninit::uninit();
44
45#[link_section = "MB_MEM1"]
46static mut TL_SYS_TABLE: MaybeUninit<SysTable> = MaybeUninit::uninit();
47
48#[link_section = "MB_MEM1"]
49static mut TL_MEM_MANAGER_TABLE: MaybeUninit<MemManagerTable> = MaybeUninit::uninit();
50
51#[link_section = "MB_MEM1"]
52static mut TL_TRACES_TABLE: MaybeUninit<TracesTable> = MaybeUninit::uninit();
53
54#[link_section = "MB_MEM1"]
55static mut TL_MAC_802_15_4_TABLE: MaybeUninit<Mac802_15_4Table> = MaybeUninit::uninit();
56
57#[link_section = "MB_MEM2"]
58static mut FREE_BUF_QUEUE: MaybeUninit<LinkedListNode> = MaybeUninit::uninit();
59
60// Not in shared RAM
61static mut LOCAL_FREE_BUF_QUEUE: MaybeUninit<LinkedListNode> = MaybeUninit::uninit();
62
63#[allow(dead_code)] // Not used currently but reserved
64#[link_section = "MB_MEM2"]
65static mut TRACES_EVT_QUEUE: MaybeUninit<LinkedListNode> = MaybeUninit::uninit();
66
67type PacketHeader = LinkedListNode; 30type PacketHeader = LinkedListNode;
68 31
69const TL_PACKET_HEADER_SIZE: usize = core::mem::size_of::<PacketHeader>();
70const TL_EVT_HEADER_SIZE: usize = 3;
71const TL_CS_EVT_SIZE: usize = core::mem::size_of::<evt::CsEvt>();
72
73#[link_section = "MB_MEM2"]
74static mut CS_BUFFER: MaybeUninit<[u8; TL_PACKET_HEADER_SIZE + TL_EVT_HEADER_SIZE + TL_CS_EVT_SIZE]> =
75 MaybeUninit::uninit();
76
77#[link_section = "MB_MEM2"]
78static mut EVT_QUEUE: MaybeUninit<LinkedListNode> = MaybeUninit::uninit();
79
80#[link_section = "MB_MEM2"]
81static mut SYSTEM_EVT_QUEUE: MaybeUninit<LinkedListNode> = MaybeUninit::uninit();
82
83#[link_section = "MB_MEM2"]
84pub static mut SYS_CMD_BUF: MaybeUninit<CmdPacket> = MaybeUninit::uninit();
85
86/**
87 * Queue length of BLE Event
88 * This parameter defines the number of asynchronous events that can be stored in the HCI layer before
89 * being reported to the application. When a command is sent to the BLE core coprocessor, the HCI layer
90 * is waiting for the event with the Num_HCI_Command_Packets set to 1. The receive queue shall be large
91 * enough to store all asynchronous events received in between.
92 * When CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE is set to 27, this allow to store three 255 bytes long asynchronous events
93 * between the HCI command and its event.
94 * This parameter depends on the value given to CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE. When the queue size is to small,
95 * the system may hang if the queue is full with asynchronous events and the HCI layer is still waiting
96 * for a CC/CS event, In that case, the notification TL_BLE_HCI_ToNot() is called to indicate
97 * to the application a HCI command did not receive its command event within 30s (Default HCI Timeout).
98 */
99const CFG_TLBLE_EVT_QUEUE_LENGTH: usize = 5;
100const CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE: usize = 255;
101const TL_BLE_EVENT_FRAME_SIZE: usize = TL_EVT_HEADER_SIZE + CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE;
102
103const fn divc(x: usize, y: usize) -> usize {
104 ((x) + (y) - 1) / (y)
105}
106
107const POOL_SIZE: usize = CFG_TLBLE_EVT_QUEUE_LENGTH * 4 * divc(TL_PACKET_HEADER_SIZE + TL_BLE_EVENT_FRAME_SIZE, 4);
108
109#[link_section = "MB_MEM2"]
110static mut EVT_POOL: MaybeUninit<[u8; POOL_SIZE]> = MaybeUninit::uninit();
111
112#[link_section = "MB_MEM2"]
113static mut SYS_SPARE_EVT_BUF: MaybeUninit<[u8; TL_PACKET_HEADER_SIZE + TL_EVT_HEADER_SIZE + 255]> =
114 MaybeUninit::uninit();
115
116#[link_section = "MB_MEM2"]
117static mut BLE_SPARE_EVT_BUF: MaybeUninit<[u8; TL_PACKET_HEADER_SIZE + TL_EVT_HEADER_SIZE + 255]> =
118 MaybeUninit::uninit();
119
120#[link_section = "MB_MEM2"]
121static mut BLE_CMD_BUFFER: MaybeUninit<CmdPacket> = MaybeUninit::uninit();
122
123#[link_section = "MB_MEM2"]
124// fuck these "magic" numbers from ST ---v---v
125static mut HCI_ACL_DATA_BUFFER: MaybeUninit<[u8; TL_PACKET_HEADER_SIZE + 5 + 251]> = MaybeUninit::uninit();
126
127pub struct TlMbox<'d> { 32pub struct TlMbox<'d> {
128 _ipcc: PeripheralRef<'d, IPCC>, 33 _ipcc: PeripheralRef<'d, IPCC>,
129 34
diff --git a/embassy-stm32-wpan/src/mm.rs b/embassy-stm32-wpan/src/mm.rs
index 21f42409a..dc499c1e7 100644
--- a/embassy-stm32-wpan/src/mm.rs
+++ b/embassy-stm32-wpan/src/mm.rs
@@ -1,22 +1,23 @@
1//! Memory manager routines 1//! Memory manager routines
2
3use core::future::poll_fn; 2use core::future::poll_fn;
4use core::marker::PhantomData; 3use core::marker::PhantomData;
4use core::mem::MaybeUninit;
5use core::task::Poll; 5use core::task::Poll;
6 6
7use cortex_m::interrupt; 7use cortex_m::interrupt;
8use embassy_stm32::ipcc::Ipcc; 8use embassy_stm32::ipcc::Ipcc;
9use embassy_sync::waitqueue::AtomicWaker; 9use embassy_sync::waitqueue::AtomicWaker;
10 10
11use crate::channels;
12use crate::consts::POOL_SIZE;
11use crate::evt::EvtPacket; 13use crate::evt::EvtPacket;
12use crate::tables::MemManagerTable; 14use crate::tables::{
13use crate::unsafe_linked_list::LinkedListNode; 15 MemManagerTable, BLE_SPARE_EVT_BUF, EVT_POOL, FREE_BUF_QUEUE, SYS_SPARE_EVT_BUF, TL_MEM_MANAGER_TABLE,
14use crate::{
15 channels, BLE_SPARE_EVT_BUF, EVT_POOL, FREE_BUF_QUEUE, LOCAL_FREE_BUF_QUEUE, POOL_SIZE, SYS_SPARE_EVT_BUF,
16 TL_MEM_MANAGER_TABLE,
17}; 16};
17use crate::unsafe_linked_list::LinkedListNode;
18 18
19static MM_WAKER: AtomicWaker = AtomicWaker::new(); 19static MM_WAKER: AtomicWaker = AtomicWaker::new();
20static mut LOCAL_FREE_BUF_QUEUE: MaybeUninit<LinkedListNode> = MaybeUninit::uninit();
20 21
21pub struct MemoryManager { 22pub struct MemoryManager {
22 phantom: PhantomData<MemoryManager>, 23 phantom: PhantomData<MemoryManager>,
diff --git a/embassy-stm32-wpan/src/shci.rs b/embassy-stm32-wpan/src/shci.rs
index f4e9ba84c..b60158b1b 100644
--- a/embassy-stm32-wpan/src/shci.rs
+++ b/embassy-stm32-wpan/src/shci.rs
@@ -1,6 +1,6 @@
1use core::{mem, slice}; 1use core::{mem, slice};
2 2
3use super::{TL_CS_EVT_SIZE, TL_EVT_HEADER_SIZE, TL_PACKET_HEADER_SIZE}; 3use crate::consts::{TL_CS_EVT_SIZE, TL_EVT_HEADER_SIZE, TL_PACKET_HEADER_SIZE};
4 4
5const SHCI_OGF: u16 = 0x3F; 5const SHCI_OGF: u16 = 0x3F;
6 6
diff --git a/embassy-stm32-wpan/src/tables.rs b/embassy-stm32-wpan/src/tables.rs
index 151216958..81873b147 100644
--- a/embassy-stm32-wpan/src/tables.rs
+++ b/embassy-stm32-wpan/src/tables.rs
@@ -1,6 +1,9 @@
1use core::mem::MaybeUninit;
2
1use bit_field::BitField; 3use bit_field::BitField;
2 4
3use crate::cmd::{AclDataPacket, CmdPacket}; 5use crate::cmd::{AclDataPacket, CmdPacket};
6use crate::consts::{POOL_SIZE, TL_CS_EVT_SIZE, TL_EVT_HEADER_SIZE, TL_PACKET_HEADER_SIZE};
4use crate::unsafe_linked_list::LinkedListNode; 7use crate::unsafe_linked_list::LinkedListNode;
5 8
6#[derive(Debug, Copy, Clone)] 9#[derive(Debug, Copy, Clone)]
@@ -173,3 +176,77 @@ pub struct RefTable {
173 pub traces_table: *const TracesTable, 176 pub traces_table: *const TracesTable,
174 pub mac_802_15_4_table: *const Mac802_15_4Table, 177 pub mac_802_15_4_table: *const Mac802_15_4Table,
175} 178}
179
180// --------------------- ref table ---------------------
181#[link_section = "TL_REF_TABLE"]
182pub static mut TL_REF_TABLE: MaybeUninit<RefTable> = MaybeUninit::uninit();
183
184#[link_section = "MB_MEM1"]
185pub static mut TL_DEVICE_INFO_TABLE: MaybeUninit<DeviceInfoTable> = MaybeUninit::uninit();
186
187#[link_section = "MB_MEM1"]
188pub static mut TL_BLE_TABLE: MaybeUninit<BleTable> = MaybeUninit::uninit();
189
190#[link_section = "MB_MEM1"]
191pub static mut TL_THREAD_TABLE: MaybeUninit<ThreadTable> = MaybeUninit::uninit();
192
193// #[link_section = "MB_MEM1"]
194// pub static mut TL_LLD_TESTS_TABLE: MaybeUninit<LldTestTable> = MaybeUninit::uninit();
195
196// #[link_section = "MB_MEM1"]
197// pub static mut TL_BLE_LLD_TABLE: MaybeUninit<BleLldTable> = MaybeUninit::uninit();
198
199#[link_section = "MB_MEM1"]
200pub static mut TL_SYS_TABLE: MaybeUninit<SysTable> = MaybeUninit::uninit();
201
202#[link_section = "MB_MEM1"]
203pub static mut TL_MEM_MANAGER_TABLE: MaybeUninit<MemManagerTable> = MaybeUninit::uninit();
204
205#[link_section = "MB_MEM1"]
206pub static mut TL_TRACES_TABLE: MaybeUninit<TracesTable> = MaybeUninit::uninit();
207
208#[link_section = "MB_MEM1"]
209pub static mut TL_MAC_802_15_4_TABLE: MaybeUninit<Mac802_15_4Table> = MaybeUninit::uninit();
210
211// #[link_section = "MB_MEM1"]
212// pub static mut TL_ZIGBEE_TABLE: MaybeUninit<ZigbeeTable> = MaybeUninit::uninit();
213
214// --------------------- tables ---------------------
215#[link_section = "MB_MEM1"]
216pub static mut FREE_BUF_QUEUE: MaybeUninit<LinkedListNode> = MaybeUninit::uninit();
217
218#[allow(dead_code)]
219#[link_section = "MB_MEM1"]
220pub static mut TRACES_EVT_QUEUE: MaybeUninit<LinkedListNode> = MaybeUninit::uninit();
221
222#[link_section = "MB_MEM2"]
223pub static mut CS_BUFFER: MaybeUninit<[u8; TL_PACKET_HEADER_SIZE + TL_EVT_HEADER_SIZE + TL_CS_EVT_SIZE]> =
224 MaybeUninit::uninit();
225
226#[link_section = "MB_MEM2"]
227pub static mut EVT_QUEUE: MaybeUninit<LinkedListNode> = MaybeUninit::uninit();
228
229#[link_section = "MB_MEM2"]
230pub static mut SYSTEM_EVT_QUEUE: MaybeUninit<LinkedListNode> = MaybeUninit::uninit();
231
232// --------------------- app tables ---------------------
233#[link_section = "MB_MEM2"]
234pub static mut EVT_POOL: MaybeUninit<[u8; POOL_SIZE]> = MaybeUninit::uninit();
235
236#[link_section = "MB_MEM2"]
237pub static mut SYS_CMD_BUF: MaybeUninit<CmdPacket> = MaybeUninit::uninit();
238
239#[link_section = "MB_MEM2"]
240pub static mut SYS_SPARE_EVT_BUF: MaybeUninit<[u8; TL_PACKET_HEADER_SIZE + TL_EVT_HEADER_SIZE + 255]> =
241 MaybeUninit::uninit();
242
243#[link_section = "MB_MEM1"]
244pub static mut BLE_CMD_BUFFER: MaybeUninit<CmdPacket> = MaybeUninit::uninit();
245
246#[link_section = "MB_MEM2"]
247pub static mut BLE_SPARE_EVT_BUF: MaybeUninit<[u8; TL_PACKET_HEADER_SIZE + TL_EVT_HEADER_SIZE + 255]> =
248 MaybeUninit::uninit();
249
250#[link_section = "MB_MEM2"]
251// fuck these "magic" numbers from ST ---v---v
252pub static mut HCI_ACL_DATA_BUFFER: MaybeUninit<[u8; TL_PACKET_HEADER_SIZE + 5 + 251]> = MaybeUninit::uninit();