Skip to content

Commit

Permalink
Make f series compile again
Browse files Browse the repository at this point in the history
  • Loading branch information
datdenkikniet committed Feb 4, 2023
1 parent a2e3061 commit e9828f4
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 115 deletions.
8 changes: 1 addition & 7 deletions src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ use cortex_m::peripheral::NVIC;

use crate::{peripherals::ETHERNET_DMA, stm32::Interrupt};

#[cfg(feature = "f-series")]
type ETHERNET_MTL = ();

#[cfg(feature = "stm32h7xx-hal")]
use crate::stm32::ETHERNET_MTL;

#[cfg(feature = "smoltcp-phy")]
mod smoltcp_phy;
#[cfg(feature = "smoltcp-phy")]
Expand Down Expand Up @@ -77,7 +71,7 @@ pub struct EthernetDMA<'rx, 'tx> {
pub(crate) struct DmaParts {
pub eth_dma: ETHERNET_DMA,
#[cfg(feature = "stm32h7xx-hal")]
pub eth_mtl: ETHERNET_MTL,
pub eth_mtl: crate::stm32::ETHERNET_MTL,
}

impl<'rx, 'tx> EthernetDMA<'rx, 'tx> {
Expand Down
23 changes: 14 additions & 9 deletions src/dma/rx/f_series_desc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ impl RxDescriptor {
}

pub(super) fn setup(&mut self, buffer: &mut [u8]) {
self.set_buffer(buffer);
self.set_owned();
self.set_owned(buffer);
}

/// Is owned by the DMA engine?
Expand All @@ -71,7 +70,9 @@ impl RxDescriptor {
/// Pass ownership to the DMA engine
///
/// Overrides old timestamp data
pub(super) fn set_owned(&mut self) {
pub(super) fn set_owned(&mut self, buffer: &mut [u8]) {
self.set_buffer(buffer);

// "Preceding reads and writes cannot be moved past subsequent writes."
#[cfg(feature = "fence")]
atomic::fence(Ordering::Release);
Expand Down Expand Up @@ -125,11 +126,15 @@ impl RxDescriptor {
((self.inner_raw.read(0) >> RXDESC_0_FL_SHIFT) & RXDESC_0_FL_MASK) as usize
}

pub(super) fn take_received(&mut self, packet_id: Option<PacketId>) -> Result<(), RxError> {
pub(super) fn take_received(
&mut self,
packet_id: Option<PacketId>,
buffer: &mut [u8],
) -> Result<(), RxError> {
if self.is_owned() {
Err(RxError::WouldBlock)
} else if self.has_error() {
self.set_owned();
self.set_owned(buffer);
Err(RxError::DmaError)
} else if self.is_first() && self.is_last() {
// "Subsequent reads and writes cannot be moved ahead of preceding reads."
Expand All @@ -143,22 +148,22 @@ impl RxDescriptor {

Ok(())
} else {
self.set_owned();
self.set_owned(buffer);
Err(RxError::Truncated)
}
}

pub(super) fn set_end_of_ring(&mut self) {
unsafe { self.inner_raw.modify(1, |w| w | RXDESC_1_RER) }
}
}

#[cfg(feature = "ptp")]
impl RxDescriptor {
pub(super) fn packet_id(&self) -> Option<&PacketId> {
self.packet_id.as_ref()
}
}

#[cfg(feature = "ptp")]
impl RxDescriptor {
/// Get PTP timestamps if available
pub(super) fn read_timestamp(&self) -> Option<Timestamp> {
#[cfg(not(feature = "stm32f1xx-hal"))]
Expand Down
7 changes: 4 additions & 3 deletions src/dma/rx/h_desc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,12 @@ impl RxDescriptor {
}

pub(super) fn setup(&mut self, buffer: &[u8]) {
self.set_owned(buffer.as_ptr());
self.set_owned(buffer);
}

/// Pass ownership to the DMA engine
pub(super) fn set_owned(&mut self, buffer: *const u8) {
pub(super) fn set_owned(&mut self, buffer: &[u8]) {
let buffer = buffer.as_ptr();
self.set_buffer(buffer);

// "Preceding reads and writes cannot be moved past subsequent writes."
Expand Down Expand Up @@ -205,7 +206,7 @@ impl RxDescriptor {

Ok(())
} else {
self.set_owned(buffer.as_ptr());
self.set_owned(buffer);
Err(RxError::Truncated)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/dma/rx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ impl<'a> core::ops::DerefMut for RxPacket<'a> {

impl<'a> Drop for RxPacket<'a> {
fn drop(&mut self) {
self.entry.set_owned(self.buffer.as_ptr());
self.entry.set_owned(self.buffer);
}
}

Expand Down
24 changes: 14 additions & 10 deletions src/dma/tx/f_series_desc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ impl TxDescriptor {

pub(super) fn setup(&mut self, buffer: &mut [u8]) {
self.set_buffer(buffer);
unsafe {
self.inner_raw.write(
0,
TXDESC_0_CIC0 | TXDESC_0_CIC1 | TXDESC_0_FS | TXDESC_0_LS | TXDESC_0_IC,
);
}
}

#[allow(unused)]
Expand Down Expand Up @@ -112,7 +106,17 @@ impl TxDescriptor {
atomic::fence(Ordering::Release);
atomic::compiler_fence(Ordering::Release);

unsafe { self.inner_raw.modify(0, |w| w | extra_flags | TXDESC_0_OWN) };
unsafe {
self.inner_raw.modify(0, |w| {
w | extra_flags
| TXDESC_0_OWN
| TXDESC_0_CIC0
| TXDESC_0_CIC1
| TXDESC_0_FS
| TXDESC_0_LS
| TXDESC_0_IC
})
};

// Used to flush the store buffer as fast as possible to make the buffer available for the
// DMA.
Expand Down Expand Up @@ -144,14 +148,14 @@ impl TxDescriptor {
pub(super) fn set_end_of_ring(&mut self) {
unsafe { self.inner_raw.modify(0, |w| w | TXDESC_0_TER) };
}
}

#[cfg(feature = "ptp")]
impl TxDescriptor {
pub(super) fn packet_id(&self) -> Option<&PacketId> {
self.packet_id.as_ref()
}
}

#[cfg(feature = "ptp")]
impl TxDescriptor {
fn read_timestamp(&mut self) -> Option<Timestamp> {
let tdes0 = self.inner_raw.read(0);

Expand Down
10 changes: 5 additions & 5 deletions src/dma/tx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub(crate) struct TxRing<'data, STATE> {
impl<'data, STATE> TxRing<'data, STATE> {
pub fn running_state(&self, eth_dma: &ETHERNET_DMA) -> RunningState {
#[cfg(feature = "f-series")]
let tx_status = eth_dma.dmasr().read().tps().bits();
let tx_status = eth_dma.dmasr.read().tps().bits();

#[cfg(feature = "stm32h7xx-hal")]
let tx_status = eth_dma.dmadsr.read().tps0().bits();
Expand Down Expand Up @@ -97,7 +97,7 @@ impl<'data> TxRing<'data, NotRunning> {

#[cfg(feature = "f-series")]
// Set end of ring register
self.ring.last_descriptor().set_end_of_ring();
self.ring.last_descriptor_mut().set_end_of_ring();

let ring_ptr = self.ring.descriptors_start_address();

Expand Down Expand Up @@ -235,20 +235,20 @@ impl<'data> TxRing<'data, Running> {
impl<'data> TxRing<'data, Running> {
pub(crate) fn collect_timestamps(&mut self) {
for descriptor in self.ring.descriptors_mut() {
f_descriptor.attach_timestamp();
descriptor.attach_timestamp();
}
}

pub(crate) fn get_timestamp_for_id(&self, id: PacketId) -> Result<Timestamp, TimestampError> {
let descriptor = if let Some(descriptor) =
self.ring.descriptors().find(|d| d.packet_id() == Some(&id))
{
f_descriptor
descriptor
} else {
return Err(TimestampError::IdNotFound);
};

f_descriptor
descriptor
.timestamp()
.map(|t| *t)
.ok_or(TimestampError::NotYetTimestamped)
Expand Down
53 changes: 25 additions & 28 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,32 +108,27 @@ where
// Set up the clocks and reset the MAC periperhal
setup::setup();

let dma_parts = DmaParts {
eth_dma: parts.dma.into(),
#[cfg(feature = "stm32h7xx-hal")]
eth_mtl: parts.mtl,
};

let mac_parts = MacParts {
eth_mac: parts.mac.into(),
#[cfg(feature = "f-series")]
eth_mmc: parts.mmc.into(),
};

// Congfigure and start up the ethernet DMA.
let dma = EthernetDMA::new(
DmaParts {
eth_dma: parts.dma,
#[cfg(feature = "stm32h7xx-hal")]
eth_mtl: parts.mtl,
},
rx_buffer,
tx_buffer,
);
let dma = EthernetDMA::new(dma_parts, rx_buffer, tx_buffer);

// Configure the ethernet PTP
#[cfg(feature = "ptp")]
let ptp = EthernetPTP::new(parts.ptp.into(), clocks, &dma);

// Configure the ethernet MAC
let mac = EthernetMAC::new(
MacParts {
eth_mac: parts.mac.into(),
#[cfg(feature = "f-series")]
eth_mmc: parts.mmc.into(),
},
clocks,
Speed::FullDuplexBase100Tx,
&dma,
)?;
let mac = EthernetMAC::new(mac_parts, clocks, Speed::FullDuplexBase100Tx, &dma)?;

let parts = Parts {
mac,
Expand Down Expand Up @@ -192,23 +187,25 @@ where
// Set up the clocks and reset the MAC periperhal
setup::setup();

let eth_mac = parts.mac.into();
let dma_parts = DmaParts {
eth_dma: parts.dma.into(),
};

let mac_parts = MacParts {
eth_mac: parts.mac.into(),
eth_mmc: parts.mmc.into(),
};

// Congfigure and start up the ethernet DMA.
let dma = EthernetDMA::new(parts.dma.into(), rx_buffer, tx_buffer);
let dma = EthernetDMA::new(dma_parts, rx_buffer, tx_buffer);

// Configure the ethernet PTP
#[cfg(feature = "ptp")]
let ptp = EthernetPTP::new(parts.ptp.into(), clocks, &dma);

// Configure the ethernet MAC
let mac = EthernetMAC::new(
MacParts { eth_mac, eth_mmc },
clocks,
Speed::FullDuplexBase100Tx,
&dma,
)?
.with_mii(mdio, mdc);
let mac =
EthernetMAC::new(mac_parts, clocks, Speed::FullDuplexBase100Tx, &dma)?.with_mii(mdio, mdc);

let parts = Parts {
mac,
Expand Down
7 changes: 4 additions & 3 deletions src/mac/miim.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
pub use ieee802_3_miim::Miim;

pub use ieee802_3_miim::*;

use core::ops::{Deref, DerefMut};

use crate::{peripherals::ETHERNET_MAC, stm32::ethernet_mac::MACMIIAR};

use super::EthernetMAC;
Expand Down Expand Up @@ -157,7 +158,7 @@ where
MDIO: MdioPin,
MDC: MdcPin,
{
pub(crate) eth_mac: EthernetMAC,
eth_mac: EthernetMAC,
mdio: MDIO,
mdc: MDC,
}
Expand Down Expand Up @@ -226,7 +227,7 @@ where
}
}

impl<MDIO, MDC> miim::Miim for EthernetMACWithMii<MDIO, MDC>
impl<MDIO, MDC> Miim for EthernetMACWithMii<MDIO, MDC>
where
MDIO: MdioPin,
MDC: MdcPin,
Expand Down
Loading

0 comments on commit e9828f4

Please sign in to comment.