Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12693 Discussions

dynamically detect ethernet link

Altera_Forum
Honored Contributor II
953 Views

Hi everyone, 

 

I'm using the nichestack TCP/IP stack with µC/OS. 

 

I'm having trouble finding out how to make the ethernet link work when the software did not boot with ethernet present. If the software boots with an ethernet cable plugged in, everything works fine. If it boots without, and I plug a cable in later, the PHY (Marvell 88E1111) detects the cable (LEDs go on), but nothing else does. 

 

Do I need to call some function to detect that the link is up ?
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
291 Views

 

There are two steps to accomplish what you want. 

 

1. You need a program structure that can re-initialize the tcp/ip stack when necessary. 

 

2. You need to be able to detect "when it is necessary". 

 

 

For the first part - the Altera examples use the following structure: 

 

alt_iniche_init(); 

netmain();  

 

/* Wait for the network stack to be ready before proceeding.  

* iniche_net_ready indicates that TCP/IP stack is ready, and IP address is obtained. 

*/ 

while (!iniche_net_ready) 

TK_SLEEP(1); 

 

This code happens once during the initial task processing, and doesn't happen again. You can instead put this code in a separate task that can re-try the two function calls, and eliminates the sleep on iniche_net_ready. 

 

With nichestack 3.1 found in the 9.x tools, netmain() is where all the action is, including talking to the PHY device to autonegotiate 10/100/1000 megabits and full or half duplex.  

 

I don't know the specific way to query the PHY chip to see if a cable has been attached, for example, but you will find the existing PHY communication code by tracing netmain() into the Altera IP Device Drivers selected by SOPC builder for the PHY circuit in your system. 

 

An alternative is to simply call netmain() from time to time and see if iniche_net_ready goes true after a suitable time delay. Again, the main part of the time delay will be autonegotiation if no cable is attached, because the current code does several retries before giving up, and if you have DHCP enabled, there might be a delay there too. 

 

Hope this gives you some pointers. 

Mike 

 

0 Kudos
Reply