Everything

APPENDIX D STACK SIZE ESTIMATION


If a stack overflows, the behavior of the system becomes irregular. Therefore, a stack must not overflow referring to this chapter.
D.1 Types of Stack
There are two types of stacks: the user stack and system stack. The method for calculating stack sizes differs between the user stack and system stack.
- User stack
The stack used by tasks is called "User stack". When a task is created by Task Information (task[]), the size and the name of the section where the stack is allocated are specified.
- System stack
The system stack is used by handlers and the kernel. The system has only one system stack. The size is specified by System stack size (stack_size) in System Information (system). The section name of the system stack is "SI".
D.2 Call Walker
The CubeSuite+ package includes "Call Walker" which is a utility tool to calculate stack size.
The Call Walker can display stack size used by each function tree.
D.3 User Stack Size Estimation
The quantity consumed of user stack for each task is calculated by the following expressions.
Quantity consumed of user stack = treesz + ctxsz
- treesz
Size consumed by function tree that makes the task entry function starting point. (the size displayed by Call Walker).
- ctxsz
Size for task context registers. This size is different according to the setting of Task context register (context) in System Information (system). Refer to Table D-1.
Table D-1 Size of Task Context Register
Setting of system.context
Compiler option "-isa"
Size of Task Contest Register
NO
-
68
FPSW
-
72
ACC
"-isa=rxv2"
92
"-isa=rxv1" or not specify "-isa"
76
FPSW,ACC
"-isa=rxv2"
96
"-isa=rxv1" or not specify "-isa"
80
MIN
-
44
MIN,FPSW
-
48
MIN,ACC
"-isa=rxv2"
68
"-isa=rxv1" or not specify "-isa"
52
MON,FPSW,ACC
"-isa=rxv2"
72
"-isa=rxv1" or not specify "-isa"
56

Note Compiler option "-isa" is supported by the compiler CC-RX V2.01 or later.
D.4 System Stack Size Estimation
The system stack is most consumed when an interrupt occurs during service call processing followed by the occurrence of multiple interrupts. The quantity consumed of system stack is calculated by the following expressions.
Quantity consumed of system stack = svcsz
15
+ inthdrsz k
k = 1
+ sysdwnsz
- svcsz
The maximum size among the service calls to be used in the all processing program. The value svcsz depends on the RI600V4 version. For details, refer to release notes.
- inthdrsz
Size consumed by function tree that makes the interrupt handler entry function starting point. (the size displayed by Call Walker).
The "k" means interrupt priority level. If there are multiple interrupts in the same priority level, the inthdrsz k should select the maximum size among the handlers.
The size used by the base clock interrupt handler (the interrupt priority level is specified by Base clock interrupt priority level (IPL) in Base Clock Interrupt Information (clock)) is the maximum value in the following Please refer to the release notes for clocksz1, clocksz2 and clocksz3.
Don't have to add the size used by the base clock interrupt handler when base clock timer is not used (clock.timer = NOTIMER).
- clocksz1 + cycsz
- clocksz2 + almsz
- clocksz3
- cycsz
Size consumed by function tree that makes the cyclic handler entry function starting point. (the size displayed by Call Walker).
If there are multiple cyclic handlers, the cycsz should select the maximum size among the handlers.
- almsz
Size consumed by function tree that makes the alarm handler entry function starting point. the size displayed by Call Walker).
If there are multiple alarm handlers, the cycsz should select the maximum size among the handlers.
- sysdwnsz
Size consumed by function tree that makes the system down routine entry function starting point. (the size displayed by Call Walker) + 40. When the system down routine has never been executed, sysdwnsz is assumed to be 0.