Skip to content

Commit a2e3061

Browse files
committed
Update some things
1 parent 26388b6 commit a2e3061

File tree

5 files changed

+181
-165
lines changed

5 files changed

+181
-165
lines changed

src/dma/rx/f_series_desc.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,7 @@ impl RxDescriptor {
125125
((self.inner_raw.read(0) >> RXDESC_0_FL_SHIFT) & RXDESC_0_FL_MASK) as usize
126126
}
127127

128-
pub(super) fn take_received(
129-
&mut self,
130-
// NOTE(allow): packet_id is unused if ptp is disabled.
131-
#[allow(unused_variables)] packet_id: Option<PacketId>,
132-
) -> Result<(), RxError> {
128+
pub(super) fn take_received(&mut self, packet_id: Option<PacketId>) -> Result<(), RxError> {
133129
if self.is_owned() {
134130
Err(RxError::WouldBlock)
135131
} else if self.has_error() {

src/dma/rx/h_desc.rs

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,44 @@ impl RxDescriptor {
101101
}
102102
}
103103

104-
pub(super) fn setup(&mut self, buffer: &[u8]) {
105-
self.set_owned(buffer.as_ptr());
106-
}
107-
108104
/// Is owned by the DMA engine?
109105
fn is_owned(&self) -> bool {
110106
(self.inner_raw.read(3) & RXDESC_3_OWN) == RXDESC_3_OWN
111107
}
112108

109+
fn has_error(&self) -> bool {
110+
self.inner_raw.read(3) & RXDESC_3_ES == RXDESC_3_ES
111+
}
112+
113+
fn is_first(&self) -> bool {
114+
self.inner_raw.read(3) & RXDESC_3_FD == RXDESC_3_FD
115+
}
116+
117+
fn is_last(&self) -> bool {
118+
self.inner_raw.read(3) & RXDESC_3_LD == RXDESC_3_LD
119+
}
120+
121+
fn is_context(&self) -> bool {
122+
self.inner_raw.read(3) & RXDESC_3_CTXT == RXDESC_3_CTXT
123+
}
124+
125+
pub(super) fn frame_length(&self) -> usize {
126+
if self.is_owned() {
127+
0
128+
} else {
129+
((self.inner_raw.read(3) & RXDESC_3_PL_MASK) >> RXDESC_3_PL_SHIFT) as usize
130+
}
131+
}
132+
133+
#[allow(unused)]
134+
pub(super) fn packet_id(&self) -> Option<&PacketId> {
135+
self.packet_id.as_ref()
136+
}
137+
138+
pub(super) fn setup(&mut self, buffer: &[u8]) {
139+
self.set_owned(buffer.as_ptr());
140+
}
141+
113142
/// Pass ownership to the DMA engine
114143
pub(super) fn set_owned(&mut self, buffer: *const u8) {
115144
self.set_buffer(buffer);
@@ -154,26 +183,9 @@ impl RxDescriptor {
154183
}
155184
}
156185

157-
fn has_error(&self) -> bool {
158-
self.inner_raw.read(3) & RXDESC_3_ES == RXDESC_3_ES
159-
}
160-
161-
fn is_first(&self) -> bool {
162-
self.inner_raw.read(3) & RXDESC_3_FD == RXDESC_3_FD
163-
}
164-
165-
fn is_last(&self) -> bool {
166-
self.inner_raw.read(3) & RXDESC_3_LD == RXDESC_3_LD
167-
}
168-
169-
fn is_context(&self) -> bool {
170-
self.inner_raw.read(3) & RXDESC_3_CTXT == RXDESC_3_CTXT
171-
}
172-
173186
pub(super) fn take_received(
174187
&mut self,
175-
// NOTE(allow): packet_id is unused if ptp is disabled.
176-
#[allow(unused_variables)] packet_id: Option<PacketId>,
188+
packet_id: Option<PacketId>,
177189
buffer: &mut [u8],
178190
) -> Result<(), RxError> {
179191
if self.is_owned() {
@@ -197,19 +209,6 @@ impl RxDescriptor {
197209
Err(RxError::Truncated)
198210
}
199211
}
200-
201-
pub(super) fn frame_length(&self) -> usize {
202-
if self.is_owned() {
203-
0
204-
} else {
205-
((self.inner_raw.read(3) & RXDESC_3_PL_MASK) >> RXDESC_3_PL_SHIFT) as usize
206-
}
207-
}
208-
209-
#[allow(unused)]
210-
pub(super) fn packet_id(&self) -> Option<&PacketId> {
211-
self.packet_id.as_ref()
212-
}
213212
}
214213

215214
#[cfg(feature = "ptp")]

src/dma/tx/h_desc.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ mod consts {
2222
// Read format
2323
/// Interrupt On Completion
2424
pub const TXDESC_2_IOC: u32 = 1 << 31;
25-
2625
/// Transmit Timestamp Enable
2726
pub const TXDESC_2_TTSE: u32 = 1 << 30;
28-
2927
/// Buffer 2 length shift
3028
pub const TXDESC_2_B2L_SHIFT: u32 = 16;
3129
/// Buffer 2 length mask
@@ -86,28 +84,20 @@ mod consts {
8684
// Write back format
8785
/// Tx Timestamp status
8886
pub const TXDESC_3_TTSS: u32 = 1 << 17;
89-
9087
/// Error Summary
9188
pub const TXDESC_3_ES: u32 = 1 << 15;
92-
9389
/// Jabber timeout
9490
pub const TXDESC_3_JT: u32 = 1 << 14;
95-
9691
/// Packet flushed
9792
pub const TXDESC_3_FF: u32 = 1 << 13;
98-
9993
/// Payload Checksum Error
10094
pub const TXDESC_3_PCE: u32 = 1 << 12;
101-
10295
/// Loss of Carrier
10396
pub const TXDESC_3_LOC: u32 = 1 << 11;
104-
10597
/// No Carrier
10698
pub const TXDESC_3_NC: u32 = 1 << 10;
107-
10899
/// Late Collision
109100
pub const TXDESC_3_LC: u32 = 1 << 9;
110-
111101
/// Excessive Collision
112102
pub const TXDESC_3_EC: u32 = 1 << 8;
113103

@@ -118,13 +108,10 @@ mod consts {
118108

119109
/// Excessive Deferral
120110
pub const TXDESC_3_ED: u32 = 1 << 3;
121-
122111
/// Underflow error
123112
pub const TXDESC_3_UF: u32 = 1 << 2;
124-
125113
/// Deferred Bit
126114
pub const TXDESC_3_DB: u32 = 1 << 1;
127-
128115
/// IP Header Error
129116
pub const TXDESC_3_IHE: u32 = 1 << 0;
130117
}
@@ -164,6 +151,11 @@ impl TxDescriptor {
164151
(self.inner_raw.read(3) & TXDESC_3_OWN) == TXDESC_3_OWN
165152
}
166153

154+
#[allow(unused)]
155+
pub(super) fn packet_id(&self) -> Option<&PacketId> {
156+
self.packet_id.as_ref()
157+
}
158+
167159
/// Pass ownership to the DMA engine
168160
pub(super) fn send(&mut self, packet_id: Option<PacketId>, buffer: &[u8]) {
169161
self.set_buffer(buffer);
@@ -219,10 +211,6 @@ impl TxDescriptor {
219211
});
220212
}
221213
}
222-
223-
// pub(super) fn packet_id(&self) -> Option<&PacketId> {
224-
// self.packet_id.as_ref()
225-
// }
226214
}
227215

228216
#[cfg(feature = "ptp")]

src/lib.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub use smoltcp;
5656
#[cfg(feature = "device-selected")]
5757
use {
5858
dma::{DmaParts, EthernetDMA, RxDescriptorRing, TxDescriptorRing},
59-
mac::{EthernetMAC, Speed, WrongClock},
59+
mac::{EthernetMAC, MacParts, Speed, WrongClock},
6060
setup::*,
6161
};
6262

@@ -108,8 +108,6 @@ where
108108
// Set up the clocks and reset the MAC periperhal
109109
setup::setup();
110110

111-
let eth_mac = parts.mac.into();
112-
113111
// Congfigure and start up the ethernet DMA.
114112
let dma = EthernetDMA::new(
115113
DmaParts {
@@ -125,13 +123,17 @@ where
125123
#[cfg(feature = "ptp")]
126124
let ptp = EthernetPTP::new(parts.ptp.into(), clocks, &dma);
127125

128-
#[cfg(not(feature = "stm32h7xx-hal"))]
129-
let mmc = parts.mmc;
130-
#[cfg(feature = "stm32h7xx-hal")]
131-
let mmc = ();
132-
133126
// Configure the ethernet MAC
134-
let mac = EthernetMAC::new(eth_mac, mmc, clocks, Speed::FullDuplexBase100Tx, &dma)?;
127+
let mac = EthernetMAC::new(
128+
MacParts {
129+
eth_mac: parts.mac.into(),
130+
#[cfg(feature = "f-series")]
131+
eth_mmc: parts.mmc.into(),
132+
},
133+
clocks,
134+
Speed::FullDuplexBase100Tx,
135+
&dma,
136+
)?;
135137

136138
let parts = Parts {
137139
mac,
@@ -200,8 +202,13 @@ where
200202
let ptp = EthernetPTP::new(parts.ptp.into(), clocks, &dma);
201203

202204
// Configure the ethernet MAC
203-
let mac = EthernetMAC::new(eth_mac, parts.mmc, clocks, Speed::FullDuplexBase100Tx, &dma)?
204-
.with_mii(mdio, mdc);
205+
let mac = EthernetMAC::new(
206+
MacParts { eth_mac, eth_mmc },
207+
clocks,
208+
Speed::FullDuplexBase100Tx,
209+
&dma,
210+
)?
211+
.with_mii(mdio, mdc);
205212

206213
let parts = Parts {
207214
mac,

0 commit comments

Comments
 (0)