diff options
Diffstat (limited to 'embassy-stm32/src/eth/mod.rs')
| -rw-r--r-- | embassy-stm32/src/eth/mod.rs | 29 |
1 files changed, 8 insertions, 21 deletions
diff --git a/embassy-stm32/src/eth/mod.rs b/embassy-stm32/src/eth/mod.rs index 10b3a0517..c8bce0e8a 100644 --- a/embassy-stm32/src/eth/mod.rs +++ b/embassy-stm32/src/eth/mod.rs | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #[cfg_attr(eth_v2, path = "v2/mod.rs")] | 5 | #[cfg_attr(eth_v2, path = "v2/mod.rs")] |
| 6 | mod _version; | 6 | mod _version; |
| 7 | mod generic_phy; | 7 | mod generic_phy; |
| 8 | mod sma; | ||
| 8 | 9 | ||
| 9 | use core::mem::MaybeUninit; | 10 | use core::mem::MaybeUninit; |
| 10 | use core::task::Context; | 11 | use core::task::Context; |
| @@ -15,6 +16,7 @@ use embassy_sync::waitqueue::AtomicWaker; | |||
| 15 | 16 | ||
| 16 | pub use self::_version::{InterruptHandler, *}; | 17 | pub use self::_version::{InterruptHandler, *}; |
| 17 | pub use self::generic_phy::*; | 18 | pub use self::generic_phy::*; |
| 19 | pub use self::sma::{Sma, StationManagement}; | ||
| 18 | use crate::rcc::RccPeripheral; | 20 | use crate::rcc::RccPeripheral; |
| 19 | 21 | ||
| 20 | #[allow(unused)] | 22 | #[allow(unused)] |
| @@ -109,7 +111,7 @@ impl<'d, T: Instance, P: Phy> embassy_net_driver::Driver for Ethernet<'d, T, P> | |||
| 109 | } | 111 | } |
| 110 | 112 | ||
| 111 | fn link_state(&mut self, cx: &mut Context) -> LinkState { | 113 | fn link_state(&mut self, cx: &mut Context) -> LinkState { |
| 112 | if self.phy.poll_link(&mut self.station_management, cx) { | 114 | if self.phy.poll_link(cx) { |
| 113 | LinkState::Up | 115 | LinkState::Up |
| 114 | } else { | 116 | } else { |
| 115 | LinkState::Down | 117 | LinkState::Down |
| @@ -157,32 +159,17 @@ impl<'a, 'd> embassy_net_driver::TxToken for TxToken<'a, 'd> { | |||
| 157 | } | 159 | } |
| 158 | } | 160 | } |
| 159 | 161 | ||
| 160 | /// Station Management Interface (SMI) on an ethernet PHY | ||
| 161 | pub trait StationManagement { | ||
| 162 | /// Read a register over SMI. | ||
| 163 | fn smi_read(&mut self, phy_addr: u8, reg: u8) -> u16; | ||
| 164 | /// Write a register over SMI. | ||
| 165 | fn smi_write(&mut self, phy_addr: u8, reg: u8, val: u16); | ||
| 166 | } | ||
| 167 | |||
| 168 | /// Trait for an Ethernet PHY | 162 | /// Trait for an Ethernet PHY |
| 169 | pub trait Phy { | 163 | pub trait Phy { |
| 170 | /// Reset PHY and wait for it to come out of reset. | 164 | /// Reset PHY and wait for it to come out of reset. |
| 171 | fn phy_reset<S: StationManagement>(&mut self, sm: &mut S); | 165 | fn phy_reset(&mut self); |
| 172 | /// PHY initialisation. | 166 | /// PHY initialisation. |
| 173 | fn phy_init<S: StationManagement>(&mut self, sm: &mut S); | 167 | fn phy_init(&mut self); |
| 174 | /// Poll link to see if it is up and FD with 100Mbps | 168 | /// Poll link to see if it is up and FD with 100Mbps |
| 175 | fn poll_link<S: StationManagement>(&mut self, sm: &mut S, cx: &mut Context) -> bool; | 169 | fn poll_link(&mut self, cx: &mut Context) -> bool; |
| 176 | } | 170 | } |
| 177 | 171 | ||
| 178 | impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { | 172 | impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { |
| 179 | /// Directly expose the SMI interface used by the Ethernet driver. | ||
| 180 | /// | ||
| 181 | /// This can be used to for example configure special PHY registers for compliance testing. | ||
| 182 | pub fn station_management(&mut self) -> &mut impl StationManagement { | ||
| 183 | &mut self.station_management | ||
| 184 | } | ||
| 185 | |||
| 186 | /// Access the user-supplied `Phy`. | 173 | /// Access the user-supplied `Phy`. |
| 187 | pub fn phy(&self) -> &P { | 174 | pub fn phy(&self) -> &P { |
| 188 | &self.phy | 175 | &self.phy |
| @@ -212,8 +199,8 @@ impl Instance for crate::peripherals::ETH {} | |||
| 212 | pin_trait!(RXClkPin, Instance, @A); | 199 | pin_trait!(RXClkPin, Instance, @A); |
| 213 | pin_trait!(TXClkPin, Instance, @A); | 200 | pin_trait!(TXClkPin, Instance, @A); |
| 214 | pin_trait!(RefClkPin, Instance, @A); | 201 | pin_trait!(RefClkPin, Instance, @A); |
| 215 | pin_trait!(MDIOPin, Instance, @A); | 202 | pin_trait!(MDIOPin, sma::Instance, @A); |
| 216 | pin_trait!(MDCPin, Instance, @A); | 203 | pin_trait!(MDCPin, sma::Instance, @A); |
| 217 | pin_trait!(RXDVPin, Instance, @A); | 204 | pin_trait!(RXDVPin, Instance, @A); |
| 218 | pin_trait!(CRSPin, Instance, @A); | 205 | pin_trait!(CRSPin, Instance, @A); |
| 219 | pin_trait!(RXD0Pin, Instance, @A); | 206 | pin_trait!(RXD0Pin, Instance, @A); |
