I have freertos 4.0.0 with the lwip tcp/ip stack version 1.1.1. I have a task that gets a website from a sd-card on a request on port 80 and sends it to the client. I’m using the at91sam7x256 port for rowley commandline.
The webserver task at random points stops sending data to the client. Sometimes it stops after sending a few KB and sometimes after a few MB.
Besides this task there is the errorcheck and the tcp/ip stack task. Those both stay alive. The led keeps flashing and my board is still pingable.
I’ve found that my webserver fails in this function:
signed portBASE_TYPE xQueueReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait )
When calling the taskYIELD(); function.
The taskYIELD function is a define of portYIELD();, which is a define for asm volatile ("SWI");
SWI is the assembly instruction for the software interrupt.
At this point the os wil switch to a task with a higher priority wich has something to do. After that it wil never handle my webservertask again.
The task is still visible in the tasklist.
Okay finaly making progress. While debugging with the tasklist over the uart I saw that the stack of
the webeserver task decreased. After increasing the stack at init from 250 to 500 it remained stable. But it didn’t yet solve the problem. \
What happend was that after the taskyield it came in a timout loop. In the file sys.c of the ip-stack. in the function sys_mbox_fetch(…)
I implemented a counter which after 2 timeouts leaps out of this function. This solves the hanging.
if (timeouts->next->time > 0)
{
time = sys_arch_mbox_fetch2(mbox, msg, timeouts->next->time);
}
else
{
time = SYS_ARCH_TIMEOUT;
}
if (time == SYS_ARCH_TIMEOUT)
{
/* If time == SYS_ARCH_TIMEOUT, a timeout occured before a message
could be fetched. We should now call the timeout handler and
deallocate the memory allocated for the timeout. */
tmptimeout = timeouts->next;
timeouts->next = tmptimeout->next;
h = tmptimeout->h;
arg = tmptimeout->arg;
memp_free(MEMP_SYS_TIMEOUT, tmptimeout);
if (h != NULL)
{
LWIP_DEBUGF(SYS_DEBUG, ("smf calling h=%p(%p)\n", (void *)h, (void *)arg));
h(arg);
}
/* We try again to fetch a message from the mbox. */
iCounter++;
if(iCounter < 2)
goto again;
}
else
{
/* If time != SYS_ARCH_TIMEOUT, a message was received before the timeout
occured. The time variable is set to the number of
milliseconds we waited for the message. */
if (time <= timeouts->next->time)
{
timeouts->next->time -= time;
}
else
{
//AT91C_BASE_PIOB->PIO_CODR = LED3;
timeouts->next->time = 0;
}
}
}
}