Quality RTOS & Embedded Software

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




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) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

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