diff options
| author | xoviat <[email protected]> | 2023-07-15 09:32:36 -0500 |
|---|---|---|
| committer | xoviat <[email protected]> | 2023-07-15 09:32:36 -0500 |
| commit | 48b37aa2bf83b8fccb293fcda7f51149a4ec1a24 (patch) | |
| tree | e0f2491897f7eeca1e3ed078ee0b451c0a0daa22 /embassy-stm32/src/eth/v2 | |
| parent | 3bae53306683a57020ba751afaf631ec169deeed (diff) | |
stm32/eth: refactor genericsmi
Diffstat (limited to 'embassy-stm32/src/eth/v2')
| -rw-r--r-- | embassy-stm32/src/eth/v2/mod.rs | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs index 600e1d3bc..bb681c42b 100644 --- a/embassy-stm32/src/eth/v2/mod.rs +++ b/embassy-stm32/src/eth/v2/mod.rs | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | mod descriptors; | 1 | mod descriptors; |
| 2 | 2 | ||
| 3 | use core::marker::PhantomData; | ||
| 3 | use core::sync::atomic::{fence, Ordering}; | 4 | use core::sync::atomic::{fence, Ordering}; |
| 4 | 5 | ||
| 5 | use embassy_hal_common::{into_ref, PeripheralRef}; | 6 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| @@ -40,9 +41,8 @@ pub struct Ethernet<'d, T: Instance, P: PHY> { | |||
| 40 | pub(crate) tx: TDesRing<'d>, | 41 | pub(crate) tx: TDesRing<'d>, |
| 41 | pub(crate) rx: RDesRing<'d>, | 42 | pub(crate) rx: RDesRing<'d>, |
| 42 | pins: [PeripheralRef<'d, AnyPin>; 9], | 43 | pins: [PeripheralRef<'d, AnyPin>; 9], |
| 43 | _phy: P, | 44 | pub(crate) phy: P, |
| 44 | clock_range: u8, | 45 | pub(crate) station_management: EthernetStationManagement<T>, |
| 45 | phy_addr: u8, | ||
| 46 | pub(crate) mac_addr: [u8; 6], | 46 | pub(crate) mac_addr: [u8; 6], |
| 47 | } | 47 | } |
| 48 | 48 | ||
| @@ -201,9 +201,12 @@ impl<'d, T: Instance, P: PHY> Ethernet<'d, T, P> { | |||
| 201 | tx: TDesRing::new(&mut queue.tx_desc, &mut queue.tx_buf), | 201 | tx: TDesRing::new(&mut queue.tx_desc, &mut queue.tx_buf), |
| 202 | rx: RDesRing::new(&mut queue.rx_desc, &mut queue.rx_buf), | 202 | rx: RDesRing::new(&mut queue.rx_desc, &mut queue.rx_buf), |
| 203 | pins, | 203 | pins, |
| 204 | _phy: phy, | 204 | phy: phy, |
| 205 | clock_range, | 205 | station_management: EthernetStationManagement { |
| 206 | phy_addr, | 206 | peri: PhantomData, |
| 207 | clock_range: clock_range, | ||
| 208 | phy_addr: phy_addr, | ||
| 209 | }, | ||
| 207 | mac_addr, | 210 | mac_addr, |
| 208 | }; | 211 | }; |
| 209 | 212 | ||
| @@ -229,8 +232,8 @@ impl<'d, T: Instance, P: PHY> Ethernet<'d, T, P> { | |||
| 229 | w.set_tie(true); | 232 | w.set_tie(true); |
| 230 | }); | 233 | }); |
| 231 | 234 | ||
| 232 | P::phy_reset(&mut this); | 235 | this.phy.phy_reset(&mut this.station_management); |
| 233 | P::phy_init(&mut this); | 236 | this.phy.phy_init(&mut this.station_management); |
| 234 | 237 | ||
| 235 | interrupt::ETH.unpend(); | 238 | interrupt::ETH.unpend(); |
| 236 | unsafe { interrupt::ETH.enable() }; | 239 | unsafe { interrupt::ETH.enable() }; |
| @@ -239,7 +242,13 @@ impl<'d, T: Instance, P: PHY> Ethernet<'d, T, P> { | |||
| 239 | } | 242 | } |
| 240 | } | 243 | } |
| 241 | 244 | ||
| 242 | unsafe impl<'d, T: Instance, P: PHY> StationManagement for Ethernet<'d, T, P> { | 245 | pub struct EthernetStationManagement<T: Instance> { |
| 246 | peri: PhantomData<T>, | ||
| 247 | clock_range: u8, | ||
| 248 | phy_addr: u8, | ||
| 249 | } | ||
| 250 | |||
| 251 | unsafe impl<T: Instance> StationManagement for EthernetStationManagement<T> { | ||
| 243 | fn smi_read(&mut self, reg: u8) -> u16 { | 252 | fn smi_read(&mut self, reg: u8) -> u16 { |
| 244 | let mac = ETH.ethernet_mac(); | 253 | let mac = ETH.ethernet_mac(); |
| 245 | 254 | ||
