Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


task ending

Posted by Nobody/Anonymous on August 23, 2006

I want to ask about task ending relevant to freeRTOS + lwIP + ppp thread.
I think that on task stack should be return address. For example in pseudo-code:

void vtask()


When vtask() finish all operations the system will crash. There is no return address to vportYield for example or better to vTaskDelete(NULL)... There was assumed that a task always is infinite loop or is deletted manually from list. I can add this manually of couse but many OS do not require this!


RE: task ending

Posted by David Williams on August 24, 2006
I second the implied request for an automatic TaskDelete() on return from a task!

RE: task ending

Posted by Nobody/Anonymous on August 24, 2006
I see there is necessary to modify tasks.c and port.c (I write for GCC_SAM7):

portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, pdTASK_CODE pxExit, void *pvParameters )
portSTACK_TYPE *pxOriginalTOS;

pxOriginalTOS = pxTopOfStack;

/* Setup the initial stack of the task. The stack is set exactly as
expected by the portRESTORE_CONTEXT() macro. */

/* First on the stack is the return address - which in this case is the
start of the task. The offset is added to make the return address appear
as it would within an IRQ ISR. */
*pxTopOfStack = ( portSTACK_TYPE ) pxCode + portINSTRUCTION_SIZE;

*pxTopOfStack = ( portSTACK_TYPE ) pxExit /*0xaaaaaaaa*/;/* R14 */ <===== LR
*pxTopOfStack = ( portSTACK_TYPE ) pxOriginalTOS; /* Stack used when task starts goes in R13. */
*pxTopOfStack = ( portSTACK_TYPE ) 0x12121212;/* R12 */

tasks.c, TaskCreate:
/* Initialize the TCB stack to look as if the task was already running,
but had been interrupted by the scheduler. The return address is set
to the start of the task function. Once the stack has been initialised
thetop of stack variable is updated. */
pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pvTaskCode, pvTaskExit, pvParameters );

void pvTaskExit() {

another possiblility is to modify port.c only with extern usage for vTaskDelete... (without modyfying taskCreate...)

best regards

RE: task ending

Posted by Nobody/Anonymous on August 24, 2006
in this moment I haven't target for tests but I will check it. Is it possible to work? What do you think?

RE: task ending

Posted by Nobody/Anonymous on August 24, 2006
I have noticed there could be problem with GCC compiler/linker:
Typicaly task is not called from code visibly for compiler because is running from OS task restore. Therefore compiler doesn't add return code!!! (the same is with register storing on the stack!).
The poor way is call task visibly in place which is newer running but it does not look nice...

any ideas?

RE: task ending

Posted by Richard on August 24, 2006
My preference was to structure tasks as:

void vATask( void *pvParameters )
________do task stuff here

____/* We broke out of the loop. */
____vTaskDelete( NULL );

This is explicit in what the behaviour is, portable (try to avoid chaning every port for a feature) and does not require any new kernel code.

However - if I'm in the minority then we can add it to the feature request list.


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

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers


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

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

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner