AnsweredAssumed Answered

Ethernet Cable Status - TWR-SER2 board

Question asked by Priya Gupta on Oct 5, 2017
Latest reply on Oct 6, 2017 by Mark Butcher

I'm trying to detect the status of the network cable (plugged, un-plugged) on a TWR-SER2 board connected with TWR-K60F120M using MQX 4.2.

 I am using the RTCS function - "ipcfg_get_link_active()" but it seems to always return a 'TRUE' once the Ethernet system is configured. Prior to configuring the Ethernet it reports a 'FALSE'.

Once the Ethernet system is configured and operational, plugging or un-plugging the Ethernet cable from the TWR-SER2 module seems to make no difference, the function always returns a 'TRUE'. 

 

Code Snippet:

#define BSP_DEFAULT_ENET_DEVICE   0

 

error = RTCS_create();
if(error == RTCS_OK)
{
   /* Initialise Ethernet */
   error = ipcfg_init_device(BSP_DEFAULT_ENET_DEVICE, mac_address);
   if (error != IPCFG_OK)
   {
      printf("Fatal Error 0x%X: Network device initialisation failed.\n", error);
      _task_block();
   }
while(retVal == FALSE)
{
   retVal = ipcfg_get_link_active(BSP_DEFAULT_ENET_DEVICE);
   if(retVal == TRUE)
      printf("\nCable Connected..!!");
   else
        printf("\nCable not connected..!!");
   _time_delay(100);

-- It comes out of while loop at once.

 

Also, i tried to read the data value in phy_dp83xxx_get_link_status() function; it always returns 0x7FFF, no matter whether the cable is connected or not connected.

 

static bool phy_dp83xxx_get_link_status
(
ENET_CONTEXT_STRUCT_PTR enet_ptr
)
{
uint32_t data;
bool res = FALSE;

/* Some PHY (e.g.DP8340) returns "unconnected" and than "connected" state
* just to show that was transition event from one state to another.
* As we need only curent state, read 2 times and return
* the current/latest state. */
if ((*enet_ptr->PARAM_PTR->ENET_IF->MAC_IF->PHY_READ)(enet_ptr, DP83XXX_REG_BMSR, &data, MII_TIMEOUT)) {
if ((*enet_ptr->PARAM_PTR->ENET_IF->MAC_IF->PHY_READ)(enet_ptr, DP83XXX_REG_BMSR, &data, MII_TIMEOUT))
{
printf("\nData: %lx", data);
res = ((data & DP83XXX_REG_BMSR_LINK_STATUS) != 0) ? TRUE : FALSE;
}
}
return res;
}

Outcomes