InterNiche Network Stack and UDP

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

InterNiche Network Stack and UDP

6,382 Views
wyliek
Contributor I
Hi there
I have been playing around with the M52233DEMO board and InterNiche's network stack and have encountered a few problems with NicheTask.
I have a simple application in mind that I have been battling to complete. I want to modify the existing ColdFire Lite project (webserver) to include a task which sends a single UDP packet containing some string and then idles. My code is as follows:
In the function create_apptasks()--
 
Code:
  e = TK_NEWTASK(&kel_udp_task);   if (e != 0)   {      dprintf("udp task create error\n" );      panic("create_apptasks" );      return -1;  // compiler warnings    }

I have declared the task Object--
Code:
TK_OBJECT(to_keludpclient);TK_ENTRY(tk_keludpclient);struct inet_taskinfo kel_udp_task={ &to_keludpclient,
                                   "KEL UDP Client",                                    tk_keludpclient,
                                   NET_PRIORITY,
                                   APP_STACK_SIZE                                  };

My task code is as follows--
Code:
TK_ENTRY(tk_keludpclient){   int e, i=0;   char data[]="heres a thing!";   void * event;   e=0;   while (!iniche_net_ready)      TK_SLEEP(1);      for (;;)   {            while (!iniche_net_ready)        TK_SLEEP(1);      i++;      if (i==1)      {        e=kel_send_udp(data, 14, 0xC0010395, 3490, 3490);      }            tk_yield();      if (net_system_exit)        break;   }   TK_RETURN_OK();}int kel_send_udp(char *data, int datalen, ip_addr destip, u_short lport, u_short fport){  PACKET data_pkt;  int e;  void * event;    data_pkt=udp_alloc(datalen,0);  tk_yield();  if (!data_pkt)    printf("trouble allocating packet" );  data_pkt->nb_prot =data;  data_pkt->nb_plen =datalen;  data_pkt->fhost   =destip;  e=udp_send(fport, lport, data_pkt);  tk_yield();  //************  //this only works if I add in tk_exit at this point  //tk_exit();  //************  udp_free(data_pkt);  tk_yield();  return e;}

 
Using the code as is, the MCF52233 boots up and sends a UDP packet as expected, but then hangs. The Serial port output stops at--
 
Calling netmain()...
InterNiche ColdFireLite TCP/
 
The only way I get it to work without hanging is when I add tk_exit() after I call the udp_send function. Why is this? How do I make the task run properly without having to kill it?
Thanks
Kyle
Labels (1)
0 Kudos
14 Replies

1,162 Views
samba
Contributor I
Hi wyliek,

the code is ok. All works fine.

I had a wrong memcopy in the Original udp_send Routine.

Now i send my char dat[] =="abcdefg..." with

e = send_udp_data(pup->ud_dstp, pup->ud_srcp,pip->ip_dest, (dat), 9);

thanks

Samba
0 Kudos

1,162 Views
samba
Contributor I
Hi wyliek,

Yes, now it works, thanks !!

I look after the data that I send to my IP address with Etereal.

-my data are: "abcdefghijk"

but I only get the data:

1) rld.ufghi (data,9)
2.)rld.ufghijk (data,11)

why this?

samba
0 Kudos

1,162 Views
wyliek
Contributor I
Hi Samba

It looks like you are somehow manipulating the first four bytes of char * data. Check to see if your code does not access this variable at any time between:

char data[]="abcdefghijk"

and

memcpy(data_pakt->nb_prot, datas, datalen);

cheers
good luck!
0 Kudos

1,162 Views
samba
Contributor I
Hi wyliek,
i try this(yours):
----------------------------------------
TK_OBJECT(to_keludpclient);
TK_ENTRY(tk_keludpclient);

struct inet_taskinfo kel_udp_task={
&to_keludpclient,
"KEL UDP Client",
tk_keludpclient,
NET_PRIORITY,
APP_STACK_SIZE
};
-------------------------------------------
e = TK_NEWTASK(&kel_udp_task);
if (e != 0)
{
dprintf("udp task create error\n" );
panic("create_apptasks" );
return -1; // compiler warnings
}
-------------------------------------------
TK_ENTRY(tk_keludpclient)
{
int e = 0;
char data[]="heres a thing!";

printf("Hello world. \n");
printf("task1: UDP send starting up. \n");
while(!uart_flush(0)){};
while (!iniche_net_ready)
{
TK_SLEEP(1);
}
send_udp_data(data, 14, 0xC0010395, 3490, 3490);
while(1)
{
printf("- still running -");
tk_yield();
}
}
--------------------------------------
int send_udp_data(u_short lport, u_short fport, ip_addr dest_ip, char * datas, int datalen)
{
PACKET data_pakt;
int e = 0;

data_pakt=udp_alloc(datalen,0);
if (data_pakt==NULL)
printf("trouble allocating packet");

memcpy(data_pakt->nb_prot, datas, datalen);
data_pakt->nb_plen =datalen;
data_pakt->fhost =dest_ip;
e=udp_send(fport, lport, data_pakt);
return e;

}

and my Output is:
--------------------------------------
...
Copyright 1997-2006 by InterNiche Technologies. All rights reserved.
Preparing device for networking
Ethernet started, Iface: 0, IP: 192.168.0.1
IP address of : 192.168.0.1
INET> Hello world.
task1: UDP send starting up.
trouble allocating packetAccess Error -- PC = 0x00001812
Attempted write to write-protected space
Access Error -- PC = 0x00001812
Attempted write to write-protected space
Access Error -- PC = 0x00001812
....
you see what's wrong?

thanks
0 Kudos

1,162 Views
wyliek
Contributor I
Hi samba
 
From your output I see, "trouble allocating packet " which means that udp_alloc is not working properly or cannot allocate the packet for you.
 
Make sure you have:
 
#include "udp.h"
#include "ip.h"
 
in the same file as send_udp_data
 
ALSO:
the line:
 
send_udp_data(data, 14, 0xC0010395, 3490, 3490);
 
is wrong. It needs to be:
send_udp_data(3941, 3941, 0xC00103CC, data, 14);
 
where 0xC00103CC is the IP address where you want to send the packet try:
 
Code:
TK_ENTRY(tk_udp_test){  int err;  char data[] = "some text";    printf("Hello world. \n");  printf("task1: UDP send starting up. \n");    while(!iniche_net_ready)    TK_SLEEP(1);    while(!uart_flush(0)){};    tk_yield();  send_udp_data(3941, 3941, 0xC00103CC, data, 9);    while (1)  {   printf("-still running");   //send_udp_data(3941, 3941, 0xC00103CC, data, 11);   tk_yield();  }  TK_RETURN_OK();}

 

Does this work?

 


 
 
0 Kudos

1,162 Views
samba
Contributor I
Hi wyliek,

can you show the working example with memcpy() please?


thanks
0 Kudos

1,162 Views
wyliek
Contributor I
Code:
//*****************************************************************************// send_udp_data//*****************************************************************************int send_udp_data(u_short lport, u_short fport, ip_addr dest_ip, char * datas, int datalen){  PACKET data_pakt;   int e = 0;    data_pakt=udp_alloc(datalen,0);  if (data_pakt==NULL)    printf("trouble allocating packet");    memcpy(data_pakt->nb_prot, datas, datalen);  data_pakt->nb_plen =datalen;  data_pakt->fhost   =dest_ip;  e=udp_send(fport, lport, data_pakt);  return e;  }

Hi Samba

Here is my function that sends a striing via udp. Is this what you need?

Kyle


 
0 Kudos

1,162 Views
wyliek
Contributor I
Hi gxd

Thanks for the suggestion. I tried it but I still get the same error:
SERIAL PORT OUTPUT:

Running ColdFire TCP/IP-Lite stack

Copyright 2006 by Freescale Semiconductor Inc.
Use of this software is controlled by the agreement
found in the project LICENSE.H file.
Built on Nov 7 2006 14:47:16

Coldfire Demo

Heap size = 25344 bytes
etheraddr = 00:CF:52:23:45:00

Starting ints.
Calling netmain()...
InterNiche ColdFireLite TCP/IP for Coldfire, v3.0

Copyright 1997-2006 by InterNiche Technologies. All rights reserved.
Preparing device for networking
Ethernet started, Iface: 0, IP: 192.1.2.42
IP address of : 192.1.2.42
INET> Hello world.
task1: UDP send starting up.
udp_send -> 1
Unimplemented F-Line Instruction -- PC = 0x00010000
Unimplemented F-Line Instruction -- PC = 0x00010000
Unimplemented F-Line Instruction -- PC = 0x00010000
Unimplemented F-Line Instruction -- PC = 0x00010000
Unimplemented F-Line Instruction -- PC = 0x00010000
Unimplemented F-Line Instruction -- PC =

etc.

What would cause such an error?
0 Kudos

1,162 Views
gxd
Contributor I
Hi :
perhaps I found a error!
 
Note udp_send(){
.......
 p->nb_prot -= sizeof(struct udp);  // at here  the nb_prob must point original address,do not change it!!!
........
}
 
so  when you append your data to udp_send.  must do not change the point p->nb_prot
 
perhaps :
 
do not do so: 
p->nb_prob=data;
 
must do so:
memcpy(p->nb_prob, "hello,world",sizeof("hello,world!");
 
it is OK?
 
 
0 Kudos

1,162 Views
wyliek
Contributor I
Hi gxd
 
Thanks for the help. Its working now with memcpy().
 
I think you are right, there is an error in udp_send(). Can anyone clarify this?
 
As for the udp_alloc() function. It seems to work but I dont know why. As you say, nb_plen is set to 0 then has len subtracted from it. This does yield a negative number. Can anyone shed some light on this?
 
Thanks again gxd
0 Kudos

1,162 Views
gxd
Contributor I
Hi: i feel sorry not to help you.
 
some things let me puzzle:
 
 
Note the------- udp_alloc(int datalen, int optlen)
{
  int   len;
  PACKET p;
  len = (datalen + sizeof(struct udp) + 1) & ~1;
  LOCK_NET_RESOURCE(FREEQ_RESID);
  p = pk_alloc(len + IPHSIZ + MaxLnh + optlen);             ///at here nb_plen=0
  UNLOCK_NET_RESOURCE(FREEQ_RESID);
  if (!p)
     return NULL;
  /* set prot pointers past end of UDP header  */
  len = sizeof(struct ip) + (optlen >> 2) + sizeof(struct udp);
  p->nb_prot += len;
  p->nb_plen -= len;                                  ///////////////////////////////////////////////   nb_plen-len==????
  return(p);
}
 
then trace udp_send()
 
  udplen = p->nb_plen + sizeof(struct udp);            ///////////////////////////////  nb_plen=?
 
can you explain why?  will it make memory overflowl?
 
if you solve the problem.pls let me share.
 
togxd@citiz.net 

 
 
 
0 Kudos

1,162 Views
wyliek
Contributor I
Hi gxd
 
Sorry, I dont really know what you mean. Are you saying that I'm sending the packets too frequently?
I tried this instead and it didn't work either:
Code:
TK_ENTRY(tk_keludpclient){int e = 0;char data[]="heres a thing!";            printf("Hello world. \n");      printf("task1: UDP send starting up. \n");      while(!uart_flush(0)){};      while (!iniche_net_ready)      {       TK_SLEEP(1);      }            //kel_send_tcp(data, 14, 0xC0010395, 3490);      kel_send_udp(data, 14, 0xC0010395, 3490, 3490);      while(1)      {         printf("- still running -");         tk_yield();      }}
and the udp_send function:
Code:
int kel_send_udp(char *data, int datalen, ip_addr destip, u_short lport, u_short fport){  PACKET data_pkt;  int e=0;  void * event;    data_pkt=udp_alloc(datalen,0);  //tk_yield();  if (!data_pkt)    printf("trouble allocating packet");  data_pkt->nb_prot =data;  data_pkt->nb_plen =datalen;  data_pkt->fhost   =destip;  udp_send(fport, lport, data_pkt);  //tk_yield(); // If i dont put in this yield the stack sends a bogus IP packet
  udp_free(data_pkt);  //tk_yield();  return e;}

If I dont put in the yield after udp_send() then the micro sends a bogus IP packet with header length 0.  With the tk_yield() in place a proper UDP packet is sent, but the serial port output is a continuous:

Unimplemented F-Line Instruction -- PC = 0x00010000

Unimplemented F-Line Instruction -- PC = 0x00010000

Unimplemented F-Line Instruction -- PC = 0x00010000
 
etc...

I really am a bit confused. Could someone shed some light?

thanks

kyle

0 Kudos

1,162 Views
gxd
Contributor I
Can you try to add " tk_sleep(1000);" below:
TK_ENTRY(tk_keludpclient){int e = 0;char data[]="heres a thing!";            printf("Hello world. \n");      printf("task1: UDP send starting up. \n");      while(!uart_flush(0)){};      while (!iniche_net_ready)      {       TK_SLEEP(1);      }        TK_SLEEP(100);      //kel_send_tcp(data, 14, 0xC0010395, 3490);      kel_send_udp(data, 14, 0xC0010395, 3490, 3490);      while(1)      {
 TK_SLEEP(1000);  ////////////////////////////////////////////add it here.         printf("- still running -");         tk_yield();      }}
I hope it is right....
0 Kudos

1,162 Views
gxd
Contributor I
 
If it is too freauencive to send the udp packet?
while i++=32768 you send a packet, CPU can't send it before the time is over.
 
can you tell me  why so many tk_yield() to call?
 
:smileyhappy:
 for (;:smileywink:
  {
     
     while (!iniche_net_ready)
       TK_SLEEP(1);
     i++;
     if (i==1)
     {
       e=kel_send_udp(data, 14, 0xC0010395, 3490, 3490);
     }
     
     tk_yield();
     if (net_system_exit)
       break;
  }
0 Kudos