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

xTaskCreate returns handle on error

Posted by DaveH on June 17, 2011
ATMega644 - WinAVR - FreeRTOS7.0.1
Initially I start only one task and put the micro to sleep. If the start button is pressed, the micro wakes up and then other tasks are started. If the system is then turned off, those other tasks are deleted by the main task and then it goes back to sleep. When I start two additional tasks from the main, I can turn it on and off five times - the sixth time doesn't start properly. If I start only one task, I can turn on/off 10 times before failure. I found that xTaskCreate is returning errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY - obviously I'm doing something wrong to use up memory. So that is my first issue - what am I doing wrong? I do not allocate any memory - only have declared variables. I thought maybe I was putting the micro to sleep before the OS had time to clean up, so I added this:
while (1)
{
num = uxTaskGetNumberOfTasks();
if (num == 2)
break;
vTaskDelay( ( portTickType ) 200 / portTICK_RATE_MS );
}
It appears to drop to two tasks after one loop, which makes sense - I assume the 2nd task is the Idle task. So that doesn't appear to be the problem. Any ideas about why I'm using up memory? Or is more time needed?

The second issue is that I question whether xTaskCreate is working as expected when it returns errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY. Again using uxTaskGetNumberOfTasks() to look at the number of tasks, it appears that the task was not actually created when the error is returned. However, it returns a Handle, which I did not expect - assumed it would return 0 for Handle if not created. I was checking for a non-zero Handle before calling vTaskDelete. When I did this - tried to delete the tasks that weren't really created, it ended up deleting all my tasks - uxTaskGetNumberOfTasks() = 0. Is that how you would expect it to work?

Best Regards,
Dave

RE: xTaskCreate returns handle on error

Posted by Richard on June 17, 2011
I don't think what happens to the task handle when a task cannot be created is specified anywhere - but what actually happens is nothing happens. The task handle is not touched if an error code is returned, so you will get out whatever you put in.

With regards to running out of memory. See the following link: http://www.freertos.org/a00111.html - you will see that the FreeRTOS heap is used when tasks are created to allocate the task stack and TCB, and that if you are using the very simplest memory manager (heap_1.c) you cannot free memory once it is allocated. Also see http://www.freertos.org/a00126.html to get an explanation of when the memory that was allocated for the stack and TCB is freed again once the task has been deleted.

Regards.

RE: xTaskCreate returns handle on error

Posted by DaveH on June 17, 2011
Richard,

Thanks so much for the quick reply. I changed to heap_2 and it works fine, of course. I had built this project on a much simpler earlier project and didn't think about the memory management.

Regards,
Dave


[ 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