Hi,
I'm having problems with iwIP as supplied in StarterWare 2.00.00.05 for the AM335x and targeted to the BeagleBone.
I made a very simple change to the example program "enetEcho" to add a periodic broadcast of a UDP packet every 1/2 second.
Here is the code segment with what I added: (in bold)
..... SNIP ......
/* Initialize the sample httpd server. */
echo_init();
struct udp_pcb* pcb = udp_new();
struct pbuf *p;
udp_bind(pcb, IP_ADDR_ANY, 1235);
char msg[80];
int packet = 0;
/* Loop forever. All the work is done in interrupt handlers. */
while(1)
{
packet++;
p = pbuf_alloc(PBUF_TRANSPORT, sizeof(msg), PBUF_RAM); // allocate a pbuf, (ref=1)
if (!p || 1!=p->ref)
{
UARTPuts("pbuf_alloc failed!\n", -1);
while (1) ;
}
sprintf(msg, "test packet %d", packet);
memcpy(p->payload, msg, strlen(msg));
UARTprintf("packet %d, PBuf at 0x%08X, ref = %d sending...", packet, p, p->ref);
udp_sendto(pcb, p, IP_ADDR_BROADCAST, 1234);
delay(500); // half second delay - should have plenty of time to send
UARTprintf("ref is now %d \n", p->ref);
pbuf_free(p); // ref should be zero after we free.
}
}
This works great for about 30 packets or so. Then suddenly they stop being sent. Below is a typical output:
StarterWare AM335x Boot Loader
Copying application image from MMC/SD card to RAM
Acquiring IP Adress...
EVM IP Address Assigned: 192.168.9.106packet 1, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 2, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 3, PBuf at 0x80018060, ref = 1 sending...ref is now 1
.... and so on....
packet 21, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 22, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 23, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 24, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 25, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 26, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 27, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 28, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 29, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 30, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 31, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 32, PBuf at 0x80018060, ref = 1 sending...ref is now 1
packet 33, PBuf at 0x80018060, ref = 1 sending...ref is now 2
packet 34, PBuf at 0x80018100, ref = 1 sending...ref is now 2
packet 35, PBuf at 0x800181a0, ref = 1 sending...ref is now 2
packet 36, PBuf at 0x80018240, ref = 1 sending...ref is now 2
I can monitor the packets on the wire, and in this case, the last one sent was number 32. This is consistient with the reference count not being decremented on packet 33. Sometimes it will make it to 50 packets before the stack dies, but never much longer.
Further investigation revealed that the interrupt handler that should be called after transmission stops being called after so many packets... But why? Any Ideas would be very welcome! I hope I haven't made some silly assumption on the use of lwIP under StarterWare.
Cheers,
-Jay