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

How to restart the task

Posted by kuoping hsu on May 10, 2008
I want to restart a task, but I do not find any of direct way to do it. Currently, I delete the task and re-create it again to restart the task. It will release the memory of stack, and allocate another memory space as stack. If I restart the task several times, it has a risky to cause memory fragmentation. How should I do to restart a task?

RE: How to restart the task

Posted by Dave on May 10, 2008
If (you are using heap_2) && (the stack size allocated to the task is always the same) && (you are not dynamically creating and deleting any other objects (queues for example)) then you should not suffer from fragmentation as the same memory block will just get reused. This is easy enough to test.

RE: How to restart the task

Posted by kuoping hsu on May 11, 2008
Unfortunately, I use malloc function call (Newlib C library) to allocate memory instead of heap_2, and the other task may dynamically allocate memory when the task is restarted. I am not sure the impact of memory fragmentation on the more complicate application, so I need more safe mechanism to restart the task. Actually, I want to implement the plug-ins function in my system. It will stop the task of plug-ins, load the other code to the memory, and restart the task again to run the code of plug-ins. Maybe I can suspend the task and modify the content of TCB or whatever, and resume the task. But, dose exist any simple & portable way to do that?

RE: How to restart the task

Posted by Christopher Coley on May 11, 2008
Why not just modify the code in the task so you can set a flag or send a message to it to cause it to restart. e.g.

boolean fMyTask_Restart;

void MyTask (void *pvParameters)
{
for (;;) {
fMyTask_Restart = FALSE;

/* Any other task initialization here */

while (!fMyTask_Restart) {

/* You main task code here */

}
}
}

Now any time you want to restart the task just set fMyTask_Restart to TRUE. You can also check the flag to make sure the restart occurred.

Chris


[ 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