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@3:fbd2336e1193, 2014-11-07 (annotated)
- Committer:
- loopsva
- Date:
- Fri Nov 07 22:05:00 2014 +0000
- Revision:
- 3:fbd2336e1193
- Parent:
- 2:59166b94dfd0
- Child:
- 4:9d2a4dc03170
Minor change to #if directive
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
loopsva | 3:fbd2336e1193 | 1 | #if defined(TARGET_K64F) |
loopsva | 0:a447869e1046 | 2 | #include "k64f_EthLink.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 | 2:59166b94dfd0 | 20 | #ifdef RTOS_H |
loopsva | 2:59166b94dfd0 | 21 | Thread::wait(1); |
loopsva | 2:59166b94dfd0 | 22 | #else |
loopsva | 2:59166b94dfd0 | 23 | wait_ms(1); |
loopsva | 2:59166b94dfd0 | 24 | #endif |
loopsva | 0:a447869e1046 | 25 | mdio_timer++; |
loopsva | 1:cbd7e77b6e38 | 26 | } while(((k64f_mdio_reg & MDIO_MII_READY_BIT) == 0) && (mdio_timer < 300)); |
loopsva | 1:cbd7e77b6e38 | 27 | if(mdio_timer > 298) { //average is about 122mS |
loopsva | 0:a447869e1046 | 28 | return(MDIO_TIMEOUT); //timeout error |
loopsva | 0:a447869e1046 | 29 | } |
loopsva | 0:a447869e1046 | 30 | |
loopsva | 0:a447869e1046 | 31 | //get Basic Status Register |
loopsva | 0:a447869e1046 | 32 | ENET_MMFR = MDIO_GET_LINK_REG; |
loopsva | 0:a447869e1046 | 33 | wait_us(35); //20 is absolute minimum!! |
loopsva | 0:a447869e1046 | 34 | k64f_mdio_reg = ENET_MMFR; //get the phy result |
loopsva | 0:a447869e1046 | 35 | if(k64f_mdio_reg & MDIO_MII_LINK_BITS) return(PHY_UP); |
loopsva | 0:a447869e1046 | 36 | return(PHY_DOWN); |
loopsva | 0:a447869e1046 | 37 | } |
loopsva | 2:59166b94dfd0 | 38 | #endif |
loopsva | 0:a447869e1046 | 39 | |
loopsva | 2:59166b94dfd0 | 40 | |
loopsva | 3:fbd2336e1193 | 41 |