aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2023-02-28 18:26:37 +0000
committerGitHub <[email protected]>2023-02-28 18:26:37 +0000
commitb16b3b0dbb16a46cee448b3a7656594a3001082e (patch)
treed4ed60a70d28cb5decf8eb89142273b27a63aedd
parentd719f8bc035485d19aff3ef76de0e1e7ba9d362e (diff)
parent3c601bf8d2624d6fa8fd8e68dfee5cb9348ab4f9 (diff)
Merge #1247
1247: `PacketQueue::init()` r=davidedellagiustina a=davidedellagiustina `PacketQueue` is pretty big, so I added a method to initialize it without requiring an allocation on the stack (which could in fact overflow). Before this PR, the only solution would be to declare a `PacketQueue` instance as a `static mut`, while now one could for example have a `Box<MaybeUninit<PacketQueue<...>>>` and then use `init()` on it. Ideally, the same work would need to be done for all those structures that own big arrays which could overflow the stack. Co-authored-by: Davide Della Giustina <[email protected]>
-rw-r--r--embassy-stm32/src/eth/mod.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/embassy-stm32/src/eth/mod.rs b/embassy-stm32/src/eth/mod.rs
index 9f62b61ee..b632861bf 100644
--- a/embassy-stm32/src/eth/mod.rs
+++ b/embassy-stm32/src/eth/mod.rs
@@ -5,6 +5,7 @@
5mod _version; 5mod _version;
6pub mod generic_smi; 6pub mod generic_smi;
7 7
8use core::mem::MaybeUninit;
8use core::task::Context; 9use core::task::Context;
9 10
10use embassy_net_driver::{Capabilities, LinkState}; 11use embassy_net_driver::{Capabilities, LinkState};
@@ -39,6 +40,13 @@ impl<const TX: usize, const RX: usize> PacketQueue<TX, RX> {
39 rx_buf: [Packet([0; RX_BUFFER_SIZE]); RX], 40 rx_buf: [Packet([0; RX_BUFFER_SIZE]); RX],
40 } 41 }
41 } 42 }
43
44 // Allow to initialize a Self without requiring it to go on the stack
45 pub fn init(this: &mut MaybeUninit<Self>) {
46 unsafe {
47 this.as_mut_ptr().write_bytes(0u8, core::mem::size_of::<Self>());
48 }
49 }
42} 50}
43 51
44static WAKER: AtomicWaker = AtomicWaker::new(); 52static WAKER: AtomicWaker = AtomicWaker::new();