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




Loading

xTaskRestart() revisited

Posted by westmorelandeng on February 17, 2016

Hello Richard,

You had made this comment - wondering if it was looked into or not:

Please add your request to the feature request tracker in sourceforge. It might be possible for the kernel to call xTaskCreate() on the task again, effectively setting it back to its initial conditions using the same TCB and stack. Regards.

I have a need for something like this - to be able to 'reset' or 'restart' a task. I suppose I could kill it and recreate it - but it would be convenient to restart it.

Thanks, John W.


xTaskRestart() revisited

Posted by rtel on February 17, 2016

This has not been done yet as it is actually quite complex - although the new ability to create tasks using statically allocated memory may make it simpler.


xTaskRestart() revisited

Posted by westmorelandeng on February 17, 2016

Hmmm. OK. I was thinking about just saving off the TCB and orig stack and restoring it - maybe it isn't that easy.

Could a region be defined in heap5.c for a particular task to make this easier?


xTaskRestart() revisited

Posted by westmorelandeng on February 18, 2016

Richard,   Do you have a procedure for how to try this with the statically allocated tasks? Maybe the easiest is to 2X the memory at task creation and restore the TCB and stack at exit if the task is to be reset or just rerun the task creation steps at exit using the original TCB and stack pointers.

Thanks,   John


xTaskRestart() revisited

Posted by rtel on February 18, 2016

I don't think this can be done in a portable way very easily. To truly restart a task (so you get the parameter passed in again, the thread local storage was cleared, etc.) you would need an API function that:

1) Deletes the existing task to ensure it is not referenced from any state lists or other objects. The easiest way of doing that would be to call vTaskDelete().

2) Create a new task so the TCB was re-initialised, the initial stack of the task was set back to its original state, the register values were set back to their initial state, etc. The easiest way of doing that would be to call xTaskCreate() again - however you would not know what the initial value of the task parameter was.

With dynamically allocated memory this is tricky because once the task has been deleted there is no stack, so xTaskCreate() could not be called. However, with statically allocated memory that is not the case, the stack memory can be borrowed between the delete and subsequent re-creation of the task.

In fact, probably the easiest way of doing this would be to allow the RTOS daemon task/timer service task to perform these actions, rather than have the task do it itself. That way you could also do it with dynamic memory allocation.

However, maybe if you really want a task to restart the simplest thing to do would be to have the task jump back up to the start of its implementing function at the appropriate time? You would have to re-initialise any stack variables manually, as the function prologue code would not execute.


xTaskRestart() revisited

Posted by westmorelandeng on February 18, 2016

Richard, So, maybe a taskReset 'hook' can be added?

Thanks, John W.


[ 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