lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] Re: [lwip] Use with a microcontroller


From: Adam Dunkels
Subject: [lwip-users] Re: [lwip] Use with a microcontroller
Date: Wed, 08 Jan 2003 22:07:08 -0000

On Monday 05 November 2001 17.21, you wrote:
> I will synchronize with CVS first, then adapt my ARP, DHCP and CS8900a
> layers to lwIP. I must
> say the layers seems to fit each other very well, although the most work
> will be to insert and
> extract to pbufs from the network drivers.

Great! The pbufs are quite easy to handle. Each pbuf has a ->payload pointer 
that points to the data carried in the pbuf. The ->len pointer contains the 
length of the data. 

Pbufs can be chained together, meaning that the data is spread over a number 
of pbufs. In such cases, the ->next pointer points to the next pbuf in the 
chain (or NULL if the pbuf isn't chained). Sending data from a pbuf is as 
simple as this:

struct pbuf *p, *q;

for(q = p; q != NULL; q = q->next) {
   send_data(q->payload, q->len); 
}

Where "p" is the pbuf that should be sent and the send_data() function is 
assumed to send the data to the NIC.

For incoming packets, pbufs are best allocated from the pbuf pool. Such pbufs 
are chains of fixed size pbufs that can be allocated quickly. Reading a 
packet can look like this:

  p = pbuf_alloc(PBUF_LINK, len, PBUF_POOL);
  
  if(p != NULL) {
    /* We iterate over the pbuf chain until we have read the entire
       packet into the pbuf. */
    for(q = p; q != NULL; q = q->next) {
      /* Read enough bytes to fill this pbuf in the chain. The
         avaliable data in the pbuf is given by the q->len
         variable. */
      read_data(q->payload, q->len);
    }

Where "len" is the length of the incoming packet.

In the latest CVS development code (avaliable at the "download" section of 
the lwIP homepage), there is a network interface driver skeleton for Ethernet 
interfaces: src/netif/ethernetif.c

> I've a CS8900a driver fully working, with both a immediate interrupt
> handler and a
> "late" handler, running outside of the interrupt mode. It's been tested in
> the field for several
> months now. Unable to crash it, even with flooding and very overcrowded
> networks.
>
> I feel confident the code complements lwIP very good. I'll ask whether I
> may release it
> to the public.

That would be very appreciated! I have a CS8900a driver that is half finished 
(doesn't work for more than 10 seconds...), but your code is probably better! 

/adam
-- 
Adam Dunkels <address@hidden>
http://www.sics.se/~adam
[This message was sent through the lwip discussion list.]




reply via email to

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