Skip to content

Commit cffc535

Browse files
committed
Fix async receive and timestamping on h7, it's wonky
1 parent bac114e commit cffc535

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

src/dma/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ impl<'rx, 'tx> EthernetDMA<'rx, 'tx> {
298298
let rx_descriptor_addr = eth_dma.dmaccarx_dr.read().bits();
299299
let rx_buffer_addr = eth_dma.dmaccarx_br.read().bits();
300300

301+
// TODO: add a link to a/the github issue describing this problem,
302+
// and how to solve it.
301303
panic!("Fatal bus error! Is the descriptor and buffer memory accessible by the Ethernet MAC/DMA? TXDESC: {:08X}, TXBUF: {:08X}, RXDESC: {:08X}, TXDESC: {:08X}", tx_descriptor_addr, tx_buffer_addr, rx_descriptor_addr, rx_buffer_addr);
302304
}
303305

@@ -352,9 +354,6 @@ impl<'rx, 'tx> EthernetDMA<'rx, 'tx> {
352354
});
353355

354356
if status.fbe().bit_is_set() {
355-
// TODO: add a link to a/the github issue describing this problem,
356-
// and how to solve it.
357-
358357
EthernetDMA::panic_fbe();
359358
}
360359

src/dma/rx/mod.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,14 @@ impl<'a> RxRing<'a> {
216216
self.ring.descriptor(self.next_entry).is_available()
217217
}
218218

219-
/// Receive the next packet (if any is ready).
219+
/// Obtain the index of the packet to receive (if any is ready).
220220
///
221-
/// This function returns a tuple of `Ok((entry_index, length))` on
221+
/// This function returns a tuple of `Ok(entry_index)` on
222222
/// success. Whoever receives the `Ok` must ensure that `set_owned`
223223
/// is eventually called on the entry with that index.
224+
///
225+
/// Actually obtaining the relevant RxPacket is done using
226+
/// [`RxRing::recv_and_timestamp`].
224227
fn recv_next_impl(
225228
&mut self,
226229
// NOTE(allow): packet_id is unused if ptp is disabled.
@@ -245,14 +248,10 @@ impl<'a> RxRing<'a> {
245248
}
246249
}
247250

248-
/// Receive the next packet (if any is ready), or return [`Err`]
249-
/// immediately.
250-
pub fn recv_next(&mut self, packet_id: Option<PacketId>) -> Result<RxPacket, RxError> {
251+
fn recv_and_timestamp(&mut self, entry: usize) -> RxPacket {
251252
#[cfg(feature = "stm32h7xx-hal")]
252253
let entries_len = self.ring.len();
253254

254-
let entry = self.recv_next_impl(packet_id.map(|p| p.into()))?;
255-
256255
#[cfg(feature = "f-series")]
257256
let (desc, buffer) = self.ring.get_mut(entry);
258257

@@ -276,11 +275,19 @@ impl<'a> RxRing<'a> {
276275

277276
let length = desc.frame_len();
278277

279-
Ok(RxPacket {
278+
RxPacket {
280279
entry: desc,
281280
buffer,
282281
length,
283-
})
282+
}
283+
}
284+
285+
/// Receive the next packet (if any is ready), or return [`Err`]
286+
/// immediately.
287+
pub fn recv_next(&mut self, packet_id: Option<PacketId>) -> Result<RxPacket, RxError> {
288+
let entry = self.recv_next_impl(packet_id.map(|p| p.into()))?;
289+
290+
Ok(self.recv_and_timestamp(entry))
284291
}
285292

286293
/// Receive the next packet.
@@ -302,14 +309,7 @@ impl<'a> RxRing<'a> {
302309
})
303310
.await;
304311

305-
let (desc, buffer) = self.ring.get_mut(entry);
306-
let length = desc.frame_len();
307-
308-
RxPacket {
309-
entry: desc,
310-
buffer,
311-
length,
312-
}
312+
self.recv_and_timestamp(entry)
313313
}
314314
}
315315

0 commit comments

Comments
 (0)