I've narrowed it down to something with the network connect() statement. I have checked the available network buffers and they are not being depleted.
For an example, the code below will cause a lockup a few minutes to a few hours after bootup. The length of time between occurrences seems to be random. This app has a task that tries to connect as a HTTP client to the first three IPs on the network, looping continually. On my network, x.x.x.1, .2, and .3 are all devices with HTTP servers, so the connect() statement doesn't block for very long. I also have the main task reporting the free buffers, which stays at 262-263. Any idea what may be causing the device to stop?
Code: Select all
#include "predef.h"
#include <stdio.h>
#include <ctype.h>
#include <startnet.h>
#include <autoupdate.h>
#include <dhcpclient.h>
#include <NetworkDebug.h>
#include <tcp.h>
#include <buffers.h>
extern "C" {
void UserMain(void * pd);
}
const char * AppName="Test";
DWORD ConnectionsTaskStack[USER_TASK_STK_SIZE];
typedef union {
unsigned long l;
unsigned char c[4];
} my_ip_union_t;
my_ip_union_t ip_addr;
void ConnectionsTask(void * pd) {
int pass = 0;
ip_addr.l = EthernetIP;
ip_addr.c[3] = 0; //Start at zero, will increment to 1
while(1) {
iprintf("a");
ip_addr.c[3] += 1; //Increment IP
if (ip_addr.c[3] == 4) {
ip_addr.c[3] = 1;
pass++;
iprintf("\r\nPass %i\r\n", pass);
}
iprintf("\r\nTrying: %i.%i.%i.%i ", (int)ip_addr.c[0], (int)ip_addr.c[1], (int)ip_addr.c[2], (int)ip_addr.c[3]);
int fd = 0;
fd = connect(ip_addr.l, 0, 80, TICKS_PER_SECOND * 5); //Block for 5 seconds max
//Would normally read data here
close(fd);
fd = 0;
iprintf("f");
OSTimeDly(20);
}
}
void UserMain(void * pd) {
InitializeStack();
OSChangePrio(MAIN_PRIO);
EnableAutoUpdate();
#ifdef _DEBUG
InitializeNetworkGDB();
OSTimeDly(TICKS_PER_SECOND * 5);
#endif
OSTaskCreatewName(ConnectionsTask, (void *)0, &ConnectionsTaskStack[USER_TASK_STK_SIZE], ConnectionsTaskStack, 42, "ConnectionsTask");
while (1) {
OSTimeDly(20);
iprintf("[%i]", GetFreeCount()); //Check the free buffer count.
}
}