How are stacks allocated during task creation in ARM 7TDMI architecture, as I understand the stack areas are created during startup in the boot code for each mode. Now, during creation of a task , what more happens ? I am aware that the TCB space is allocated from the heap but what about the task stack ? What is the necessity of explicitly allocating a stack space after allocationg it in the startup code anyway. I believe during an RTOS tick or an interrupt the stack pointer of the current mode of the processor will be used anyway to save context . Could someone point out in which section of the source code we have the part which reserves stack space on task creation ? What I missing out here ? Thanks in advance .
First, the reason you need a stack for each task is to have a place to store the state of each task, including all the auto variables used by that task. The stacks are set up inside of the Create Task function, and the Yield function does the actual stack switching.
The function call in task.c says it all. prvAllocateTCBAndStack() this calls pvPortMalloc() this is pretty easy to find if you review task.c I found it helps to understand how the first task is set up and how is stack is prepared. Note that the first task is started as if returning from the context pushed by pxPortInitialiseStack. Review pxPortInitialiseStack in the port.c file. If this initial stack frame is setup correctly, (and it is easy to debug with any debugger since no interrupts yet) your port of FreeRTOS will run. Lastly review a sample portSAVE_CONTEXT() to understand the difference between the Arm and FreeRTOS task stacks. Richard did a nice job commenting the source, I think you questions are best answered there. David.
Thanks for your answers , I will definitely work on this . I admit I am new to this as of now . If I get a hang of this , I would like to make some contribution in the form of documentation , where I would like to describe the function call flow during initialisation, the stack usage , basically how the RTOS initialises . I am not sure when really :) but I would definitely try it . Right now I might not be able to understand the scheduler functionalities , so cant promise documentation on those . Would such a contribution be accepted ?
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.