【修改】PHY 检测相关处理

This commit is contained in:
SummerGift 2019-05-15 15:36:46 +08:00
parent 0dae909f66
commit 6309492ec5
1 changed files with 24 additions and 21 deletions

View File

@ -431,13 +431,15 @@ static void phy_monitor_thread_entry(void *parameter)
uint8_t phy_addr = 0xFF; uint8_t phy_addr = 0xFF;
uint8_t phy_speed_new = 0; uint8_t phy_speed_new = 0;
rt_uint32_t status = 0; rt_uint32_t status = 0;
uint8_t detected_count = 0;
while(phy_addr == 0xFF)
{
/* phy search */ /* phy search */
rt_uint32_t i, temp; rt_uint32_t i, temp;
for (i = 0; i <= 0x1F; i++) for (i = 0; i <= 0x1F; i++)
{ {
EthHandle.Init.PhyAddress = i; EthHandle.Init.PhyAddress = i;
HAL_ETH_ReadPHYRegister(&EthHandle, PHY_ID1_REG, (uint32_t *)&temp); HAL_ETH_ReadPHYRegister(&EthHandle, PHY_ID1_REG, (uint32_t *)&temp);
if (temp != 0xFFFF && temp != 0x00) if (temp != 0xFFFF && temp != 0x00)
@ -447,16 +449,17 @@ static void phy_monitor_thread_entry(void *parameter)
} }
} }
if (phy_addr == 0xFF) detected_count++;
rt_thread_mdelay(1000);
if (detected_count > 10)
{ {
LOG_E("phy not probe!"); LOG_E("No PHY device was detected, please check hardware!");
return;
} }
else
{
LOG_D("found a phy, address:0x%02X", phy_addr);
} }
LOG_D("Found a phy, address:0x%02X", phy_addr);
/* RESET PHY */ /* RESET PHY */
LOG_D("RESET PHY!"); LOG_D("RESET PHY!");
HAL_ETH_WritePHYRegister(&EthHandle, PHY_BASIC_CONTROL_REG, PHY_RESET_MASK); HAL_ETH_WritePHYRegister(&EthHandle, PHY_BASIC_CONTROL_REG, PHY_RESET_MASK);