Quality RTOS & Embedded Software

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




Loading

Restart task from begining without deleting it?

Posted by a909e on October 18, 2017

I have a static task and a watchdog task that keeps track of all tasks.

~~~ void vTask1() { //Entry point here

StartWatchdog();

//Some function hangs
foo();

//Never reaches here
FeedWatchdog();

} ~~~

Start the watchdog task and for each task there is a count down variable.

If a task has a function that hangs and takes a lot of CPU cycles then the task can't feed/reset the watchdog count down.

Then the watchdog task will be notified of the task hanging.

What is the best way to go from foo() to the entry point if a task hangs?

Is it deleting the task with vTaskDelete() and then using xTaskCreateStatic() again?


Restart task from begining without deleting it?

Posted by heinbali01 on October 18, 2017

What is the best way to go from foo() to the entry point if a task hangs? Is it deleting the task with vTaskDelete() and then using xTaskCreateStatic() again?

That is up to you. I would find it too complicated to restart / restore everything, and rather choose for a CPU reset.

A possible solution is the following: when a task turns out to be hanging, enable the hardware watchdog (WDT) and let it expire as quickly as possible. The CPU will get a reset, and make sure that after rebooting the WDT is not re-enabled. Unless you want to use it, of course.

Also I would store some debug information at a certain place in flash. Store the value of LR of each process, to see where they were hanging out.

Regards.


Restart task from begining without deleting it?

Posted by rtel on October 18, 2017

That is definitely the cleanest way. Other options would be to place an outer loop in the implementation of your task, so the offending task can 'break' out of the normally infinite loop, then go back to the start of the outer loop. Another but more cumbersome option would be for the task use xTimerPendFunctionCall() (http://www.freertos.org/xTimerPendFunctionCall.html ) to pend a function that deletes then re-creates it.


Restart task from begining without deleting it?

Posted by richard_damon on October 19, 2017

One thing to point out that arbitrarily restarting a task is often a very bad thing, as there will be no cleanup of resources for that task (It isn't like aborting a process on a big OS, where the OS tracks most resources and automatically frees them when a process terminates).

You can set a flag that the task checks frequently, and when it sees it, it can then clean up for itself and restart. If it is unable to do that, then unless you know a lot of details about the state of that task, just resetting the task tends to cause issues, and the real solution tends to be you need to reset the full system. (The right solution would be add the needed error checks/time outs to the task to keep it from misbehaving in this way).


[ 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