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@0:a447869e1046, 2014-09-30 (annotated)
- Committer:
- loopsva
- Date:
- Tue Sep 30 21:48:34 2014 +0000
- Revision:
- 0:a447869e1046
- Child:
- 1:cbd7e77b6e38
Crude driver for obtaining the K64F's Ethernet link status
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
loopsva | 0:a447869e1046 | 1 | #include "k64f_EthLink.h" |
loopsva | 0:a447869e1046 | 2 | #include "rtos.h" |
loopsva | 0:a447869e1046 | 3 | |
loopsva | 0:a447869e1046 | 4 | //--------------------------------------------------------------------------------------------------------------------------------------// |
loopsva | 0:a447869e1046 | 5 | // Constructor |
loopsva | 0:a447869e1046 | 6 | |
loopsva | 0:a447869e1046 | 7 | k64fEthLink::k64fEthLink() { |
loopsva | 0:a447869e1046 | 8 | } |
loopsva | 0:a447869e1046 | 9 | |
loopsva | 0:a447869e1046 | 10 | //--------------------------------------------------------------------------------------------------------------------------------------// |
loopsva | 0:a447869e1046 | 11 | // Get Ethernet link status on the K64F |
loopsva | 0:a447869e1046 | 12 | |
loopsva | 0:a447869e1046 | 13 | int k64fEthLink::GetELink() { |
loopsva | 0:a447869e1046 | 14 | int mdio_timer = 0; |
loopsva | 0:a447869e1046 | 15 | uint32_t k64f_mdio_reg = ENET_EIR; |
loopsva | 0:a447869e1046 | 16 | |
loopsva | 0:a447869e1046 | 17 | //wait for MDIO interface to be ready |
loopsva | 0:a447869e1046 | 18 | do { |
loopsva | 0:a447869e1046 | 19 | k64f_mdio_reg = ENET_EIR; |
loopsva | 0:a447869e1046 | 20 | Thread::wait(1); //release RTOS to do other functions |
loopsva | 0:a447869e1046 | 21 | mdio_timer++; |
loopsva | 0:a447869e1046 | 22 | } while(((k64f_mdio_reg & MDIO_MII_READY_BIT) == 0) && (mdio_timer < 200)); |
loopsva | 0:a447869e1046 | 23 | if(mdio_timer > 198) { //average is about 122mS |
loopsva | 0:a447869e1046 | 24 | return(MDIO_TIMEOUT); //timeout error |
loopsva | 0:a447869e1046 | 25 | } |
loopsva | 0:a447869e1046 | 26 | |
loopsva | 0:a447869e1046 | 27 | //get Basic Status Register |
loopsva | 0:a447869e1046 | 28 | ENET_MMFR = MDIO_GET_LINK_REG; |
loopsva | 0:a447869e1046 | 29 | wait_us(35); //20 is absolute minimum!! |
loopsva | 0:a447869e1046 | 30 | k64f_mdio_reg = ENET_MMFR; //get the phy result |
loopsva | 0:a447869e1046 | 31 | if(k64f_mdio_reg & MDIO_MII_LINK_BITS) return(PHY_UP); |
loopsva | 0:a447869e1046 | 32 | return(PHY_DOWN); |
loopsva | 0:a447869e1046 | 33 | } |
loopsva | 0:a447869e1046 | 34 |