Ethernet link status for the K64F
Dependents: JRO_CR2 K64F_EthLink_HelloWorld frdm_test JRO_DDSv2
Simple K64F technique to determine if the Ethernet PHY link is up or down. The routine utilizes the Ethernet MII interface to gain access to the Ethernet PHY which contains the actual link status.
I wrote this because the mbed Ethernet function does not recognize its own "int link();" function with the K64F.
k64f_EthLink.cpp
- Committer:
- loopsva
- Date:
- 2014-11-07
- Revision:
- 3:fbd2336e1193
- Parent:
- 2:59166b94dfd0
- Child:
- 4:9d2a4dc03170
File content as of revision 3:fbd2336e1193:
#if defined(TARGET_K64F) #include "k64f_EthLink.h" //--------------------------------------------------------------------------------------------------------------------------------------// // Constructor k64fEthLink::k64fEthLink() { } //--------------------------------------------------------------------------------------------------------------------------------------// // Get Ethernet link status on the K64F int k64fEthLink::GetELink() { int mdio_timer = 0; uint32_t k64f_mdio_reg = ENET_EIR; //wait for MDIO interface to be ready do { k64f_mdio_reg = ENET_EIR; #ifdef RTOS_H Thread::wait(1); #else wait_ms(1); #endif mdio_timer++; } while(((k64f_mdio_reg & MDIO_MII_READY_BIT) == 0) && (mdio_timer < 300)); if(mdio_timer > 298) { //average is about 122mS return(MDIO_TIMEOUT); //timeout error } //get Basic Status Register ENET_MMFR = MDIO_GET_LINK_REG; wait_us(35); //20 is absolute minimum!! k64f_mdio_reg = ENET_MMFR; //get the phy result if(k64f_mdio_reg & MDIO_MII_LINK_BITS) return(PHY_UP); return(PHY_DOWN); } #endif