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 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 ]    [ 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