mirror of
https://github.com/embassy-rs/embassy.git
synced 2025-09-29 21:31:08 +00:00
Option to detect Ethernet PHY address automatically
This commit is contained in:
parent
27fb1f4dd0
commit
5885369f47
@ -51,6 +51,8 @@ pub struct GenericSMI {
|
|||||||
|
|
||||||
impl GenericSMI {
|
impl GenericSMI {
|
||||||
/// Construct the PHY. It assumes the address `phy_addr` in the SMI communication
|
/// Construct the PHY. It assumes the address `phy_addr` in the SMI communication
|
||||||
|
///
|
||||||
|
/// Set `phy_addr` to `0xFF` for automatic detection
|
||||||
pub fn new(phy_addr: u8) -> Self {
|
pub fn new(phy_addr: u8) -> Self {
|
||||||
Self {
|
Self {
|
||||||
phy_addr,
|
phy_addr,
|
||||||
@ -62,8 +64,24 @@ impl GenericSMI {
|
|||||||
|
|
||||||
unsafe impl PHY for GenericSMI {
|
unsafe impl PHY for GenericSMI {
|
||||||
fn phy_reset<S: StationManagement>(&mut self, sm: &mut S) {
|
fn phy_reset<S: StationManagement>(&mut self, sm: &mut S) {
|
||||||
sm.smi_write(self.phy_addr, PHY_REG_BCR, PHY_REG_BCR_RESET);
|
// Detect SMI address
|
||||||
while sm.smi_read(self.phy_addr, PHY_REG_BCR) & PHY_REG_BCR_RESET == PHY_REG_BCR_RESET {}
|
if self.phy_addr == 0xFF {
|
||||||
|
for addr in 0..32 {
|
||||||
|
sm.smi_write(addr, PHY_REG_BCR, PHY_REG_BCR_RESET);
|
||||||
|
for _ in 0..10 {
|
||||||
|
if sm.smi_read(addr, PHY_REG_BCR) & PHY_REG_BCR_RESET != PHY_REG_BCR_RESET {
|
||||||
|
trace!("Found ETH PHY on address {}", addr);
|
||||||
|
self.phy_addr = addr;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cortex_m::asm::delay(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic!("PHY did not respond");
|
||||||
|
} else {
|
||||||
|
sm.smi_write(self.phy_addr, PHY_REG_BCR, PHY_REG_BCR_RESET);
|
||||||
|
while sm.smi_read(self.phy_addr, PHY_REG_BCR) & PHY_REG_BCR_RESET == PHY_REG_BCR_RESET {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn phy_init<S: StationManagement>(&mut self, sm: &mut S) {
|
fn phy_init<S: StationManagement>(&mut self, sm: &mut S) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user