Task stack


For the purpose of saving the FreeRTOS tasks’ stacks before going to sleep we need to know (possibly by using the Task Control Block) where are the stacks of the different tasks and its current size. We are creating all tasks with xTaskCreateStatic so no malloc involved.

Could someone tell me where I can gather this info?


The best way would be to pre sort all static stacks into one contiguous segment via the linker command file unsing the section keyword. That way you do have full control over where the affected memory will be located.

What do you mean by “current size?” DO you want to save only the bytes in use? Why not save the entire stack? If you wnated to do the former, you’d need to traverse the task list and extract the top of stack members from the respective TCBs.

The stacks usually are over dimensioned. One declares a stack of 1 Kbytes and it only uses not even half. And at the moment of going to sleep the stack could be just 100 bytes deep.

What do you mean by “current size?” DO you want to save only the bytes in use?
Yes. the ideal would be just to save what is in use. The reason being, the more one saves the more current will be needed to keep the data.

Where can I find in the TCBs the stack pointer, beginning and current?


Is there any info regarding the Dummy variables inside a TCB?
I think in the past the TCB variables had names that indicated its purpose like


The proper definition of the TCB is inside tasks.c, and only tasks.c is supposed to deal with that structure. There is a reason the ‘public’ definition uses just ‘dummy’ as variable names.

There is a user file that tasks.c can include to add functionality that needs that capability, so you could add it there.