MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_genphy_update_link

Function rt_genphy_update_link

components/drivers/phy/general.c:162–202  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

160}
161
162int rt_genphy_update_link(struct rt_phy_device *phydev)
163{
164 unsigned int mii_reg;
165
166 mii_reg = rt_phy_read(phydev, RT_MDIO_DEVAD_NONE, RT_MII_BMSR);
167
168 if (phydev->link && mii_reg & RT_BMSR_LSTATUS)
169 return 0;
170
171 if ((phydev->autoneg == AUTONEG_ENABLE) &&
172 !(mii_reg & RT_BMSR_ANEGCOMPLETE))
173 {
174 int i = 0;
175 rt_kprintf("Waiting for PHY auto negotiation to complete");
176 while (!(mii_reg & RT_BMSR_ANEGCOMPLETE))
177 {
178
179 if (i > (RT_PHY_ANEG_TIMEOUT))
180 {
181 LOG_E(" TIMEOUT !\n");
182 phydev->link = 0;
183 return -ETIMEDOUT;
184 }
185
186 mii_reg = rt_phy_read(phydev, RT_MDIO_DEVAD_NONE, RT_MII_BMSR);
187
188 rt_thread_delay(100);
189 }
190 LOG_D(" done\n");
191 phydev->link = 1;
192 } else {
193 mii_reg = rt_phy_read(phydev, RT_MDIO_DEVAD_NONE, RT_MII_BMSR);
194
195 if (mii_reg & RT_BMSR_LSTATUS)
196 phydev->link = 1;
197 else
198 phydev->link = 0;
199 }
200
201 return 0;
202}
203
204static void __genphy_auto_neg(struct rt_phy_device *phydev,int mii_reg)
205{

Callers 1

rt_genphy_startupFunction · 0.85

Calls 3

rt_kprintfFunction · 0.85
rt_thread_delayFunction · 0.85
rt_phy_readFunction · 0.70

Tested by

no test coverage detected