Quality RTOS & Embedded Software

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




Loading

ATMega2560 reset when exiting task

Posted by Jesper Matthiesen on June 17, 2008
Hi,

i have 3 tasks running and a shutdown condition that causes every task to exit its main loop. if i after the main loop have each task enter an infinite loop, everything is fine; if *any* one of them exit out of the task function, the device reboots.. this also happens when only running 1 task and at any stack size.. watch dog is turned off...

since the kernel, according to the documentation, never exits vTaskStartScheduler unless vTaskEndScheduler is called, what happens to tasks that return? do they just end as one would expect with the scheduler continuing? maybe it's when the idle task tries to do post-task cleanup that the device crashes/reboots? im using heap_1.c by the way...


RE: ATMega2560 reset when exiting task

Posted by Dave on June 17, 2008
From the WEB "Task functions should never return so are typically implemented as a continuous loop".

If you want to leave a task then you have to write something like this -

void TaskFunction(void *pv)
{
while(1)
{
// task code that contains a break to jump out of the loop.
}

// Must not run off end of function so delete ourselves.
vTaskDelete(NULL);
}

RE: ATMega2560 reset when exiting task

Posted by JMR on June 17, 2008
Further to davedoors' comment:
The tasks are simply functions when you create a task at start-up all you do is put a pointer to the functions entry point in the TCB list of the scheduler.
When the function then terminates, unless you explicitely call vTaskDelete(NULL) the function exit will cause a stack underflow, that is items that hadn't been pushed on the stack get popped and the program counter made to point somewhere in oblivion. Resulting in the reset that you observed.

RE: ATMega2560 reset when exiting task

Posted by Jesper Matthiesen on June 17, 2008
great advice...

since vTaskDelete can be omitted from the build to save space, i probably will put a "for ( ;; );" at the end of the tasks in question instead..

thanks..

RE: ATMega2560 reset when exiting task

Posted by Dave on June 17, 2008
If you never want the task to run again and don't want to free the memory it is using you can instead use vTaskSuspend(NULL); This will prevent the task using CPU time, unlike the for(;;) solution.

RE: ATMega2560 reset when exiting task

Posted by Jesper Matthiesen on June 17, 2008
it's not that important if the tasks use cpu or not when entering shutdown.. i tried the vTaskSuspend ( NULL) option anyway (since i have it included in the build already), but this trigs a spontaneous device reboot in about 50% of cases also, which i find very strange...


[ 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