PHY_xxx, ENET_xxx functions are thread safe?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

PHY_xxx, ENET_xxx functions are thread safe?

1,037 次查看
creatorwonny
Contributor III

Hi

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 (SDK_2.6.2_EVK-MIMXRT1060-FreeRTOS.zip)
  • 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)
                {
                    LOCK_TCPIP_CORE();
                    ENET_SetMII(ENET, xSpeed, xDuplex);
                    UNLOCK_TCPIP_CORE();
                    PRINTF("ETH0 link is going up, speed=%iMBit/s, duplex=%s", xSpeed==kPHY_Speed100M ? 100:10,                   xDuplex==kPHY_FullDuplex ? "Full":"Half"); 
                }
                else
                { 
                    PRINTF("ETH0 link is going up");
                }
           } 
           else
           {
               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;
        }

    }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Thanks

标签 (1)
0 项奖励
回复
1 回复

961 次查看
danielchen
NXP TechSupport
NXP TechSupport

Hi Jiwon:

As far as I know, sdk drivers (prefix with fsl_xxx.c , such as fsl_enet.c/fsl_phy.c)are not thread safe, the sdk drivers focus on bare metal, so when used in a multiple thread environment,  application should take care of the competition. 

Regards

Daniel

0 项奖励
回复