This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

What is the purpose of a Task Stack?

Other Parts Discussed in Thread: CODECOMPOSER

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)

Xds560 emulator

CodeComposer Studio v3.3

DSP/BIOS RTOS

  • Naveed,

    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.

    Scott

  • Thanks a lot for the helpful information. I still seem to be stuck.

    Background:

    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.

    Problem:

    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?

  • Naveed,

    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?

    Scott