Skip to main content

ch32_hal/eth/
mod.rs

1//! Ethernet (ETH)
2#![macro_use]
3
4#[cfg_attr(eth_10m, path = "v10m/mod.rs")]
5#[cfg_attr(any(eth_v1, emac_v1), path = "v1/mod.rs")]
6mod _version;
7
8#[cfg(eth)]
9pub mod generic_smi;
10
11pub use self::_version::*;
12
13#[cfg(eth)]
14#[allow(unused)]
15const MTU: usize = 1514;
16
17/// Station Management Interface (SMI) on an ethernet PHY
18///
19/// # Safety
20///
21/// The methods cannot move out of self
22#[cfg(eth)]
23pub unsafe trait StationManagement {
24    /// Read a register over SMI.
25    fn smi_read(&mut self, phy_addr: u8, reg: u8) -> u16;
26    /// Write a register over SMI.
27    fn smi_write(&mut self, phy_addr: u8, reg: u8, val: u16);
28}
29
30/// Traits for an Ethernet PHY
31///
32/// # Safety
33///
34/// The methods cannot move S
35#[cfg(eth)]
36pub unsafe trait PHY {
37    /// Reset PHY and wait for it to come out of reset.
38    fn phy_reset<S: StationManagement>(&mut self, sm: &mut S);
39    /// Read PHY registers to check if link is established
40    fn link_up<S: StationManagement>(&mut self, sm: &mut S) -> bool;
41}
42
43#[cfg(eth)]
44trait SealedInstance {
45    fn regs() -> crate::pac::eth::Eth;
46}
47
48/// Ethernet instance.
49#[allow(private_bounds)]
50#[cfg(eth)]
51pub trait Instance: SealedInstance + Send + 'static {}
52
53#[cfg(eth)]
54impl SealedInstance for crate::peripherals::ETH {
55    fn regs() -> crate::pac::eth::Eth {
56        crate::pac::ETH
57    }
58}
59#[cfg(eth)]
60impl Instance for crate::peripherals::ETH {}