xStackCreate

michaeln32 wrote on Monday, January 15, 2018:

Can you please tell me what are the values that initial the stack of a task whae it
create (xTaskCreate) ?

Are those values the general purpose registers ?

rtel wrote on Monday, January 15, 2018:

To my knowledge there is no function xStackCreate().

Each task has its own stack and its own set of MCU registers. When a
task is swapped out (stops executing to allow a different task to run)
the task’s registers are saved onto its stack. When it starts running
again its registers are popped off its stack so it can continue
executing with exactly the same MCU context as when it stopped.

The stack used by a task is created when the task is created, and then
initialized to make it look like the task had been swapped out - so the
values placed onto the stack when the task is created are the values
that the task will pop off the stack into the MCU registers when it
first executes.

michaeln32 wrote on Monday, January 15, 2018:

Richard, Thank you very much.

  1. Are local variables of a task are saves on the task stack too ? If they do, Are the local variables that saved in the stack are saved after the MCU registers or before the MCU registers ?

  2. Where can I find what is the order of the MCU registers are saved in the stack of a task, and what are the registers that are saved ?

Thank you !

Michael

rtel wrote on Monday, January 15, 2018:

Are local variables of a task are saves on the task stack too ? 

Where local variables are saved is completely under the control of the
compiler you are using. FreeRTOS is just C code, compiled along with
the rest of your application - it cannot change how the processor or the
compiler work.

Where can I find what is the order of the MCU registers are saved in
the stack of a task, and what are the registers that are saved ?

Have a look at the port layer source code. The initial stack is created
by vPortInitialiseStack() in each port.c file - but that might not tell
you much (depending on the port). Otherwise look at the code that saves
and restores the context, which will be in the same port.c file or in an
assembly file in the same directory as the port.c file.

michaeln32 wrote on Monday, January 15, 2018:

I have this task:

void Task(void *arg)
{
char stackBufferLcl[100];

while(1)
{
	vTaskDelay(5000);
}

}

When I call the API vTaskList() I see that the stack memory usege has grown in 100 bytes.
So i asume that local varialbes of task do saves in task stack

rtel wrote on Monday, January 15, 2018:

If you want to know where local variables are stored you should consult
your compiler’s manual. 100 bytes its almost certain to go on the
stack. If it were 4 bytes then it would probably be stored in a register.