RTCS recvfrom() not working on consistent lines

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

RTCS recvfrom() not working on consistent lines

跳至解决方案
3,697 次查看
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?

标记 (1)
0 项奖励
回复
1 解答
3,431 次查看
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

在原帖中查看解决方案

0 项奖励
回复
7 回复数
3,431 次查看
danielchen
NXP TechSupport
NXP TechSupport

Hi Ravindra:

Which board you are using?

Regards

Daniel

0 项奖励
回复
3,431 次查看
ravindragurjar
Contributor I

K70F120M tower board.

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

0 项奖励
回复
3,432 次查看
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

0 项奖励
回复
3,431 次查看
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 项奖励
回复
3,431 次查看
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 项奖励
回复
3,431 次查看
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 项奖励
回复
3,431 次查看
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 项奖励
回复