AnsweredAssumed Answered

PHY_xxx, ENET_xxx functions are thread safe?

Question asked by JIWON KIM on May 28, 2020
Latest reply on Jul 9, 2020 by Daniel Chen



I don't think PHY_xxx and ENET_xxx functions are not thread safe but want to clarify if they really are and want to know how to use it in the right way.


Q1) is it possible to call PHY_GetLinkStatus function in different thread? Or it would be better one task only call the function and update the status into a variable and other tasks read the variable with lock?


Q2) Do I need to lock/unlcok  TCP core whenever calling PHY_xxx OR ENET_xxx functions?


Q3) netif_set_link_up and netif_set_up are not thread safe so there are netifapi_xxx functions to support thread safe but there are not thread safe functions for netif_is_link_up and netif_is_up. Is this because those function are read functions? Can I assume they are thread safe? or I also need to lock the functions using LOCK_TCPIP_CORE or seperate lock.


Q4) Do I need to set phy speed and duplex by calling ENET_SetMII function whenever the Ethernet cable is connected from disconnection?


The following are the information of my project environment:

  • Board: imxrt1060 evk
  • SDK: 2.6.2 (
  • Library: Newlib (semihost)
static void EthernetMonitoring( void )
    static bool xOldLink = -1;
    bool xCurLink;

    if (PHY_GetLinkStatus(ENET, BOARD_ENET0_PHY_ADDRESS, &xCurLink) == kStatus_Success)
        if (xCurLink != xOldLink)
            if (xCurLink)
                netifapi_netif_set_link_up( (struct netif*) &fsl_netif0);
                netifapi_netif_set_up( (struct netif*) &fsl_netif0);
                phy_speed_t xSpeed;
                phy_duplex_t xDuplex;
                if (PHY_GetLinkSpeedDuplex(ENET, BOARD_ENET0_PHY_ADDRESS, &xSpeed, &xDuplex) ==                              kStatus_Success)
                    ENET_SetMII(ENET, xSpeed, xDuplex);
                    PRINTF("ETH0 link is going up, speed=%iMBit/s, duplex=%s", xSpeed==kPHY_Speed100M ? 100:10,                   xDuplex==kPHY_FullDuplex ? "Full":"Half");
                    PRINTF("ETH0 link is going up");
               netifapi_netif_set_link_down((struct netif *) &fsl_netif0);
               netifapi_netif_set_down((struct netif*) &fsl_netif0);
               PRINTF("ETH0 link is going down");

           xOldLink = xCurLink;