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

Task within a task - causing crash

Posted by rog57 on March 7, 2013
Hi,

I have a fairly straightforward bit of code as such. The task time for this function in the main loop is set for 50ms.

static void prvReadCOMBufferTaskFunction( void *pvParameters )
{
portTickType xLastCheckTime;
xLastCheckTime = xTaskGetTickCount();

for(;;)
{
vTaskDelayUntil( &xLastCheckTime, check_COM_SIGNAL_RATE );

//check to see if start sequence received (startCycle). If started,
//initiate a task that will validate time taken. should never be
//more than 10-12 seconds from start.
if(startCycle )
{
//launch task to check in 10 seconds to see if completeFlag is set
pdPass = xTaskCreate( prvCommCheckTaskFunction, ( signed char * ) "CommCheck", configMINIMAL_STACK_SIZE, NULL, 2,(xTaskHandle)&CommCheckTask );
sprintf(msgBuf, "pdPass = %i", pdPass); _DBG_(msgBuf);
}

. if(completeFlag)
{
//found end of sequence; Ok to delete the comm check task.
if(CommCheckTask) vTaskDelete( (xTaskHandle) CommCheckTask );
//then process data
processData();
}
}

Here's the function callback for the created function: it's timer is set to 10 seconds

static void prvCommCheckTaskFunction( void *pvParameters )
{
portTickType xLastCheckTime;

// Initialize xLast***Times prior to the first call to vTaskDelayUntil()
xLastCheckTime = xTaskGetTickCount();

for(;;)
{
vTaskDelayUntil( &xLastCheckTime, checkComFlag_RATE );
_DBG_("If you can read this, an incomplet rx buffer was landed.");
if( CommCheckTask ) vTaskDelete( (xTaskHandle) CommCheckTask );
}

}

Here's the problem.
I can run it once and see that it deletes the task.
If I try it a second time - it crashes the program, causing WDT to kick.

Anything obviously wrong that I can change?

Thanks.


RE: Task within a task - causing crash

Posted by Friedrich Lobenstock on March 7, 2013
Sound like you should be using a software timer instead.

Please see:


RE: Task within a task - causing crash

Posted by Richard Damon on March 8, 2013
One question, why are you casting CommCheckTask to a xTaskHandle, it should be one already (and casting &CommCheckTask to one is incorrect).

Also, you need to take some care in deleting a task, as doing so stops it right were it is with NO cleanup, so any resources it creates are not released. In your case if it is in the vTaskDelayUntil call you should be ok, but if that ends and you are starting the _DBG call, that might cause problems.

RE: Task within a task - causing crash

Posted by rog57 on March 8, 2013
Hi, thanks for the help.
Not sure how that cast got in there? I thought most of my code was from FreeRTOS examples, but none of the other tasks have that cast. Thanks for pointing that out.

When you refer to cleanup, are you referring to FreeRTOS, or my code? If my code, yes, I have other stuff, just a few variables to set, which I would do before the delete. At this point I was just getting it to work repetitiously.

The function "prvReadCOMBufferTaskFunction" has been working with no issues at all before the above.

Any other suggestions - or is it just the task handle you think is causing this?






RE: Task within a task - causing crash

Posted by Richard Damon on March 8, 2013
The casts can only cause trouble if CommCheckTask wasn't defined as a xTaskHandle.

For cleanup, I was referring to things like allocating memory in the task, or acquiring semaphores.

One other thought is the code you posted doesn't check that the xTaskCreate call succeeds. It is possible that you run out of memory. A few quick questions, which heap version are you using? Also, is the idle task able to get time to run? In you application it MUST be given time to run, as vTaskDelete does not put the memory from the task back into the heap, but postpones that operation to the idle task. If you have a task, above priority 0, that doesn't block, you will not get your memory freed.

RE: Task within a task - causing crash

Posted by rog57 on March 8, 2013
Sorry, in the loop below it is actually this:

if(completeFlag && !pdPass) (have pdPass declared as well)

I'll add in the idle task and see if that changes anything. Thanks again for pointing that out.

Gr

RE: Task within a task - causing crash

Posted by rog57 on March 8, 2013
friedl - maybe I could use one. I'll read up on that and check it out. Thanks!


[ 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