Author Topic: Ethernet Awareness  (Read 6208 times)

Offline FM

  • Newbie
  • *
  • Posts: 1
    • View Profile
Ethernet Awareness
« on: December 26, 2014, 03:31:57 PM »
Hi All,

Is it possible to detect/sense that the ethernet cable is plugged in or not with a simple (existing) function call?
And if so, is there an easy test to check whether the network connection is actually running/working?

I figured to run a task performing a simple ping every x seconds to tackle this problem, but is there an easier solution I overlooked?

Happy holidays,
F

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3237
    • View Profile
    • uTasker
Re: Ethernet Awareness
« Reply #1 on: December 26, 2014, 03:53:46 PM »
Hi F

The PHY reacts to the link's up/down state and it depends on the PHY's connection to the processor. In the best case there is a PHY interrupt line connected and the Ethernet driver will be handling these interrupts on each link state change. In some cases there is no interrupt line connected (eg. the FRDM-K64F board doesn't have one) and so it is necessary to poll the state of the PHY (and thus the link).

In the interrupt case there is LINK UP/DOWN and speed information reported to the NetworkIndicator task (NetworkIndicator.c) - enabled when INTERRUPT_TASK_PHY is defined. There is a debug message indicating the new link state, speed and duplex setting. Eg. "LAN link-up 100 full-duplex"

In the non-interrupt case polling is enabled by the define PHY_POLL_LINK. This will cause the NetworkIndicator to periodically be repeated at a rate of PHY_POLL_TIME (5s is default) and each time it reads the state from the PHY and reacts to state changes in the same way. To do this the function fnCheckEthLinkState() is called by the task.

The polling method was added on 16th December 2012 so will be available in any versions newer than that. The interrupt method has always been available.

NetworkIndicator.c is an application file and so can be modified to display such details on LEDs, on an LCD etc. or pass them on to other tasks as required.

If you prefer that the events are sent directly to a different task than the NetworkIndicator one you can also set the task as INTERRUPT_TASK_PHY so that all are sent to it instead.

Regards

Mark