Skip to content

Commit b7511d7

Browse files
committed
Move all DMA related modules into a subfolder
1 parent e03d2cc commit b7511d7

File tree

13 files changed

+52
-48
lines changed

13 files changed

+52
-48
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use stm32_eth::{
2929
hal::gpio::GpioExt,
3030
hal::rcc::RccExt,
3131
stm32::Peripherals,
32-
RingEntry,
32+
dma::{RxRingEntry, TxRingEntry},
3333
EthPins,
3434
};
3535
use fugit::RateExtU32;
@@ -56,8 +56,8 @@ fn main() {
5656
rx_d1: gpioc.pc5,
5757
};
5858
59-
let mut rx_ring: [RingEntry<_>; 16] = Default::default();
60-
let mut tx_ring: [RingEntry<_>; 8] = Default::default();
59+
let mut rx_ring: [RxRingEntry; 16] = Default::default();
60+
let mut tx_ring: [TxRingEntry; 8] = Default::default();
6161
let (mut eth_dma, _eth_mac) = stm32_eth::new(
6262
p.ETHERNET_MAC,
6363
p.ETHERNET_MMC,

examples/arp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use stm32_eth::{
2222

2323
pub mod common;
2424

25-
use stm32_eth::{RingEntry, TxError};
25+
use stm32_eth::dma::{RxRingEntry, TxError, TxRingEntry};
2626

2727
const PHY_ADDR: u8 = 0;
2828

@@ -42,8 +42,8 @@ fn main() -> ! {
4242

4343
let (eth_pins, mdio, mdc) = common::setup_pins(gpio);
4444

45-
let mut rx_ring: [RingEntry<_>; 2] = Default::default();
46-
let mut tx_ring: [RingEntry<_>; 2] = Default::default();
45+
let mut rx_ring: [RxRingEntry; 2] = Default::default();
46+
let mut tx_ring: [TxRingEntry; 2] = Default::default();
4747

4848
let (mut eth_dma, eth_mac) = stm32_eth::new(
4949
ethernet.mac,

examples/ip.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address};
2222

2323
pub mod common;
2424

25-
use stm32_eth::RingEntry;
25+
use stm32_eth::dma::{RxRingEntry, TxRingEntry};
2626

2727
const SRC_MAC: [u8; 6] = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF];
2828

@@ -42,8 +42,8 @@ fn main() -> ! {
4242

4343
let (eth_pins, _mdio, _mdc) = common::setup_pins(gpio);
4444

45-
let mut rx_ring: [RingEntry<_>; 2] = Default::default();
46-
let mut tx_ring: [RingEntry<_>; 2] = Default::default();
45+
let mut rx_ring: [RxRingEntry; 2] = Default::default();
46+
let mut tx_ring: [TxRingEntry; 2] = Default::default();
4747
let (mut eth_dma, _eth_mac) = stm32_eth::new(
4848
ethernet.mac,
4949
ethernet.mmc,

examples/pktgen.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use stm32_eth::{
1717
stm32::{interrupt, CorePeripherals, Peripherals, SYST},
1818
};
1919

20-
use stm32_eth::{RingEntry, TxError};
20+
use stm32_eth::dma::{RxRingEntry, TxError, TxRingEntry};
2121

2222
pub mod common;
2323

@@ -41,8 +41,8 @@ fn main() -> ! {
4141
defmt::info!("Enabling ethernet...");
4242
let (eth_pins, mdio, mdc) = common::setup_pins(gpio);
4343

44-
let mut rx_ring: [RingEntry<_>; 2] = Default::default();
45-
let mut tx_ring: [RingEntry<_>; 2] = Default::default();
44+
let mut rx_ring: [RxRingEntry; 2] = Default::default();
45+
let mut tx_ring: [TxRingEntry; 2] = Default::default();
4646
let (mut eth_dma, eth_mac) = stm32_eth::new(
4747
ethernet.mac,
4848
ethernet.mmc,

examples/rtic-echo.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ mod app {
2828
use ieee802_3_miim::{phy::PhySpeed, Phy};
2929
use systick_monotonic::Systick;
3030

31-
use stm32_eth::{mac::Speed, EthernetDMA, RxRingEntry, TxRingEntry};
31+
use stm32_eth::{
32+
dma::{EthernetDMA, RxRingEntry, TxRingEntry},
33+
mac::Speed,
34+
};
3235

3336
use smoltcp::{
3437
iface::{self, Interface, SocketHandle},
File renamed without changes.

src/dma.rs renamed to src/dma/mod.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
1+
//! Ethernet DMA access and configuration.
2+
13
use core::borrow::Borrow;
24

35
use cortex_m::peripheral::NVIC;
46

57
use crate::{
68
peripherals::{ETHERNET_DMA, ETHERNET_MAC},
7-
rx::{RxPacket, RxRing},
89
stm32::Interrupt,
9-
tx::TxRing,
10-
RxError, RxRingEntry, TxError, TxRingEntry,
1110
};
1211

12+
#[cfg(feature = "smoltcp-phy")]
13+
mod smoltcp_phy;
14+
#[cfg(feature = "smoltcp-phy")]
15+
pub use smoltcp_phy::*;
16+
17+
pub(crate) mod desc;
18+
19+
pub(crate) mod ring;
20+
21+
mod rx;
22+
use rx::RxRing;
23+
pub use rx::{RxError, RxPacket, RxRingEntry};
24+
25+
mod tx;
26+
use tx::TxRing;
27+
pub use tx::{TxError, TxRingEntry};
28+
29+
/// From the datasheet: *VLAN Frame maxsize = 1522*
30+
pub(crate) const MTU: usize = 1522;
31+
1332
/// Ethernet DMA.
1433
pub struct EthernetDMA<'rx, 'tx> {
1534
eth_dma: ETHERNET_DMA,
@@ -173,8 +192,11 @@ impl<'rx, 'tx> EthernetDMA<'rx, 'tx> {
173192
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
174193
#[derive(Debug, Clone, Copy)]
175194
pub struct InterruptReasonSummary {
195+
/// The interrupt was caused by an RX event.
176196
pub is_rx: bool,
197+
/// The interrupt was caused by an TX event.
177198
pub is_tx: bool,
199+
/// The interrupt was caused by an error event.
178200
pub is_error: bool,
179201
}
180202

src/ring.rs renamed to src/dma/ring.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use aligned::{Aligned, A8};
22
use core::ops::{Deref, DerefMut};
33

4-
use crate::{RxDescriptor, TxDescriptor, MTU};
4+
use super::{rx::RxDescriptor, tx::TxDescriptor, MTU};
55

66
pub trait RingDescriptor {
77
fn setup(&mut self, buffer: *const u8, len: usize, next: Option<&Self>);

src/rx.rs renamed to src/dma/rx.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use core::{
66
sync::atomic::{self, Ordering},
77
};
88

9-
use crate::{
9+
use super::{
1010
desc::Descriptor,
1111
ring::{RingDescriptor, RingEntry},
1212
};
@@ -173,6 +173,7 @@ impl RxRingEntry {
173173
}
174174
}
175175

176+
/// A received packet.
176177
pub struct RxPacket<'a> {
177178
entry: &'a mut RxRingEntry,
178179
length: usize,
@@ -199,7 +200,7 @@ impl<'a> Drop for RxPacket<'a> {
199200
}
200201

201202
impl<'a> RxPacket<'a> {
202-
// Pass back to DMA engine
203+
/// Pass the received packet back to the DMA engine
203204
pub fn free(self) {
204205
drop(self)
205206
}

src/smoltcp_phy.rs renamed to src/dma/smoltcp_phy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{rx::RxPacket, tx::TxError, EthernetDMA};
1+
use super::{rx::RxPacket, tx::TxError, EthernetDMA};
22
use core::intrinsics::transmute;
33
use smoltcp::phy::{ChecksumCapabilities, Device, DeviceCapabilities, RxToken, TxToken};
44
use smoltcp::time::Instant;

0 commit comments

Comments
 (0)