aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/eth/mod.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-12-17 22:09:14 +0100
committerDario Nieuwenhuis <[email protected]>2023-12-18 00:53:18 +0100
commit80c9d04bbd83367340a4f3a1e991df825a0b6029 (patch)
treed79b74b0ca17dd943dfcb3b809e895918f4ae629 /embassy-stm32/src/eth/mod.rs
parenta2d4bab2f8a4a9b994bc0289938a9f725950715f (diff)
stm32: add some docs.
Diffstat (limited to 'embassy-stm32/src/eth/mod.rs')
-rw-r--r--embassy-stm32/src/eth/mod.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/embassy-stm32/src/eth/mod.rs b/embassy-stm32/src/eth/mod.rs
index 556aadd73..dbf91eedc 100644
--- a/embassy-stm32/src/eth/mod.rs
+++ b/embassy-stm32/src/eth/mod.rs
@@ -22,6 +22,14 @@ const RX_BUFFER_SIZE: usize = 1536;
22#[derive(Copy, Clone)] 22#[derive(Copy, Clone)]
23pub(crate) struct Packet<const N: usize>([u8; N]); 23pub(crate) struct Packet<const N: usize>([u8; N]);
24 24
25/// Ethernet packet queue.
26///
27/// This struct owns the memory used for reading and writing packets.
28///
29/// `TX` is the number of packets in the transmit queue, `RX` in the receive
30/// queue. A bigger queue allows the hardware to receive more packets while the
31/// CPU is busy doing other things, which may increase performance (especially for RX)
32/// at the cost of more RAM usage.
25pub struct PacketQueue<const TX: usize, const RX: usize> { 33pub struct PacketQueue<const TX: usize, const RX: usize> {
26 tx_desc: [TDes; TX], 34 tx_desc: [TDes; TX],
27 rx_desc: [RDes; RX], 35 rx_desc: [RDes; RX],
@@ -30,6 +38,7 @@ pub struct PacketQueue<const TX: usize, const RX: usize> {
30} 38}
31 39
32impl<const TX: usize, const RX: usize> PacketQueue<TX, RX> { 40impl<const TX: usize, const RX: usize> PacketQueue<TX, RX> {
41 /// Create a new packet queue.
33 pub const fn new() -> Self { 42 pub const fn new() -> Self {
34 const NEW_TDES: TDes = TDes::new(); 43 const NEW_TDES: TDes = TDes::new();
35 const NEW_RDES: RDes = RDes::new(); 44 const NEW_RDES: RDes = RDes::new();
@@ -41,7 +50,18 @@ impl<const TX: usize, const RX: usize> PacketQueue<TX, RX> {
41 } 50 }
42 } 51 }
43 52
44 // Allow to initialize a Self without requiring it to go on the stack 53 /// Initialize a packet queue in-place.
54 ///
55 /// This can be helpful to avoid accidentally stack-allocating the packet queue in the stack. The
56 /// Rust compiler can sometimes be a bit dumb when working with large owned values: if you call `new()`
57 /// and then store the returned PacketQueue in its final place (like a `static`), the compiler might
58 /// place it temporarily on the stack then move it. Since this struct is quite big, it may result
59 /// in a stack overflow.
60 ///
61 /// With this function, you can create an uninitialized `static` with type `MaybeUninit<PacketQueue<...>>`
62 /// and initialize it in-place, guaranteeing no stack usage.
63 ///
64 /// After calling this function, calling `assume_init` on the MaybeUninit is guaranteed safe.
45 pub fn init(this: &mut MaybeUninit<Self>) { 65 pub fn init(this: &mut MaybeUninit<Self>) {
46 unsafe { 66 unsafe {
47 this.as_mut_ptr().write_bytes(0u8, 1); 67 this.as_mut_ptr().write_bytes(0u8, 1);
@@ -93,6 +113,7 @@ impl<'d, T: Instance, P: PHY> embassy_net_driver::Driver for Ethernet<'d, T, P>
93 } 113 }
94} 114}
95 115
116/// `embassy-net` RX token.
96pub struct RxToken<'a, 'd> { 117pub struct RxToken<'a, 'd> {
97 rx: &'a mut RDesRing<'d>, 118 rx: &'a mut RDesRing<'d>,
98} 119}
@@ -110,6 +131,7 @@ impl<'a, 'd> embassy_net_driver::RxToken for RxToken<'a, 'd> {
110 } 131 }
111} 132}
112 133
134/// `embassy-net` TX token.
113pub struct TxToken<'a, 'd> { 135pub struct TxToken<'a, 'd> {
114 tx: &'a mut TDesRing<'d>, 136 tx: &'a mut TDesRing<'d>,
115} 137}
@@ -159,6 +181,7 @@ pub(crate) mod sealed {
159 } 181 }
160} 182}
161 183
184/// Ethernet instance.
162pub trait Instance: sealed::Instance + Send + 'static {} 185pub trait Instance: sealed::Instance + Send + 'static {}
163 186
164impl sealed::Instance for crate::peripherals::ETH { 187impl sealed::Instance for crate::peripherals::ETH {