Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


task not resumed after taskswitch

Posted by Eddie on April 7, 2006
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.

RE: task not resumed after taskswitch

Posted by Nobody/Anonymous on April 7, 2006
I presume it is calling taskYIELD() in xQueueReceive because it is blocking on the queue to wait for data to become available?

If so, is any data posted to the queue ever again? Maybe the problem is with the data source, rather than the task receiving the data.

RE: task not resumed after taskswitch

Posted by Eddie on April 10, 2006
hmm strange thing.. the more debug info I put out through the uart the more stable the webserver becomes. Is there any logic?

RE: task not resumed after taskswitch

Posted by Eddie on April 11, 2006
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.

void sys_mbox_fetch2(sys_mbox_t mbox, void **msg)
u32_t time;
struct sys_timeouts *timeouts;
struct sys_timeout *tmptimeout;
sys_timeout_handler h;
void *arg;
u8_t iCounter = 0;

timeouts = sys_arch_timeouts();

if (!timeouts || !timeouts->next)

sys_arch_mbox_fetch(mbox, msg, 0);

if (timeouts->next->time > 0)
time = sys_arch_mbox_fetch2(mbox, msg, timeouts->next->time);

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));
/* We try again to fetch a message from the mbox. */
if(iCounter < 2)
goto again;
/* 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;
timeouts->next->time = 0;

RE: task not resumed after taskswitch

Posted by Nobody/Anonymous on April 11, 2006
Stack issues again ;-)

Maybe take a look at the lwIP mail list for answers to your timeout problem?

RE: task not resumed after taskswitch

Posted by Eddie on April 11, 2006
Yes indeed that was part of it. But mainly the timeout caused the hanging and I worked around that.

So if you're the one pointing out to me to check the stack. Thanks for your assistance

[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists