Products & Services Solutions Academia Support User Community Company

Learn more about Real-Time Workshop   

Signals with Auto Storage Class

Options are available for signals with Auto storage class:

Use these options to control signal memory reuse and choose local or global (model_B) storage for signals. The Signal storage reuse option is on the Optimization pane of the Configuration Parameters dialog box, as shown in the next figure.

When you select Signal storage reuse, the Enable local block outputs, Reuse block outputs, Eliminate superfluous local variables (Expression folding), and Minimize data copies between local and global variables options in the Code Generation section of the dialog box are enabled.

These options interact. When the Signal storage reuse option is selected,

The following code examples illustrate the effects of the Signal storage reuse, Enable Local block outputs, Reuse block outputs, Eliminate superfluous local variables (Expression folding) and Minimize data copies between local and global variables options. The examples were generated from the signal_examp model (see figure Signal_examp Model).

The first example illustrates signal storage optimization, with Signal storage reuse, Enable Local block outputs, Reuse block outputs, and Minimize data copies between local and global variables selected. (For clarity in showing the individual Gain and Sum block computation, expression folding is off in this example.) The output signal from the Sum block reuses signal_examp_Y.Out1, a variable local to the model output function.

/* Model output function */
static void signal_examp_output(int_T tid)
{
  /* Sum: '<Root>Sum' incorporates:
   *  Constant: '<Root>/Constant'
   *  Inport: '<Root>>/In1'
   */
  signal_examp_Y.Out1 = signal_examp_U.In1 + signal_examp_P.Constant_Value;
  
  /* Gain: '<Root>/Gain' */
  signal_examp_Y.Out1 = signal_examp_P.Gain_Gain * signal_examp_Y.Out1;

  /* tid is required for a uniform function interface.
   * Argument tid is not used in the function. */
  UNUSED_PARAMETER(tid);
}

If you are constrained by limited stack space, you can turn Enable local block outputs off and still benefit from memory reuse. The following example was generated with Enable local block outputs cleared and Signal storage reuse, Reuse block outputs, and Minimize data copies between local and global variables selected. The output signals from the Sum and Gain blocks use global structure signal_examp_B rather than declaring local variables and in both cases the signal name is gainSig.

/* Model output function */
static void signal_examp_output(int_T tid)
{
  /* Sum: '<Root>/Add' incorporates:
   *  Constant: '<Root>/Constant'
   *  Inport: '<Root>/In1'
   */
  signal_examp_B.gainSig = signal_examp_U.In1 + 
    signal_examp_P.Constant_Value;

  /* Gain: '<Root>/Gain' */
  signal_examp_B.gainSig = signal_examp_P.Gain_Gain * 
    signal_examp_B.gainSig;

  /* Outport: '<Root>/Out1' */
  signal_examp_Y.Out1 = signal_examp_B.gainSig;
  
  /* tid is required for a uniform function interface.
   * Argument tid is not used in the function. */
  UNUSED_PARAMETER(tid);
}

When the Signal storage reuse option is cleared, Reuse block outputs, Enable local block outputs, and Minimize data copies between local and global variables are disabled. This makes the block output signals global and unique, signal_examp_B.sumSig and signal_examp_B.gainSig, as shown in the following code.

/* Model output function */
static void signal_examp_output(int_T tid)
{
  /* Sum: '<Root>/Add' incorporates:
   *  Constant: '<Root>/Constant'
   *  Inport: '<Root>/In1'
   */
  signal_examp_B.sumSig = signal_examp_U.In1 + 
    signal_examp_P.Constant_Value;

  /* Gain: '<Root>/Gain' */
  signal_examp_B.gainSig = signal_examp_P.Gain_Gain * 
    signal_examp_B.sumSig;

  /* Outport: '<Root>/Out1' */
  signal_examp_Y.Out1 = signal_examp_B.gainSig;

  /* tid is required for a uniform function interface.
   * Argument tid is not used in the function. */
  UNUSED_PARAMETER(tid);
}

In large models, disabling Signal storage reuse can significantly increase RAM and ROM usage. Therefore, this approach is not recommended for code deployment; however it can be useful in rapid prototyping environments.

The following table summarizes the possible combinations of the Signal storage reuse / Reuse block outputs and Enable local block outputs options.

Signal storage reuse and Reuse block outputs ON

Signal storage reuse OFF
(Reuse block outputs disabled)

Enable local block outputs ON

Reuse signals in local memory (fully optimized)

N/A

Enable local block outputs OFF

Reuse signals in model_B structure

Individual signal storage in model_B structure

Controlling Stack Space Allocation

When the Enable local block outputs option is on, the following TLC variables constrain the use of stack space by local block output variables:

You may need to adjust the settings of these variables when working with models that contain large signals. When a variable exceeds MaxStackVariableSize, the Real-Time Workshop product places the variable in global memory space. Similarly, if the accumulated size of variables in local memory exceeds MaxStackSize, the product places subsequent local variables in global memory space. The Real-Time Workshop product analyzes the accumulated size of local variables based on a worst-case scenario without taking into account that local variables are released after functions return.

Consider the following options for your specific model:

See Setting Target Language Compiler Options for more information.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS