FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [May 2007 Threads] RAM Usage / ManagementPosted 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 / ManagementPosted 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.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|