RTCS recvfrom() not working on consistent lines

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

RTCS recvfrom() not working on consistent lines

ソリューションへジャンプ
3,636件の閲覧回数
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,370件の閲覧回数
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,370件の閲覧回数
danielchen
NXP TechSupport
NXP TechSupport

Hi Ravindra:

Which board you are using?

Regards

Daniel

0 件の賞賛
返信
3,370件の閲覧回数
ravindragurjar
Contributor I

K70F120M tower board.

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

0 件の賞賛
返信
3,371件の閲覧回数
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,370件の閲覧回数
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,370件の閲覧回数
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,370件の閲覧回数
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,370件の閲覧回数
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 件の賞賛
返信