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

resource wasted on task delete and create

Posted by Sergio Sider on January 15, 2010
Dear All & Richard,

I am using FreeRTOS for a while, and now I bumped into a problem that I need help to figure out:

On an MP3 application, I have the following task:

void vFADERTask (void* pvParameters)
{
char STEP;
for (STEP=0; (STEP<32) && (SYSFLAGS(SS_FLAG_PLAYING)); STEP++) {
wrsta(0x46,STEP);
wrsta(0x48,STEP);
vTaskDelay(60 / portTICK_RATE_MS);
}

if (SYSFLAGS(SS_FLAG_PLAYING)) SYSFLAGS(SS_FLAG_ABORTPLAY)=1;
FADERTaskHandle = NULL;
vTaskDelete(NULL);

}


and, in another part of the program:

//create the Fader Task
if (FaderTaskHandle==NULL) {
if (xTaskCreate( vFADERTask, (signed portCHAR*) "Fader", 64, NULL, 2, &FaderTaskHandle) != pdTRUE) DEBUG_PRINT("CANT CREATE TASK!!!");
} else {
DEBUG_PRINT("Fader task running!");
}

Here's what happens:

It's working fine, until I call it for aproximately 10 times...(plenty of time before each call, so no overlaps)
Then the code to create the task returns != pdTRUE... as there are no resources available

Do I have to clean up anything beyond calling vTaskDelete ?

another 'parallel' thing I noticed is that the Task Handle does not get NULLed by TaskDelete, so I had do it manually (is this a potential problem? so the task could be created before actually deleted ?)

Thank you very much!
Sergio P. Sider

RE: resource wasted on task delete and create

Posted by MEdwards on January 15, 2010
Is the idle task getting any time to execute? The idle task frees up some of the resources after a task delete.

RE: resource wasted on task delete and create

Posted by Sergio Sider on January 15, 2010
Yes... in my case, it's fading out a music that is playing... I was commanding with the keyboard to fade out a music at a time.. so there is plenty of time in theory...

RE: resource wasted on task delete and create

Posted by Sergio Sider on January 15, 2010
Well, I think I may have found the problem, although did not test it:

I am not letting the Idle task run.... because all of my other task are higher priority and not all uses a taskdelay, only taskYIELD or not at all... so if I understood it, if I not call a vTaskDelay inside a higher priority task or something like that, the idle task never gets a chance to run... is that correct ?

RE: resource wasted on task delete and create

Posted by Richard Damon on January 15, 2010
Just calling taskYIELD will not let any lower priority tasks run (so depending on your task setup, more than the Idle task might get starved). You don't need to use just vTaskDelay, a wait on a Queue (including semaphores and Mutexs) with a non-zero max delay parameter can also give time to lower priority tasks (assuming the task at least sometime gets to the Queue when it isn't ready). A task that is designed to use "All remaining available CPU bandwidth" needs to be at the lowest priority that needs to be run.

RE: resource wasted on task delete and create

Posted by Richard Damon on January 15, 2010
A second comment, If you are going to be creating and deleting this task multiple times, and each creation will be doing the same thing, and you don't need a variable number of them at once (which looks like it fits this case), it may be better to create the task once, and have it wait for a semaphore to tell it to start, it does its stuff, and then goes back, reinitialize itself and waits on the semaphore again.

RE: resource wasted on task delete and create

Posted by Sergio Sider on January 16, 2010
Thanks Richard...
I wasn't letting the idle task run at all... one of my tasks was using taskYIELD only, and other was nothing at all... (the remaining tasks were ok, either using mutexes/semaphores and delays).

I actually implemented the "problematic" task in a run once task with semaphore (as you suggested).

Thanks again!
Sergio.


[ 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