embOS实时操作系统 - 堆栈 < Cortex M >

 

The stack has the same function as in a single-task system:

storage of return addresses of function calls,
parameters and local variables,
and temporary storage of intermediate calculation results and register values.

 

embOS实时操作系统 - 堆栈 < Cortex M >

Task stack for Cortex M

All embOS tasks execute in thread mode using the process stack pointer. <PSP>

Each embOS task has a separate stack. The location and size of this stack is defined when creating the task

The stack itself is located in any RAM location.
Each task uses its individual stack.
The stack poiter is initialized and set every time a task is activated by the scheduler.
The stacksize required for a task is the sum of the stack-size of all routines
plus a basic stack size plus size used by exceptions.

The basic stack size is the size of memory required to store the registers of the CPU
plus the stack size required by calling embOS-routines.

For the Cortex M CPUs, this minimum basic task stack size is about 72 bytes.
Because any function call uses some amount of stack and
every exception also pushes at least 32 bytes onto the current stack,
the task stack size has to be large enough to handle one exception too.

We recommend at least 256 bytes stack as a start.

When Cortex M4F CPUs with VFPv4 are used,
keep in mind that the VFP registers may be pushed onto the stack
and will require additional 136 bytes of stack.

 

System stack for Cortex M

The embOS system executes in thread mode, the scheduler executes in handler mode.

The scheduler and OS_Idle() execute using the main stack pointer. <MSP>

The minimum system stack size required by embOS is about 136 bytes (stack check & profiling build)
However, since the system stack is also used by the application before the start of multitasking (the call to OS_Start()),
and because software-timers and .C.-level interrupt handlers also use the system-stack,
the actual stack requirements depend on the application.

The size of the system stack can be changed by modifying the CSTACK size in your *.icf file.

We recommend a minimum stack size of 256 bytes for the CSTACK.

Using a Cortex M4F CPU with floating point unit may require more stack,
because the floating point registers might be saved on the system stack also.

Interrupt stack for Cortex M

If a normal hardware exception occurs, the Cortex M core switches to handler mode which uses the main stack pointer.<MSP>

With embOS, the main stack pointer is initialized to use the CSTACK which is defined in the linker command file.
The main stack is also used as stack by the embOS scheduler and during idle times, when no task is ready to run and OS_Idle() is executed

 

<PSP>  initialized and set every time a task is activated by the scheduler <Task Stack>

<MSP> initialized from vector_table[0] < CSTACK >

            for the embOS system<Software Timers(and callback)>the embOS scheduler, OS_Idle(),  and hardware exception 

 

你可能感兴趣的:(操作系统)