AnsweredAssumed Answered

RTCS link detection

Question asked by vines on Nov 13, 2012
Latest reply on Nov 16, 2012 by vines

Hi all,

 

I have been working with K60 platform with my own hardware. Sending and Receiving to/from my hardware is working fine. I can communicate to my utility software without a problem. However, detection of whether the link is up or down is not working.

 

Here is the scenario:

1. connect the hardware ethernet to network

2. Opens Utility SW and connect to the hardware (successful)

3. Sends something from SW to HW and vice versa (successful - proves that initialization of network parameters e.g. IP, submask, gateway are succesful - I can see acknowledge packets from my utility SW)

4. Try to pull out the ethernet cable from HW (now this is the problem)

 

The system should be able to detect that the system lost the ethernet link. I have tried a few things like polling, pinging, Even sending when the link is down. But the system won't give back an error message base on my debug.It always returns OK message.

 

Here is a portion of the simplified code.I didn't copy some of the things that are I think not essential to this question.

 

//From tower default

/*

#define BSP_DEFAULT_ENET_DEVICE             0

#define BSP_DEFAULT_ENET_OUI                { 0x00, 0x00, 0x5E, 0, 0, 0 }

#define AF_INET         1

#define INADDR_ANY               0

#define ENET_DEVICE BSP_DEFAULT_ENET_DEVICE

*/

//Own  port

#define TCP_PORT                    20000

typedef _enet_address net_addr;

u32 gChildHandle;

static IPCFG_IP_ADDRESS_DATA ipDataGlobal;

bool gTcpLinkUp = false;

 

 

void HalInitRtcs(void)

{

    u32 error;

    net_addr enet_address = BSP_DEFAULT_ENET_OUI;

 

    error = RTCS_create();

    if (error)

        os_task_block();

    if ((ipcfg_init_device(ENET_DEVICE, enet_address)) != IPCFG_OK)

        os_task_block();

#ifdef ENET_DEVICE

    ENET_get_mac_address(ENET_DEVICE, ipDataGlobal.ip, enet_address);

#endif

    if ((ipcfg_bind_staticip(ENET_DEVICE, &ipDataGlobal)) != IPCFG_OK)

        os_task_block();

}

 

 

void HalSockInit(u32 *sock, sockaddr_in *sockaddrlocal)

{

    u32 error;

    sockaddrlocal->sin_family = AF_INET;

    sockaddrlocal->sin_port = TCP_PORT;

    sockaddrlocal->sin_addr.s_addr = INADDR_ANY;

 

    *sock = socket(PF_INET, SOCK_STREAM, 0);

    if (*sock == RTCS_SOCKET_ERROR)

        os_task_block();

 

    error = bind(*sock, sockaddrlocal, sizeof(sockaddr_in));

    if (error != RTCS_OK)

        os_task_block();

}

 

 

void HalNicInitTask(u32 dummy)

{

    u32 error;

    sockaddr_in gPeerAddr;

    u16 gPeerLen;

    sockaddr_in gLocalAddr;

    u32 gSock;

    u32 opt_length = sizeof(u32);

    u32 opt_value = FALSE;

    u32 sock, sockMonitor;

 

    //do some mutex init didn't copy this portion

 

    HalInitRtcs();

    HalSockInit(&gSock, &gLocalAddr);

   

    while (TRUE)

    {

        if (listen(gSock, 0) == RTCS_OK)

        {

               gPeerLen = sizeof(gPeerAddr);

               if ((gChildHandle = accept(gSock, &gPeerAddr, &gPeerLen)) != RTCS_SOCKET_ERROR)

                {

                         //both values with no effect to send() return value

                         //opt_value = TRUE;

                         opt_value = FALSE;

                         error = setsockopt(gChildHandle, SOL_TCP, OPT_RECEIVE_NOWAIT, &opt_value,1);

                         //no effect to poll

                         //opt_value = 1;

                         //error = setsockopt(gChildHandle, SOL_TCP, OPT_KEEPALIVE, &opt_value, 1);

                         if (error == RTCS_OK)

                         {

                              if (gChildHandle != RTCS_SOCKET_ERROR)

                              {

                                   os_time_delay(100);

                                   gTcpLinkUp = true;

                                   ipcfg_task_create(8, 1000);

                                   while (gTcpLinkUp)

                                   {

                                        u32 timeout=1000;

                                        boolean testBit=0;

                                        if ((testBit =ipcfg_task_poll()) == false)

                                             gTcpLinkUp = false;//it won't enter this line

                                        if ((error = RTCS_ping(ipDataGlobal.ip,&timeout,0)) != RTCS_OK)

                                             gTcpLinkUp = false;//it won't enter this line

                                        if ((testBit = ipcfg_get_link_active(BSP_DEFAULT_ENET_DEVICE)) == FALSE)

                                             gTcpLinkUp = false;//it won't enter this line

                                        os_time_delay(100);

                                   }

                                   ipcfg_task_destroy(TRUE);

                                   shutdown(gChildHandle, FLAG_CLOSE_TX);

                                   shutdown(gSock, FLAG_CLOSE_TX);

                       

                                   HalSockInit(&gSock, &gLocalAddr); // reinit socket after shutdown

                              }

                    }

                    else

                    {

                    shutdown(gChildHandle, FLAG_CLOSE_TX);

                    shutdown(gSock, FLAG_CLOSE_TX);

                   

                    HalSockInit(&gSock, &gLocalAddr); // reinit socket after shutdown

                     }

               }

               os_time_delay(100);

          }

          os_time_delay(10);

    }

}

 

from a different task i tried calling the below line when I remove the ethernet cable from the HW. Still the send returns the previous datalen or not an error.

 

     error = send(gChildHandle, TxDataTcp, TxDataLenTcp, 0);

     if (error == RTCS_ERROR || error != TxDataLenTcp)

          gTcpLinkUp = false;//it won't enter this line

 

My BSP Userconfig.h lines are:

 

#define RTCSCFG_ENABLE_ICMP  1
#define RTCSCFG_ENABLE_UDP   1
#define RTCSCFG_ENABLE_TCP   1
#define RTCSCFG_ENABLE_STATS 1

#define RTCSCFG_ENABLE_GATEWAYS  1

#define FTPDCFG_USES_MFS     1
#define RTCSCFG_ENABLE_SNMP  0

 

#define TELNETDCFG_NOWAIT    FALSE

 

#define MQX_TASK_DESTRUCTION 1

 

#define HTTPDCFG_POLL_MODE   0
#define HTTPDCFG_STATIC_TASKS0

#define HTTPDCFG_DYNAMIC_TASKS   1

 

Thanks in advance for the help.


 


Outcomes