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

Deleting task and creating again

Posted by Hemang on February 19, 2012
I am in a process of creating software watchdog using software timers. I need to monitor current status and if any task takes long time then I want to delete that task and recreate it. Can someone help me with this???

RE: Deleting task and creating again

Posted by Richard Damon on February 19, 2012
I am not sure you really want to do that. There are a couple of issues with this.

1) Forcefully just terminating a task will not release any resources owned by it, especially any mutexs or dynamic memory.

2) If there is a problem that is causing a task to take to long, just reseting it isn't apt to fix whatever real problem caused that to happen.

If you really want to do this, the simplest would probably just have each task as part of its loop write the current timer tick into a mail box (distinct for each task), and have a periodic task/timer hook scan the list and delete any task that has gotten too old. You will have to watch out in this case for any task that isn't activated often enough.

If you only want to look at elapsed time since they "started" an operation, then you could have too mailboxes. one for the start time, and a second for having completed. This assumes that once a task gets a "request" there shouldn't be any other significant delays. Here right after the task gets the request, it sets the start time and clears the completed flag. When it finishes, just before waiting for another operation, set the completed flag. Now the watchdog only wants to see if any non-completed task has gotten too old.

RE: Deleting task and creating again

Posted by Hemang on February 20, 2012
I have tried that mechanism which monitors counters for each task and timer routine. I want to delete that task and restart the same task. Can you help me with recreating same task

RE: Deleting task and creating again

Posted by Richard Damon on February 20, 2012
You need to remember how to create the thread. If you are just checking on or two, you can just replicate the code. If you want it to be a bit more general purpose, than you probably want all these flags to be in an array (either an array of structs, with each task being an array element and the struct having the data for each task, or just a set of arrays and a given task has a common index), and you save either the data needed to recreate the task (name, priority, stack size, task function address, parameter), or a address of a function to create the task.

RE: Deleting task and creating again

Posted by Hemang on February 21, 2012
The main function looks like mentioned below

int main(){

.....
/* Create timers and tasks*/



xTimer_soft_WD = xTimerCreate((const signed char*)"soft_WD",
(SOFT_WD_TICKS),
pdTRUE,
(void *) 0,
soft_WD);




xTaskCreate( eth_task,
(signed portCHAR *)"eth_task",
configMINIMAL_STACK_SIZE * 2.5,
NULL,
tskIDLE_PRIORITY + 1,
ðTaskHndl );

xTaskCreate( ser_task,
(signed portCHAR *)"serial_task",
configMINIMAL_STACK_SIZE/5,
NULL,
tskIDLE_PRIORITY + 1,
&serTaskHndl );




xTimerStart( xTimer_soft_WD,portMAX_DELAY );



/* Start the scheduler. */
vTaskStartScheduler();
.....

Soft_WD timer routine looks like below which basically monitors task and if some task takes too long to finish execution then I am using the below steps to delete task and creating it again. The task create function call is the same which I have used in main function. But, it doesnot work here and system hangs up.


vTaskSuspendAll();
vTaskDelete(ethTaskHndl);
xTaskCreate( eth_task,
(signed portCHAR *)"eth_task",
configMINIMAL_STACK_SIZE * 2.5,
NULL,
tskIDLE_PRIORITY + 1,
ðTaskHndl );
xTaskResumeAll();


RE: Deleting task and creating again

Posted by Richard Damon on February 22, 2012
First a side point, why does the serial task get configMINIMAL_STACK_SIZE/5 for its stack size, why does it need so much less stack than the idle task? This could be the source of your problem if it i is corrupting things.

Your code should recreate the eth task properly. Of course, what ever is making it take too long hasn't been fixed, and if that problem has been caused by some sort of corruption, who knows what will be happening.


[ 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