I’v been working on porting LWIP to FreeRTOS for the AT91SAM7x with IAR EWARM 5.1. I now have it compiling fine, but LWIP seems to “run away” whenever it receives a packet. For example, if I send it an ARP request, it continues to send ARP responses. It seems to not clear the old receive buffer, so it interprets the buffer over and over as a new packet.
The offending code seems to be in ethernetif.c:
for( ;; )
ethernetif = xNetIf->state;
/* move received packet into a new pbuf */
p = low_level_input( xNetIf );
if( p == NULL )
/* No packet could be read. Wait a for an interrupt to tell us
there is more data available. */
} while( p == NULL );
vEMACWaitForInput() is only run if low_level_input() returns null. I don’t fully understand what low_level_input() does, but it calls ulEMACInputLength() which always returns a length even if a new packet has not been received.
I don’t understand the initial do loop, since it seems to me you would want to do vEMACWaitForInput() and then process what was received instead of trying to receive and only calling vEMACWaitForInput() if that “fails” – which it never does for me after I receive the first packet.
I am hesitant to start changing this code since it seems to work for someone. This is the stock Rowley AT91SAM7x logic in the demo distribution. If someone can explain how this is supposed to work and how it determines whether the data is the buffer is new or not, I would certainly appreciate it.