lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] Installed the new version, since all the changes and tu


From: Kieran Mansley
Subject: Re: [lwip-users] Installed the new version, since all the changes and turned on the ASSERT debug
Date: Tue, 20 Mar 2007 13:18:08 +0000

On Tue, 2007-03-20 at 11:22 +0000, Joolz [RSD] wrote:
> My code now stops with the following message.
> 
> Asserion p->flags==PBUF_FLAG_RAM || p->flags==PBUF_FLAG_POOL failed at
> line 487 in lwip2/src/core/pbuf.c
> 
> Now in my code what I do is the following
> 
> ...
> Struct pbuf *data;
> Unsigned char *tempBuffer;
> 
>       data = pbuf_alloc( PBUF_RAW, PAYLOAD_SIZE, PBUF_ROM);
>       tempBuffer = pvMalloc( PAYLOAD_SIZE);
> // Allocate my buffer from my memory
> 
> Now further in the code I need to fill a buffer from a circular buffer
> and if the data does not wrap around I do the following
> 
>       data->payload = currentBufferAddress;
>       udp_send( outUdp, data);
> 
> If the buffer will wrap around I copy the two parts into the temp buffer
> allocated at the start 
>       memcpy( tempBuffer, curren....
>       memcpy( tempBuffer+whatsLeft, ....
>       data->payload = tempBuffer;
>       udp_send( outUdp, data);

As an aside you could avoid this copy by just calling udp_send twice,
once for each fragment. 

> So what is the best way because I don't want to copy the data when I do
> not need to.

The problem is that lwIP needs to stick a UDP and IP header on the front
of the pbuf payload, and for a ROM type of pbuf it can't do this, as it
has no knowledge of what is in memory before the pointer provided.  In
your case for example, there is a good chance that it would overwrite
another packet if it tried to use that space.

If you could arrange for there to be space in front of each fragment you
pass to udp_send() to store the pbuf structure, ethernet, IP and UDP
headers, then you could create your own PBUF_RAM pbuf rather than
allocate a PBUF_ROM pbuf and set the payload as you do above.  Then it
should all work fine.  However, if you're transferring from a circular
buffer then you'll have a problem doing that I think, and so you're
probably going to have to take the hit of a copy.

Kieran







reply via email to

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