11.07.2015 Views

IAR PowerPac RTOS User Guide

IAR PowerPac RTOS User Guide

IAR PowerPac RTOS User Guide

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

StacksIntroductionThe stack is the memory area used for storing the return address of function calls, parameters, and local variables, aswell as for temporary storage. Interrupt routines also use the stack to save the return address and flag registers, exceptin cases where the CPU has a separate stack for interrupt functions. Refer to the CPU & Compiler Specifics manual of<strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> documentation for details on your processor's stack. A "normal" single-task program needsexactly one stack. In a multitasking system, every task has to have its own stack.The stack needs to have a minimum size which is determined by the sum of the stack usage of the routines in the worstcasenesting. If the stack is too small, a section of the memory that is not reserved for the stack will be overwritten, anda serious program failure is most likely to occur. <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> monitors the stack size (and, if available, alsointerrupt stack size in the debug version), and calls the failure routine OS_Error() if it detects a stack overflow.However, <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> cannot reliably detect a stack overflow.A stack that has been defined larger than necessary does not hurt; it is only a waist of memory. To detect a stackoverflow, the debug and stack check builds of <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> fill the stack with control characters when it iscreated and check these characters every time the task is deactivated. If an overflow is detected, OS_Error() is called.System stackBefore <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> takes over control (before the call to OS_Start()), a program uses the system stack. Thisis the same stack that a non-<strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> program for this CPU would use. After transferring control to the<strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> scheduler by calling OS_Start(), the system stack is used only when no task is executed forthe following:● <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> scheduler● <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> software timers (and the callback).For details regarding required size of your system stack, refer to the CPU & Compiler Specifics manual of <strong>IAR</strong><strong>PowerPac</strong> <strong>RTOS</strong> documentation.Task stackEach <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> task has a separate stack. The location and size of this stack is defined when creating thetask. The minimum size of a task stack pretty much depends on the CPU and the compiler. For details, see the CPU &Compiler Specifics manual of <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> documentation.Interrupt stackTo reduce stack size in a multitasking environment, some processors use a specific stack area for interrupt serviceroutines (called a hardware interrupt stack). If there is no interrupt stack, you will have to add stack requirements ofyour interrupt service routines to each task stack.Even if the CPU does not support a hardware interrupt stack, <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong> may support a separate stack forinterrupts by calling the function OS_EnterIntStack() at beginning of an interrupt service routine andOS_LeaveIntStack() at its very end. In case the CPU already supports hardware interrupt stacks or if a separateinterrupt stack is not supported at all, these function calls are implemented as empty macros.PP<strong>RTOS</strong>-2 97

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!