TI E2E Community
What is the purpose of a Task Stack?
Hi, I have been reading different documents on this subject and none of them have managed to explain the following:
A. When exactly is a Task stack created? (e.g. when I enter a task, when I post it, or when I am exiting it. Some tutorial said that it is created for storing the context when the TASK IS BEING EXECUTED. I don't quite get why you need to make a stack for that if the variables are already global)
B. What exactly are the contents of such a stack.
C. If I am calling x number of functions from within a task, how does that affect the task stack
I am using the following:
DM6446 (custom board)
CodeComposer Studio v3.3
A. A task’s stack is allocated when the task is created.
Yes, a task’s stack holds context for the task execution. When a task is preempted by another task, or if the task blocks (for example, with a SEM_pend()), then the task’s context is *maintained* on its stack until the task executes again.
A task can use both global variables (that aren’t maintained in the task’s stack), or it can use task-local variables, that are maintained on the task’s stack.
B. The context on the task's stack is local variables for the task’s function, as well as the execution stack for any other functions that the task’s function calls.
C. As you call functions they will consume space on the task’s stack. If you call them one at a time, the task stack depth will rise/fall for each function call. If you have functions that call other functions, the depth will increase with each nested function call. The space required for each task can vary, and can be specified during task creation. Usually a larger stack size will be allocated to begin with, and then tuned downward later in development as stack size requirements are determined.
Thanks a lot for the helpful information. I still seem to be stuck.
I am running audio compression (MELP) in a task that is posted from the interrupt routine that is catering for interrupts from the DMA. The DMA is linked with the ASP and is configured for interrupting after every 2ms. Each data sample collected after 2ms has 16 good voice samples, each 16 bits wide.
Once 180 (or more) samples are collected, the task is posted. This seemed to run fine.
It takes exactly 22.5ms to collect 180 samples and the compressor takes, averaging, 21~21.5 ms. So the realtimeness is not hurt.
The task is structured as follows:
The task calls a copy function and then calls the compressor on the copied data. The compressor nests function calls to up to 4 levels.
I had to optimize the code further so I configured the DMA to interrupt me every 125 us (microseconds). The problem I am facing now is that the entire code crashes and the reason, as far as I have been able to figure out, is that the stack for the compressor task overflows.
The only effect of increasing the interrupt rate on this task is that now it is preempted 16 times more than before.
The effective function calls, task posts and nesting have not changed.
What could be causing this issue?
Can you describe how you are configuring and handling the DMA interrupt? Are you using the HWI dispatcher or the HWI_enter/HWI_exit macros?
All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.
TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs andembedded processors, along with software, tools and the industry’s largest sales/support staff.