e = TK_NEWTASK(&kel_udp_task); if (e != 0) { dprintf("udp task create error\n" ); panic("create_apptasks" ); return -1; // compiler warnings }
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 };
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;}
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?
//*****************************************************************************// 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
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:
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
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....