RTCS recvfrom() not working on consistent lines

cancel
Showing results for 
Search instead for 
Did you mean: 

RTCS recvfrom() not working on consistent lines

Jump to solution
513 Views
ravindragurjar
Contributor I

Here is my code to send/receive data on UDP on a MQX task

   uint32_t error = RTCS_create();

   if (error != RTCS_OK)

   {

      printf("\nRTCS failed to initialize, error = %X", error);

      _task_block();

   }

   ip_data.ip = ENET_IPADDR;

   ip_data.mask = ENET_IPMASK;

   ip_data.gateway = ENET_GATEWAY;

   /* calcualte unique mac address from IP ADDRES */

   ENET_get_mac_address (ENET_DEVICE, ENET_IPADDR, enet_address);

   error = ipcfg_init_device (ENET_DEVICE, enet_address);

   if (error != RTCS_OK)

   {

      printf("\nFailed to initialize ethernet device, error = %X", error);

      _task_block();

   }

   error = ipcfg_bind_staticip (ENET_DEVICE, &ip_data);

   

    sock_udp = socket(PF_INET, SOCK_DGRAM, 0);

    local_addr.sin_family      = AF_INET;

    local_addr.sin_port        = DEF_HARTIP_PORT;  

    local_addr.sin_addr.s_addr = INADDR_ANY;

    bind(sock_udp, (sockaddr *)(&local_addr), sizeof(sockaddr_in));

    while (1)

    {

      len_request = recvfrom(sock_udp, &msg_buffer[0], sizeof(hartmsg_buffer), 0, (struct sockaddr *) &local_addr,&remote_len);

     ...Process the received data * compose response

      sendto(sock_udp, &hartmsg_buffer[0], tx_size, 0, (struct sockaddr *)&local_addr,sizeof(sockaddr_in));             

    }

When i hook up the UDP client, the communication works fine for few iterations. The recvfrom() dont process all the requests and 1 out 10 request dont generate response.

Am i missing something like a time delay or something?

Tags (1)
0 Kudos
1 Solution
247 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi

From your issue description, it seems a hardware issue.  But your tcp socket is working perfectly. So I am not sure. Anyway, you can check your board jump settings first.

eth_en.jpg

  If this issue  still exists,  how much traffic you are using? only ping packets?

Regards

Daniel

View solution in original post

0 Kudos
7 Replies
247 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Ravindra:

Which board you are using?

Regards

Daniel

0 Kudos
247 Views
ravindragurjar
Contributor I

K70F120M tower board.

My TCP/IP socket is working perfectly, issue is only with UDP socket.

0 Kudos
248 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi

From your issue description, it seems a hardware issue.  But your tcp socket is working perfectly. So I am not sure. Anyway, you can check your board jump settings first.

eth_en.jpg

  If this issue  still exists,  how much traffic you are using? only ping packets?

Regards

Daniel

View solution in original post

0 Kudos
247 Views
ravindragurjar
Contributor I

Turned out to be a jumper setting issue. After changing the J18 position I am able to see good behavior.

Thanks for your prompt support. :smileyhappy:

0 Kudos
247 Views
ravindragurjar
Contributor I

My TWR-SER is Rev E. The Ethernet switch seems to be fine on board as TCP/IP is working fine.

I am using pretty less traffic with UDP client sending read request every 500mSec.

0 Kudos
247 Views
danielchen
NXP TechSupport
NXP TechSupport

Is your computer connected directly to your MCU?   Because UDP is an unreliable transfer, maybe it will lose some packets especially in some complex networking environment.

0 Kudos
247 Views
ravindragurjar
Contributor I

Yes, its direct connection. When i run the ping command, i see no response to 1 out of 10 requests (times out).

One thing to mention is that i am running the code in Debug mode, not in release mode if that can possibly matter...

0 Kudos