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

RAM Usage / Management

Posted by Scott Nortman on May 17, 2007
Hi,

How does one know how much stack space to allocate to each task? Also, what about the configTOTAL_HEAP_SIZE option? How is the heap size related to the memory allocation scheme?

Thanks,
Scott Nortman

RE: RAM Usage / Management

Posted by Richard on May 18, 2007
The amount of stack required by a task is completely dependent on the implementation of the task. The following items will increase the amount of stack the task requires:

1) High function call nesting depth.

Each time a function is called data is saved to the stack.

2) Local, non static variables. Each of which is allocated stack space. This is why you should not declare large structures or arrays as local variables (unless you make them static).

When a task is created its stack is set to 0xa5, so you can always check the high water mark by viewing the memory in a debugger. The location of the currently used stack can be obtained from the stack pointer of the processor you are using. Alternatively, using the debugger you can inspect the pxCurrentTCB pointer, which is a pointer to the TCB. The pxCurrentTCB->pxStack member points to the start of the stack used by the task. The pxCurrentTCB->pxTopOfStack points to the top of the stack as it was the last time the task entered the Running state.

Also take a look at the function usTaskCheckFreeStackSpace() in tasks.c, this can be used to return the task high water mark. The lower the number returned the closer the task has come to overflowing its stack.




configTOTAL_HEAP_SIZE defines the size of the block of memory available to the memory allocator used by either the heap_1 or heap_2 schemes. Memory is grabbed from this pool each time a task or queue is created. Take a look here: http://www.freertos.org/a00111.html if you have not already seen it.

Regards.


[ 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