Real-Time Workshop | ![]() ![]() |
Signals with Auto Storage Class
This section discusses options that are available for signals with Auto
storage class. These options let you control signal memory reuse and choose local or global (rtB
) storage for signals.
The Signal storage reuse and Buffer reuse options control signal memory reuse. The Signal storage reuse option is on the Advanced page of the Simulation Parameters dialog box.
When Signal storage reuse is on, the Buffer reuse option becomes enabled. The Buffer reuse option is located on the General Code Generation Options (cont.)
category of the Real-Time Workshop pane. When the Buffer reuse option is selected, signal storage is reused whenever possible.
The Local block outputs option determines whether signals are stored as members of rtB
, or as local variables in functions. This option is in the General code generation options
category of the Real-Time Workshop pane.
By default, both Signal storage reuse and Local block outputs are on.
Note that these options interact. When the Signal storage reuse option is on:
The following code examples illustrate the effects of the Signal storage reuse, Buffer reuse, and Local block outputs options. The examples were generated from the Signals_examp
model (see Figure 5-4).
The first example illustrates maximal signal storage optimization, with Signal storage reuse, Buffer reuse, and Local block outputs on (the default). The output signals from the Sine Wave and Gain blocks reuse rtb_SinSig, a variable local to the MdlOutputs
function.
/* local block i/o variables */ real_T rtb_SinSig; /* Sin Block: <Root>/Sine Wave */ rtb_SinSig = rtP.Sine_Wave_Amp * sin(rtP.Sine_Wave_Freq * rtmGetT(rtM_Signals_examp) + ... rtP.Sine_Wave_Phase) + rtP.Sine_Wave_Bias; /* Expression for <Root>/Out1 incorporates: */ /* Gain Block: <Root>/Gain1 */ /* Outport Block: <Root>/Out1 */ rtY.Out1 = (rtP.Gain1_Gain * rtb_SinSig);
If you are constrained by limited stack space, you can turn Local block outputs off and still benefit from memory reuse. The following example was generated with Local block outputs off and Signal storage reuse and Buffer reuse on. The output signals from the Sine Wave and Gain blocks reuse rtB.temp0
, a member of rtB
.
rtB.temp0 = rtP.Sine_Wave_Amp * sin(rtP.Sine_Wave_Freq * rtmGetT(rtM_Signals_examp) + rtP.Sine_Wave_Phase) + rtP.Sine_Wave_Bias;
/* Gain Block: <Root>/Gain1 */
rtB.temp0 *= rtP.Gain1_Gain;
When the Signal storage reuse option is off, Buffer reuse and Local block outputs are disabled. This makes all block outputs global and unique, as in the following code fragment.
/* Sin Block: <Root>/Sine Wave */ rtB.SinSig = rtP.Sine_Wave_Amp * sin(rtP.Sine_Wave_Freq * rtmGetT(rtM_Signals_examp) + rtP.Sine_Wave_Phase) + rtP.Sine_Wave_Bias; /* Gain Block: <Root>/Gain1 */ rtB.Gain1Sig = rtB.SinSig * rtP.Gain1_Gain;
In large models, disabling Signal storage reuse can significantly increase RAM and ROM usage. Therefore, this approach is not recommended.
Table 5-4 summarizes the possible combinations of the Signal storage reuse/ Buffer reuse and Local block outputs options.
Controlling Stack Space Allocation
When the Local block outputs option is on, the use of stack space is constrained by the following TLC variables:
MaxStackSize
: the total allocation size of local variables that are declared by all functions in the entire model may not exceed MaxStackSize
(in bytes). MaxStackSize
can be any positive integer. If the total size of local variables exceeds this maximum, the Target Language Compiler will allocate the remaining variables in global, rather than local, memory.
MaxStackVariableSize
: limits the size of any local variable declared in a function to N
bytes, where N>0
. A variable whose size exceeds MaxStackVariableSize
will be allocated in global, rather than local, memory.
You can change the values of these variables in your system target file if necessary. SeeTarget Language Compiler Variables and Options for further information.
![]() | Signal Storage Concepts | Declaring Test Points | ![]() |