Determine Ethernet Link Status in TWR-MPC-5125

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Determine Ethernet Link Status in TWR-MPC-5125

Jump to solution
690 Views
Tim562
Senior Contributor I

Hi All,

     I'm trying to detect the status of the network cable (plugged, un-plugged) on a TWR-MPC-5125 module. The Ethernet connection is working properly (I am using streaming sockets) but I would like to be able to detect the status of the network cable. I see there is a function in the RTCS manual that looks like it should do this "ipcfg_get_link_active()" but it seems to always return a 1 once the Ethernet system is configured. Prior to configuring the Ethernet it reports a 0 (that part makes sense). Once the Ethernet system is configured and operational, plugging or un-plugging the Ethernet cable from the TWR-MPC-5125 module seems to make no difference, the function always returns a 1. Perhaps I am using it incorrectly? I'm currently calling it from my program main loop like this:

main()

     {

     Boolean bLinkActive;

     bLinkActive = ipcfg_get_link_active(BSP_DEFAULT_ENET_DEVICE);

     if(bLinkActive == TRUE)

          {

          printf("Cable is plugged in");

          }

     else

          {

          printf("Cable is unplugged");

          }

     }

The constant BSP_DEFAULT_ENET_DEVICE is set to 0 which is the correct adapter. I'm using MQX 3.8.1 patched to RTCS 4.0.2 Any ideas?

Thanks!

Tim

Labels (1)
0 Kudos
1 Solution
406 Views
soledad
NXP Employee
NXP Employee

Hi Tim,

Please try replacing the phy_dp83xxx_get_link_status() function implementation in phy_dp83xxx.c

({MQX installation path}\mqx\source\io\enet\phy) by the following one:

static boolean phy_dp83xxx_get_link_status

(

ENET_CONTEXT_STRUCT_PTR enet_ptr

)

{

uint_32 data;

boolean 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)) {

_time_delay(BSP_ALARM_RESOLUTION);

if ((*enet_ptr->PARAM_PTR->ENET_IF->MAC_IF->PHY_READ)(enet_ptr, DP83XXX_REG_BMSR, &data, MII_TIMEOUT))

{

res = ((data & DP83XXX_REG_BMSR_LINK_STATUS) != 0) ? TRUE : FALSE;

}

}

return res;

}

...in fact, just a delay was inserted between two consecutive readings of the BMSR register of the PHY chip.

Please let me know if this helps,


Have a great day,
Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
2 Replies
407 Views
soledad
NXP Employee
NXP Employee

Hi Tim,

Please try replacing the phy_dp83xxx_get_link_status() function implementation in phy_dp83xxx.c

({MQX installation path}\mqx\source\io\enet\phy) by the following one:

static boolean phy_dp83xxx_get_link_status

(

ENET_CONTEXT_STRUCT_PTR enet_ptr

)

{

uint_32 data;

boolean 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)) {

_time_delay(BSP_ALARM_RESOLUTION);

if ((*enet_ptr->PARAM_PTR->ENET_IF->MAC_IF->PHY_READ)(enet_ptr, DP83XXX_REG_BMSR, &data, MII_TIMEOUT))

{

res = ((data & DP83XXX_REG_BMSR_LINK_STATUS) != 0) ? TRUE : FALSE;

}

}

return res;

}

...in fact, just a delay was inserted between two consecutive readings of the BMSR register of the PHY chip.

Please let me know if this helps,


Have a great day,
Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
406 Views
Tim562
Senior Contributor I

Hi Sol,

     Your suggestion did the trick! The MPC-5125 has an 8710 phy on it, so I modified the phy_lan8710_get_link_status() function in the phy_lan8710.c file and now it works properly. I had noticed earlier that if I stepped through that function when it performed the two reads, it returned the proper result but if I let it run at full speed if always returned 0xFFFF so this fix made a lot of sense. Thank you for your help, I appreciate it.

Best Regards,

Tim

0 Kudos