ST10R272L - SYSTEM PROGRAMMING
307/320
The effect of the address transformation, is that the physical stack addresses
wraps around
- from the end of the defined area to its beginning. When flushing and filling the internal
stack, the Circular Stack Mechanism requires only the portion of stack data which is really to
be re-used, to be moved (i.e. the upper part of the defined stack area). It does not require the
whole stack area to be moved. Stack data that remains in the lower part of the internal stack
need not be moved by the distance of the space being flushed or filled, as the stack pointer
automatically wraps around to the beginning of the freed part of the stack area.
Note
This circular stack technique is applicable for stack sizes of 32 to 256 words
(STKSZ = ‘000b’ to ‘0116b’), it does not work with option STKSZ = ‘111b’, which
uses the complete internal RAM for system stack.
When a boundary is reached, the stack underflow or overflow trap is entered, where the user
moves a predetermined portion of the internal stack to or from the external stack. The
amount of transferred data is determined by the average stack space required by routines,
and the frequency of calls, traps, interrupts and returns. In most cases this will be
approximately one quarter to one tenth of the size of the internal stack. Once the transfer is
complete, the boundary pointers are updated to reflect the newly allocated space on the
internal stack. Thus, the user is free to write code without concern for the internal stack
limits. User programs are only affected by the execution time required by the trap routines.
The following procedure initializes the controller to use of the circular stack mechanism:
•
Specify the size of the physical system stack area within the internal RAM (bitfield
STKSZ in register SYSCON).
•
Define two pointers, which specify the upper and lower boundary of the external
stack. These values are then tested in the stack underflow and overflow trap routines
when moving data.
•
Set the stack overflow pointer (STKOV) to the limit of the defined internal stack area
plus six words (for the reserved space to store two interrupt entries).
The internal stack fills until the overflow pointer is reached. After entry into the overflow trap
procedure, the top of the stack is copied to the external memory. The internal pointers are
modified to reflect the newly allocated space. After exiting from the trap procedure, the
internal stack wraps around to the top of the internal stack, and continues to grow until the
new value of the stack overflow pointer is reached.
When the underflow pointer is reached while the stack is emptied the bottom of stack is
reloaded from the external memory and the internal pointers are adjusted accordingly.
PUSH R1
;(SP) =
F800h: Physical stack address = FA00h
PUSH R2
;(SP) =
F7FEh: Physical stack address = FBFEh
MOV SP, #0F802h
;Set SP before last entry of physical stack of 256 words