When I integrated this code into my code I found a strange error. 0x4000 was being inserted in the same place in random ethernet packets. After a lot of investigation I found my culprit – code I got from the demo code.
~~~~
static void prvRxHandler( void
pvNetIf )
{
/ This is taken from lwIP example code and therefore does not conform
to the FreeRTOS coding standard. */
struct eth
hdr *pxHeader;
struct pbuf *p;
unsigned short usInputLength;
static unsigned char ucBuffer[ 1520 ] attribute((aligned(32)));
extern portBASETYPE xInsideISR;
struct netif *pxNetIf = ( struct netif * ) pvNetIf;
XIntc_AckIntr( XPAR_AXI_ETHERNETLITE_0_BASEADDR, XPAR_AXI_ETHERNETLITE_0_IP2INTC_IRPT_MASK );
/* Ensure the pbuf handling functions don't attempt to use critical
sections. */
xInsideISR++;
usInputLength = ( long ) XEmacLite_Recv( &xEMACInstance, ucBuffer );
…
~~~~
This code is from lwIP/netif/ethernetif.c
The line
XIntc_AckIntr( XPAR_AXI_ETHERNETLITE_0_BASEADDR, XPAR_AXI_ETHERNETLITE_0_IP2INTC_IRPT_MASK );
is designed to acknowledge the interrupt but it writes to the Ethernet peripheral instead of the interrupt controller. The place where it writes is in the middle of the outgoing buffer and the MASK has the value of 0x4000 in my code (it may be different in different systems).
The solution is to remove this line entirely as the interrupt acknowledgement is done in the interrupt controller driver and thus the line was irrelevant anyway.
Hopefully this will stop people getting mystery errors in the future.
Thanks,
Tim