Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 17 Next »

Subscribe / Unsubscribe to link state changes

The Micriµm TCP/IP stack offers two API functions : NetIF_LinkStateSubscribe()NetIF_LinkStateUnsubscribe(), allowing the customer application to implement a callback function that will be called when a link state change occurs.

Getting the Current Link State for an Interface

µC/TCP-IP provides two mechanisms for obtaining interface link state.

  1. A function which reads a global variable that is periodically updated.
  2. A function which reads the current link state from the hardware.

Method 1 provides the fastest mechanism to obtain link state since it does not require communication with the physical layer device. For most applications, this mechanism is suitable and if necessary, the polling rate can be increased by calling NetIF_CfgPhyLinkPeriod(). In order to utilize Method 1, the application may call NetIF_LinkStateGet() which returns NET_IF_LINK_UP or NET_IF_LINK_DOWN.

The accuracy of Method 1 can be improved by using a physical layer device and driver combination that supports link state change interrupts. In this circumstance, the value of the global variable containing the link state is updated immediately following a link state change. Therefore, the polling rate can be reduced further if desired and a call to NetIF_LinkStateGet() will return the actual link state.

Method 2 requires the application to call NetIF_IO_Ctrl() with the option parameter set to either NET_IF_IO_CTRL_LINK_STATE_GET or NET_IF_IO_CTRL_LINK_STATE_GET_INFO.

  • If the application specifies NET_IF_IO_CTRL_LINK_STATE_GET, then NET_IF_LINK_UP or NET_IF_LINK_DOWN will be returned.
  • Alternatively, if the application specifies NET_IF_IO_CTRL_LINK_STATE_GET_INFO, the link state details such as speed and duplex will be returned.

The advantage to Method 2 is that the link state returned is the actual link state as reported by the hardware at the time of the function call. However, the overhead of communicating with the physical layer device may be high and therefore some cycles may be wasted waiting for the result since the connection bus between the CPU and the physical layer device is often only a couple of MHz.

Calling NetIF_IO_Ctrl() will poll the hardware for the current link state. Alternatively, NetIF_LinkStateGet() gets the approximate link state by reading the interface link state flag. Polling the Ethernet hardware for link state takes significantly longer due to the speed and latency of the MII bus. Consequently, it may not be desirable to poll the hardware in a tight loop. Reading the interface flag is fast, but the flag is only periodically updated by the Net IF every 250mS (default) when using the generic Ethernet PHY driver. PHY drivers that implement link state change interrupts may change the value of the interface flag immediately upon link state change detection. In this scenario, calling NetIF_LinkStateGet() is ideal for these interfaces.

Increasing the Rate of Link State Polling

The application may increase the µC/TCP-IP link state polling rate by calling NetIF_CfgPhyLinkPeriod(). The default value is 250ms.

Forcing an Ethernet PHY to a Specific Link State

The generic PHY driver that comes with µC/TCP-IP does not provide a mechanism for disabling auto-negotiation and specifying a desired link state. This restriction is required in order to remain MII register block compliant with all (R)MII compliant physical layer devices.

However, µC/TCP-IP does provide a mechanism for coaching the physical layer device into advertising only the desired auto-negotiation states. This may be achieved by adjusting the physical layer device configuration as specified in net_dev_cfg.c with alternative link speed and duplex values.

The following is an example physical layer device configuration structure.

The parameters NET_PHY_SPD_AUTO and NET_PHY_DUPLEX_AUTO may be changed to match any of the following settings:

NET_PHY_SPD_10
NET_PHY_SPD_100
NET_PHY_SPD_1000
NET_PHY_SPD_AUTO
NET_PHY_DUPLEX_HALF
NET_PHY_DUPLEX_FULL
NET_PHY_DUPLEX_AUTO

This mechanism is only effective when both the physical layer device attached to the target and the remote link state partner support auto-negotiation.

Refer to section Ethernet PHY Configuration for detailed information on the PHY device configuration.

  • No labels