lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] Xilinx PowerPC receive udp messages


From: Sathya Thammanur
Subject: Re: [lwip-users] Xilinx PowerPC receive udp messages
Date: Tue, 22 Aug 2006 11:00:51 -0700

Hi Peter,
Xilkernel is needed when you want to use the sockets API of lwIP. The kernel provides the semaphores and mailboxes feature required for the sockets mode operation. However, the RAW API works using callback functions. The code definitely is different for Sockets mode vs Raw mode. Mixing the two modes will not work correctly. A TCP echo server example using the RAW API mode is attached.

Hope this helps.

Sathya


On 8/21/06, Peter Kampmann <address@hidden> wrote:

Hi everyone,

after trying various ways to receive an udp-packet to the powerPC, I want to
ask if somebody of you sees perhaps the missing or wrong code that makes my
code refusing to accept udp packages.


static u8_t my_timer = 0;

struct ip_addr ipaddr, netmask, gw;
char macAdress[6];
char port = 9050;
struct netif * networkInterface;
struct pbuf *pb;
int waiting_for_timer = 1;
XTime ml_base, ml_new, ml_offset;

extern XEmacIf_Config XEmacIf_ConfigTable[];

struct udp_pcb *pcb;

//init the lwip services
void init()
{
        err_t err;
        macAdress[0] = 0x00;
        macAdress[1] = 0x0A;
        macAdress[2] = 0x35;
        macAdress[3] = 0x00;
        macAdress[4] = 0x22;
        macAdress[5] = 0x21;

        //we need a timer

        //init the lwip parts
        sys_init();

        mem_init();
        xil_printf("heap initialised\r\n");

        memp_init();
        xil_printf("memp initialised\r\n");

        pbuf_init();
        xil_printf("pbuf init done\r\n");

        xil_printf("Wait some time, for initialising\r\n");

        unsigned int init_wait = 15000000;
        while(init_wait--);

        //set the Hardware MAC-Address
        xemacif_setmac(0,(u8_t *) macAdress );

        //set up the ipAddress, Netmask and Gateway
        IP4_ADDR(&gw, 0,0,0,0);
        IP4_ADDR(&ipaddr, 192,168,1,1);
        IP4_ADDR(&netmask, 255,255,255,0);

        //init netif
        netif_init();
        xil_printf("netif_init done\r\n");

        ip_init();

        //tcp_init();

        udp_init();

        //allocate memory for the netif
        networkInterface = (netif*)mem_malloc(sizeof(struct netif));

        //add a new network interface.
        networkInterface = netif_add(networkInterface,
                                                                                        &ipaddr,
                                                                                        &netmask,
                                                                                        &gw,
                                                                                        &XEmacIf_ConfigTable[0],
                                                                                        xemacif_init,
                                                                                        ip_input);

        xil_printf("wait for network to start...\r\n");
        init_wait = 15000000;
        while(init_wait--);

        netif_set_default(networkInterface);

        xil_printf("Network started up!\r\n");

        pcb = udp_new();

        err = udp_bind(pcb, IP_ADDR_ANY, port);
        //err = udp_bind(pcb, &ipaddr, port);

        if (err == ERR_OK)
        {
                xil_printf("NOTICE, Successfuly bound to port\r\n");

        }
        else
        {
                xil_printf("ERROR, Could not bound to port\r\n");
        }

}

void echo_udp_init(void)
{
struct udp_pcb *pcb;

pcb = udp_new();
udp_bind( pcb, IP_ADDR_ANY, port );
udp_recv( pcb, &echo_udp_recv, NULL );
}


static void echo_udp_recv( void* arg, struct udp_pcb *pcb, struct pbuf *p,
struct ip_addr *addr, u16_t port )
{

xil_printf("receive...\r\n");

err_t err;

err = udp_connect( pcb, addr, port );
if (err != ERR_OK)
{
   printf( "ERROR:  udp_connect() error:  %d\n", err );
}
err = udp_send( pcb, p );
if (err != ERR_OK)
{
   printf( "ERROR:  udp_send() error:  %d\n", err );
}
pbuf_free( p );
udp_remove( pcb );
echo_udp_init();
return;
}

int main()
{
   init();

   echo_udp_init();

   // Get the current Time-Base Register Value
   //    offset it by ml_offset
   XTime_SetTime(0);
   XTime_GetTime(&ml_base);
   ml_base += ml_offset;

   while (1) {
      while (waiting_for_timer) {
         xemacif_input(networkInterface);
         XTime_GetTime(&ml_new);
         if ( ml_new >= ml_base ) {
            waiting_for_timer = 0;
            ml_base = ml_new + ml_offset;
         }
      }
      // Call my_tmr() every ml_offset cycles
      my_tmr();
      waiting_for_timer = 1;

   }
   return(1);
}

As far as I understand the raw API, after calling the function
echo_udp_init()
the function echo_udp_recv is registered as a callback function, when a udp
package arrives, the function is then called automatically.

Instead of registering the callback function like udp_recv( pcb,
&echo_udp_recv, NULL ); I tried also udp_recv( pcb, &echo_udp_recv,
networkInterface );
But that didn't work, too.

Does this code not work in the stand-alone version? Do I need to use the
xilkernel?

Hope somebody can help me.

Thanks and regards,
Peter
--
View this message in context: http://www.nabble.com/Xilinx-PowerPC-receive-udp-messages-tf2138912.html#a5902800
Sent from the lwip-users forum at Nabble.com.



_______________________________________________
lwip-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/lwip-users

Attachment: tcp_echo_raw.zip
Description: Zip archive


reply via email to

[Prev in Thread] Current Thread [Next in Thread]