Provides a real-time Ethernet link status for the K64F, since the K64F lacks such a function.
Dependencies: EthernetInterface k64f_EthLink mbed-rtos mbed
Fork of K64F_EthLink_HelloWorld by
Demo program for k64f_EthLink library.
IMPORTANT NOTE: The latest mbed builds (mbed 120, mbed-rtos 115, EthernetInterface 54) broke a few things in the K64F, including the k64f_EthLink - generates MDIO Timeout errors.
I recommend staying with the following mbed library versions until issues with the K64F are resolved.
mbed = 119 mbed-rtos = 111 EthernetInterface = 52
Diff: main.cpp
- Revision:
- 0:66507f292910
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Sep 30 21:41:06 2014 +0000 @@ -0,0 +1,44 @@ +#include "mbed.h" +#include "EthernetInterface.h" +#include "k64f_EthLink.h" + +EthernetInterface eth; +k64fEthLink link; +Serial pc(USBTX, USBRX); + +//--------------------------------------------------------------------------------------------------------------------------------------// +// Check for a valid Ethernet Link, print ONLY on status change and keep count of link "downs" + +bool EthPhyUpT = false; +int EthUpDownCnt = 0; + +int TestEthLink() { + int EthLinkStat = link.GetELink(); + if((!(EthLinkStat)) && (EthPhyUpT == false)) { + pc.printf("Eth Link UP\r\n"); + EthPhyUpT = true; + } else if(((EthLinkStat)) && (EthPhyUpT == true)){ + EthUpDownCnt++; + pc.printf("Eth Link DOWN, count: %d\r\n", EthUpDownCnt); + EthPhyUpT = false; + } + if(EthLinkStat == MDIO_TIMEOUT) return(MDIO_TIMEOUT); + if(EthPhyUpT == true) return(PHY_UP); + return(PHY_DOWN); +} + +//--------------------------------------------------------------------------------------------------------------------------------------// + +int main() { + pc.baud(230400); + pc.printf("\r\n\r\nBasic Ethernet Link Up / Down test for K64F\r\n"); + int EthInitStatus = eth.init(); + + /* Finish up initialization here!!! */ + + while(1) { + Thread::wait(500); + int i = TestEthLink(); + if(i == MDIO_TIMEOUT) pc.printf("MDIO Timeout!!!\r\n"); + } +}