2021-06-07 07:30:38 +02:00
|
|
|
use core::marker::PhantomData;
|
|
|
|
use core::sync::atomic::{fence, Ordering};
|
2021-06-11 04:22:34 +02:00
|
|
|
use core::task::Waker;
|
2021-06-07 07:30:38 +02:00
|
|
|
|
|
|
|
use embassy::util::{AtomicWaker, Unborrow};
|
2021-07-29 14:08:32 +02:00
|
|
|
use embassy_hal_common::peripheral::{PeripheralMutex, PeripheralState, StateStorage};
|
2021-07-29 13:44:51 +02:00
|
|
|
use embassy_hal_common::unborrow;
|
2021-06-11 04:22:34 +02:00
|
|
|
use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU};
|
2021-06-07 07:30:38 +02:00
|
|
|
|
|
|
|
use crate::gpio::sealed::Pin as __GpioPin;
|
|
|
|
use crate::gpio::AnyPin;
|
|
|
|
use crate::gpio::Pin as GpioPin;
|
|
|
|
use crate::pac::gpio::vals::Ospeedr;
|
2021-06-11 04:42:20 +02:00
|
|
|
use crate::pac::{ETH, RCC, SYSCFG};
|
2021-06-07 07:30:38 +02:00
|
|
|
use crate::peripherals;
|
|
|
|
|
|
|
|
mod descriptors;
|
2021-06-10 07:38:59 +02:00
|
|
|
use super::{StationManagement, PHY};
|
2021-06-07 07:30:38 +02:00
|
|
|
use descriptors::DescriptorRing;
|
|
|
|
|
2021-07-29 14:08:32 +02:00
|
|
|
pub struct State<'d, const TX: usize, const RX: usize>(StateStorage<Inner<'d, TX, RX>>);
|
|
|
|
impl<'d, const TX: usize, const RX: usize> State<'d, TX, RX> {
|
2021-08-02 19:50:07 +02:00
|
|
|
pub const fn new() -> Self {
|
2021-07-29 14:08:32 +02:00
|
|
|
Self(StateStorage::new())
|
|
|
|
}
|
|
|
|
}
|
2021-06-11 04:33:31 +02:00
|
|
|
pub struct Ethernet<'d, P: PHY, const TX: usize, const RX: usize> {
|
2021-07-29 14:08:32 +02:00
|
|
|
state: PeripheralMutex<'d, Inner<'d, TX, RX>>,
|
2021-06-07 07:30:38 +02:00
|
|
|
pins: [AnyPin; 9],
|
2021-06-10 07:38:59 +02:00
|
|
|
_phy: P,
|
|
|
|
clock_range: u8,
|
|
|
|
phy_addr: u8,
|
2021-06-11 04:22:34 +02:00
|
|
|
mac_addr: [u8; 6],
|
2021-06-07 07:30:38 +02:00
|
|
|
}
|
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
impl<'d, P: PHY, const TX: usize, const RX: usize> Ethernet<'d, P, TX, RX> {
|
2021-08-02 12:40:01 +02:00
|
|
|
/// safety: the returned instance is not leak-safe
|
|
|
|
pub unsafe fn new(
|
2021-07-29 14:08:32 +02:00
|
|
|
state: &'d mut State<'d, TX, RX>,
|
2021-06-11 04:33:31 +02:00
|
|
|
peri: impl Unborrow<Target = peripherals::ETH> + 'd,
|
|
|
|
interrupt: impl Unborrow<Target = crate::interrupt::ETH> + 'd,
|
|
|
|
ref_clk: impl Unborrow<Target = impl RefClkPin> + 'd,
|
|
|
|
mdio: impl Unborrow<Target = impl MDIOPin> + 'd,
|
|
|
|
mdc: impl Unborrow<Target = impl MDCPin> + 'd,
|
|
|
|
crs: impl Unborrow<Target = impl CRSPin> + 'd,
|
|
|
|
rx_d0: impl Unborrow<Target = impl RXD0Pin> + 'd,
|
|
|
|
rx_d1: impl Unborrow<Target = impl RXD1Pin> + 'd,
|
|
|
|
tx_d0: impl Unborrow<Target = impl TXD0Pin> + 'd,
|
|
|
|
tx_d1: impl Unborrow<Target = impl TXD1Pin> + 'd,
|
|
|
|
tx_en: impl Unborrow<Target = impl TXEnPin> + 'd,
|
2021-06-10 07:38:59 +02:00
|
|
|
phy: P,
|
2021-06-07 07:30:38 +02:00
|
|
|
mac_addr: [u8; 6],
|
2021-06-10 07:38:59 +02:00
|
|
|
phy_addr: u8,
|
2021-06-07 07:30:38 +02:00
|
|
|
) -> Self {
|
|
|
|
unborrow!(interrupt, ref_clk, mdio, mdc, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en);
|
|
|
|
|
2021-06-11 04:42:20 +02:00
|
|
|
// Enable the necessary Clocks
|
|
|
|
// NOTE(unsafe) We have exclusive access to the registers
|
2021-08-02 12:40:01 +02:00
|
|
|
critical_section::with(|_| {
|
2021-06-11 04:42:20 +02:00
|
|
|
RCC.apb4enr().modify(|w| w.set_syscfgen(true));
|
|
|
|
RCC.ahb1enr().modify(|w| {
|
|
|
|
w.set_eth1macen(true);
|
|
|
|
w.set_eth1txen(true);
|
|
|
|
w.set_eth1rxen(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
// RMII
|
|
|
|
SYSCFG.pmcr().modify(|w| w.set_epis(0b100));
|
|
|
|
});
|
|
|
|
|
2021-06-07 07:30:38 +02:00
|
|
|
ref_clk.configure();
|
|
|
|
mdio.configure();
|
|
|
|
mdc.configure();
|
|
|
|
crs.configure();
|
|
|
|
rx_d0.configure();
|
|
|
|
rx_d1.configure();
|
|
|
|
tx_d0.configure();
|
|
|
|
tx_d1.configure();
|
|
|
|
tx_en.configure();
|
|
|
|
|
2021-08-02 12:40:01 +02:00
|
|
|
// NOTE(unsafe) We are ourselves not leak-safe.
|
2021-08-02 20:13:41 +02:00
|
|
|
let state = PeripheralMutex::new_unchecked(interrupt, &mut state.0, || Inner::new(peri));
|
2021-06-07 07:30:38 +02:00
|
|
|
|
2021-08-02 12:40:01 +02:00
|
|
|
// NOTE(unsafe) We have exclusive access to the registers
|
|
|
|
let dma = ETH.ethernet_dma();
|
|
|
|
let mac = ETH.ethernet_mac();
|
|
|
|
let mtl = ETH.ethernet_mtl();
|
|
|
|
|
|
|
|
// Reset and wait
|
|
|
|
dma.dmamr().modify(|w| w.set_swr(true));
|
|
|
|
while dma.dmamr().read().swr() {}
|
|
|
|
|
|
|
|
mac.maccr().modify(|w| {
|
|
|
|
w.set_ipg(0b000); // 96 bit times
|
|
|
|
w.set_acs(true);
|
|
|
|
w.set_fes(true);
|
|
|
|
w.set_dm(true);
|
|
|
|
// TODO: Carrier sense ? ECRSFD
|
|
|
|
});
|
2021-06-07 07:30:38 +02:00
|
|
|
|
2021-09-07 00:16:43 +02:00
|
|
|
// Note: Writing to LR triggers synchronisation of both LR and HR into the MAC core,
|
|
|
|
// so the LR write must happen after the HR write.
|
|
|
|
mac.maca0hr()
|
|
|
|
.modify(|w| w.set_addrhi(u16::from(mac_addr[4]) | (u16::from(mac_addr[5]) << 8)));
|
2021-08-02 12:40:01 +02:00
|
|
|
mac.maca0lr().write(|w| {
|
|
|
|
w.set_addrlo(
|
|
|
|
u32::from(mac_addr[0])
|
|
|
|
| (u32::from(mac_addr[1]) << 8)
|
|
|
|
| (u32::from(mac_addr[2]) << 16)
|
|
|
|
| (u32::from(mac_addr[3]) << 24),
|
|
|
|
)
|
|
|
|
});
|
2021-06-07 07:30:38 +02:00
|
|
|
|
2021-08-02 12:40:01 +02:00
|
|
|
mac.macqtx_fcr().modify(|w| w.set_pt(0x100));
|
2021-06-07 07:30:38 +02:00
|
|
|
|
2021-08-02 12:40:01 +02:00
|
|
|
mtl.mtlrx_qomr().modify(|w| w.set_rsf(true));
|
|
|
|
mtl.mtltx_qomr().modify(|w| w.set_tsf(true));
|
2021-06-07 07:30:38 +02:00
|
|
|
|
2021-08-02 12:40:01 +02:00
|
|
|
dma.dmactx_cr().modify(|w| w.set_txpbl(1)); // 32 ?
|
|
|
|
dma.dmacrx_cr().modify(|w| {
|
|
|
|
w.set_rxpbl(1); // 32 ?
|
|
|
|
w.set_rbsz(MTU as u16);
|
|
|
|
});
|
2021-06-07 07:30:38 +02:00
|
|
|
|
2021-06-14 22:20:04 +02:00
|
|
|
// NOTE(unsafe) We got the peripheral singleton, which means that `rcc::init` was called
|
2021-08-02 12:40:01 +02:00
|
|
|
let hclk = crate::rcc::get_freqs().ahb1;
|
2021-06-10 07:38:59 +02:00
|
|
|
let hclk_mhz = hclk.0 / 1_000_000;
|
2021-06-14 22:20:04 +02:00
|
|
|
|
|
|
|
// Set the MDC clock frequency in the range 1MHz - 2.5MHz
|
2021-06-10 07:38:59 +02:00
|
|
|
let clock_range = match hclk_mhz {
|
|
|
|
0..=34 => 2, // Divide by 16
|
|
|
|
35..=59 => 3, // Divide by 26
|
|
|
|
60..=99 => 0, // Divide by 42
|
|
|
|
100..=149 => 1, // Divide by 62
|
|
|
|
150..=249 => 4, // Divide by 102
|
|
|
|
250..=310 => 5, // Divide by 124
|
|
|
|
_ => {
|
|
|
|
panic!("HCLK results in MDC clock > 2.5MHz even for the highest CSR clock divider")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-07 07:30:38 +02:00
|
|
|
let pins = [
|
|
|
|
ref_clk.degrade(),
|
|
|
|
mdio.degrade(),
|
|
|
|
mdc.degrade(),
|
|
|
|
crs.degrade(),
|
|
|
|
rx_d0.degrade(),
|
|
|
|
rx_d1.degrade(),
|
|
|
|
tx_d0.degrade(),
|
|
|
|
tx_d1.degrade(),
|
|
|
|
tx_en.degrade(),
|
|
|
|
];
|
|
|
|
|
2021-07-29 14:08:32 +02:00
|
|
|
let mut this = Self {
|
2021-06-10 07:38:59 +02:00
|
|
|
state,
|
|
|
|
pins,
|
|
|
|
_phy: phy,
|
|
|
|
clock_range,
|
|
|
|
phy_addr,
|
2021-06-11 04:22:34 +02:00
|
|
|
mac_addr,
|
2021-07-29 14:08:32 +02:00
|
|
|
};
|
2021-06-07 07:30:38 +02:00
|
|
|
|
2021-07-29 14:08:32 +02:00
|
|
|
this.state.with(|s| {
|
2021-06-07 07:30:38 +02:00
|
|
|
s.desc_ring.init();
|
|
|
|
|
|
|
|
fence(Ordering::SeqCst);
|
|
|
|
|
2021-08-02 12:40:01 +02:00
|
|
|
let mac = ETH.ethernet_mac();
|
|
|
|
let mtl = ETH.ethernet_mtl();
|
|
|
|
let dma = ETH.ethernet_dma();
|
|
|
|
|
|
|
|
mac.maccr().modify(|w| {
|
|
|
|
w.set_re(true);
|
|
|
|
w.set_te(true);
|
|
|
|
});
|
|
|
|
mtl.mtltx_qomr().modify(|w| w.set_ftq(true));
|
|
|
|
|
|
|
|
dma.dmactx_cr().modify(|w| w.set_st(true));
|
|
|
|
dma.dmacrx_cr().modify(|w| w.set_sr(true));
|
|
|
|
|
|
|
|
// Enable interrupts
|
|
|
|
dma.dmacier().modify(|w| {
|
|
|
|
w.set_nie(true);
|
|
|
|
w.set_rie(true);
|
|
|
|
w.set_tie(true);
|
|
|
|
});
|
2021-06-07 07:30:38 +02:00
|
|
|
});
|
2021-07-29 14:08:32 +02:00
|
|
|
P::phy_reset(&mut this);
|
|
|
|
P::phy_init(&mut this);
|
|
|
|
|
|
|
|
this
|
2021-06-10 07:38:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
unsafe impl<'d, P: PHY, const TX: usize, const RX: usize> StationManagement
|
|
|
|
for Ethernet<'d, P, TX, RX>
|
2021-06-10 07:38:59 +02:00
|
|
|
{
|
|
|
|
fn smi_read(&mut self, reg: u8) -> u16 {
|
|
|
|
// NOTE(unsafe) These registers aren't used in the interrupt and we have `&mut self`
|
|
|
|
unsafe {
|
|
|
|
let mac = ETH.ethernet_mac();
|
|
|
|
|
|
|
|
mac.macmdioar().modify(|w| {
|
|
|
|
w.set_pa(self.phy_addr);
|
|
|
|
w.set_rda(reg);
|
|
|
|
w.set_goc(0b11); // read
|
|
|
|
w.set_cr(self.clock_range);
|
|
|
|
w.set_mb(true);
|
|
|
|
});
|
|
|
|
while mac.macmdioar().read().mb() {}
|
|
|
|
mac.macmdiodr().read().md()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn smi_write(&mut self, reg: u8, val: u16) {
|
|
|
|
// NOTE(unsafe) These registers aren't used in the interrupt and we have `&mut self`
|
|
|
|
unsafe {
|
|
|
|
let mac = ETH.ethernet_mac();
|
|
|
|
|
|
|
|
mac.macmdiodr().write(|w| w.set_md(val));
|
|
|
|
mac.macmdioar().modify(|w| {
|
|
|
|
w.set_pa(self.phy_addr);
|
|
|
|
w.set_rda(reg);
|
|
|
|
w.set_goc(0b01); // write
|
|
|
|
w.set_cr(self.clock_range);
|
|
|
|
w.set_mb(true);
|
|
|
|
});
|
|
|
|
while mac.macmdioar().read().mb() {}
|
|
|
|
}
|
2021-06-07 07:30:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-29 14:08:32 +02:00
|
|
|
impl<'d, P: PHY, const TX: usize, const RX: usize> Device for Ethernet<'d, P, TX, RX> {
|
2021-06-11 04:22:34 +02:00
|
|
|
fn is_transmit_ready(&mut self) -> bool {
|
2021-07-29 14:08:32 +02:00
|
|
|
self.state.with(|s| s.desc_ring.tx.available())
|
2021-06-11 04:22:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn transmit(&mut self, pkt: PacketBuf) {
|
2021-07-29 14:08:32 +02:00
|
|
|
self.state.with(|s| unwrap!(s.desc_ring.tx.transmit(pkt)));
|
2021-06-11 04:22:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn receive(&mut self) -> Option<PacketBuf> {
|
2021-07-29 14:08:32 +02:00
|
|
|
self.state.with(|s| s.desc_ring.rx.pop_packet())
|
2021-06-11 04:22:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn register_waker(&mut self, waker: &Waker) {
|
2021-06-11 04:33:31 +02:00
|
|
|
WAKER.register(waker);
|
2021-06-11 04:22:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn capabilities(&mut self) -> DeviceCapabilities {
|
|
|
|
let mut caps = DeviceCapabilities::default();
|
|
|
|
caps.max_transmission_unit = MTU;
|
|
|
|
caps.max_burst_size = Some(TX.min(RX));
|
|
|
|
caps
|
|
|
|
}
|
|
|
|
|
|
|
|
fn link_state(&mut self) -> LinkState {
|
2021-07-29 14:08:32 +02:00
|
|
|
if P::poll_link(self) {
|
2021-06-11 04:22:34 +02:00
|
|
|
LinkState::Up
|
|
|
|
} else {
|
|
|
|
LinkState::Down
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn ethernet_address(&mut self) -> [u8; 6] {
|
2021-07-29 14:08:32 +02:00
|
|
|
self.mac_addr
|
2021-06-11 04:22:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
impl<'d, P: PHY, const TX: usize, const RX: usize> Drop for Ethernet<'d, P, TX, RX> {
|
2021-06-07 07:30:38 +02:00
|
|
|
fn drop(&mut self) {
|
2021-06-11 04:22:34 +02:00
|
|
|
// NOTE(unsafe) We have `&mut self` and the interrupt doesn't use this registers
|
|
|
|
unsafe {
|
|
|
|
let dma = ETH.ethernet_dma();
|
|
|
|
let mac = ETH.ethernet_mac();
|
|
|
|
let mtl = ETH.ethernet_mtl();
|
|
|
|
|
|
|
|
// Disable the TX DMA and wait for any previous transmissions to be completed
|
|
|
|
dma.dmactx_cr().modify(|w| w.set_st(false));
|
|
|
|
while {
|
|
|
|
let txqueue = mtl.mtltx_qdr().read();
|
|
|
|
txqueue.trcsts() == 0b01 || txqueue.txqsts()
|
|
|
|
} {}
|
|
|
|
|
|
|
|
// Disable MAC transmitter and receiver
|
|
|
|
mac.maccr().modify(|w| {
|
|
|
|
w.set_re(false);
|
|
|
|
w.set_te(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Wait for previous receiver transfers to be completed and then disable the RX DMA
|
|
|
|
while {
|
|
|
|
let rxqueue = mtl.mtlrx_qdr().read();
|
|
|
|
rxqueue.rxqsts() != 0b00 || rxqueue.prxq() != 0
|
|
|
|
} {}
|
|
|
|
dma.dmacrx_cr().modify(|w| w.set_sr(false));
|
|
|
|
}
|
|
|
|
|
2021-06-07 07:30:38 +02:00
|
|
|
for pin in self.pins.iter_mut() {
|
|
|
|
// NOTE(unsafe) Exclusive access to the regs
|
|
|
|
critical_section::with(|_| unsafe {
|
|
|
|
pin.set_as_analog();
|
|
|
|
pin.block()
|
|
|
|
.ospeedr()
|
|
|
|
.modify(|w| w.set_ospeedr(pin.pin() as usize, Ospeedr::LOWSPEED));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
struct Inner<'d, const TX: usize, const RX: usize> {
|
|
|
|
_peri: PhantomData<&'d mut peripherals::ETH>,
|
2021-06-07 07:30:38 +02:00
|
|
|
desc_ring: DescriptorRing<TX, RX>,
|
|
|
|
}
|
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
impl<'d, const TX: usize, const RX: usize> Inner<'d, TX, RX> {
|
|
|
|
pub fn new(_peri: impl Unborrow<Target = peripherals::ETH> + 'd) -> Self {
|
2021-06-07 07:30:38 +02:00
|
|
|
Self {
|
|
|
|
_peri: PhantomData,
|
|
|
|
desc_ring: DescriptorRing::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-29 07:11:26 +02:00
|
|
|
impl<'d, const TX: usize, const RX: usize> PeripheralState for Inner<'d, TX, RX> {
|
2021-06-11 04:33:31 +02:00
|
|
|
type Interrupt = crate::interrupt::ETH;
|
2021-06-07 07:30:38 +02:00
|
|
|
|
|
|
|
fn on_interrupt(&mut self) {
|
|
|
|
unwrap!(self.desc_ring.tx.on_interrupt());
|
|
|
|
self.desc_ring.rx.on_interrupt();
|
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
WAKER.wake();
|
2021-06-07 07:30:38 +02:00
|
|
|
|
|
|
|
// TODO: Check and clear more flags
|
|
|
|
unsafe {
|
|
|
|
let dma = ETH.ethernet_dma();
|
|
|
|
|
|
|
|
dma.dmacsr().modify(|w| {
|
2021-06-11 16:51:51 +02:00
|
|
|
w.set_ti(true);
|
|
|
|
w.set_ri(true);
|
|
|
|
w.set_nis(true);
|
2021-06-07 07:30:38 +02:00
|
|
|
});
|
|
|
|
// Delay two peripheral's clock
|
|
|
|
dma.dmacsr().read();
|
|
|
|
dma.dmacsr().read();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mod sealed {
|
|
|
|
use super::*;
|
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
pub trait RefClkPin: GpioPin {
|
2021-06-07 07:30:38 +02:00
|
|
|
fn configure(&mut self);
|
|
|
|
}
|
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
pub trait MDIOPin: GpioPin {
|
2021-06-07 07:30:38 +02:00
|
|
|
fn configure(&mut self);
|
|
|
|
}
|
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
pub trait MDCPin: GpioPin {
|
2021-06-07 07:30:38 +02:00
|
|
|
fn configure(&mut self);
|
|
|
|
}
|
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
pub trait CRSPin: GpioPin {
|
2021-06-07 07:30:38 +02:00
|
|
|
fn configure(&mut self);
|
|
|
|
}
|
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
pub trait RXD0Pin: GpioPin {
|
2021-06-07 07:30:38 +02:00
|
|
|
fn configure(&mut self);
|
|
|
|
}
|
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
pub trait RXD1Pin: GpioPin {
|
2021-06-07 07:30:38 +02:00
|
|
|
fn configure(&mut self);
|
|
|
|
}
|
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
pub trait TXD0Pin: GpioPin {
|
2021-06-07 07:30:38 +02:00
|
|
|
fn configure(&mut self);
|
|
|
|
}
|
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
pub trait TXD1Pin: GpioPin {
|
2021-06-07 07:30:38 +02:00
|
|
|
fn configure(&mut self);
|
|
|
|
}
|
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
pub trait TXEnPin: GpioPin {
|
2021-06-07 07:30:38 +02:00
|
|
|
fn configure(&mut self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
pub trait RefClkPin: sealed::RefClkPin + 'static {}
|
2021-06-07 07:30:38 +02:00
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
pub trait MDIOPin: sealed::MDIOPin + 'static {}
|
2021-06-07 07:30:38 +02:00
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
pub trait MDCPin: sealed::MDCPin + 'static {}
|
2021-06-07 07:30:38 +02:00
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
pub trait CRSPin: sealed::CRSPin + 'static {}
|
2021-06-07 07:30:38 +02:00
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
pub trait RXD0Pin: sealed::RXD0Pin + 'static {}
|
2021-06-07 07:30:38 +02:00
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
pub trait RXD1Pin: sealed::RXD1Pin + 'static {}
|
2021-06-07 07:30:38 +02:00
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
pub trait TXD0Pin: sealed::TXD0Pin + 'static {}
|
2021-06-07 07:30:38 +02:00
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
pub trait TXD1Pin: sealed::TXD1Pin + 'static {}
|
2021-06-07 07:30:38 +02:00
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
pub trait TXEnPin: sealed::TXEnPin + 'static {}
|
2021-06-07 07:30:38 +02:00
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
static WAKER: AtomicWaker = AtomicWaker::new();
|
2021-06-07 07:30:38 +02:00
|
|
|
|
|
|
|
macro_rules! impl_pin {
|
2021-06-11 04:33:31 +02:00
|
|
|
($pin:ident, $signal:ident, $af:expr) => {
|
|
|
|
impl sealed::$signal for peripherals::$pin {
|
2021-06-07 07:30:38 +02:00
|
|
|
fn configure(&mut self) {
|
|
|
|
// NOTE(unsafe) Exclusive access to the registers
|
|
|
|
critical_section::with(|_| unsafe {
|
|
|
|
self.set_as_af($af);
|
|
|
|
self.block()
|
|
|
|
.ospeedr()
|
|
|
|
.modify(|w| w.set_ospeedr(self.pin() as usize, Ospeedr::VERYHIGHSPEED));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-11 04:33:31 +02:00
|
|
|
impl $signal for peripherals::$pin {}
|
2021-06-07 07:30:38 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
crate::pac::peripheral_pins!(
|
2021-06-11 06:43:28 +02:00
|
|
|
($inst:ident, eth, ETH, $pin:ident, REF_CLK) => {
|
|
|
|
impl_pin!($pin, RefClkPin, 11);
|
2021-06-07 07:30:38 +02:00
|
|
|
};
|
2021-06-11 06:43:28 +02:00
|
|
|
($inst:ident, eth, ETH, $pin:ident, MDIO, $af:expr) => {
|
2021-06-11 04:33:31 +02:00
|
|
|
impl_pin!($pin, MDIOPin, $af);
|
2021-06-07 07:30:38 +02:00
|
|
|
};
|
2021-06-11 06:43:28 +02:00
|
|
|
($inst:ident, eth, ETH, $pin:ident, MDC, $af:expr) => {
|
2021-06-11 04:33:31 +02:00
|
|
|
impl_pin!($pin, MDCPin, $af);
|
2021-06-07 07:30:38 +02:00
|
|
|
};
|
2021-06-11 06:43:28 +02:00
|
|
|
($inst:ident, eth, ETH, $pin:ident, CRS_DV, $af:expr) => {
|
2021-06-11 04:33:31 +02:00
|
|
|
impl_pin!($pin, CRSPin, $af);
|
2021-06-07 07:30:38 +02:00
|
|
|
};
|
2021-06-11 06:43:28 +02:00
|
|
|
($inst:ident, eth, ETH, $pin:ident, RXD0, $af:expr) => {
|
2021-06-11 04:33:31 +02:00
|
|
|
impl_pin!($pin, RXD0Pin, $af);
|
2021-06-07 07:30:38 +02:00
|
|
|
};
|
2021-06-11 06:43:28 +02:00
|
|
|
($inst:ident, eth, ETH, $pin:ident, RXD1, $af:expr) => {
|
2021-06-11 04:33:31 +02:00
|
|
|
impl_pin!($pin, RXD1Pin, $af);
|
2021-06-07 07:30:38 +02:00
|
|
|
};
|
2021-06-11 06:43:28 +02:00
|
|
|
($inst:ident, eth, ETH, $pin:ident, TXD0, $af:expr) => {
|
2021-06-11 04:33:31 +02:00
|
|
|
impl_pin!($pin, TXD0Pin, $af);
|
2021-06-07 07:30:38 +02:00
|
|
|
};
|
2021-06-11 06:43:28 +02:00
|
|
|
($inst:ident, eth, ETH, $pin:ident, TXD1, $af:expr) => {
|
2021-06-11 04:33:31 +02:00
|
|
|
impl_pin!($pin, TXD1Pin, $af);
|
2021-06-07 07:30:38 +02:00
|
|
|
};
|
2021-06-11 06:43:28 +02:00
|
|
|
($inst:ident, eth, ETH, $pin:ident, TX_EN, $af:expr) => {
|
2021-06-11 04:33:31 +02:00
|
|
|
impl_pin!($pin, TXEnPin, $af);
|
2021-06-07 07:30:38 +02:00
|
|
|
};
|
|
|
|
);
|