5.1.106. Stack used (psc_StackUsed)

Get the maximum number of bytes used by the stack since power on (or reset).

5.1.106.1. Supported targets

All targets

5.1.106.2. Required license

None (Main library). (See Section 2.3, “Licensed Features”.)

5.1.106.3. Description

Gets the number of bytes used by the application model and platform library since the ECU was last powered on (or reset). The stack is shared area of RAM used to store temporary information, such as calculations and function call parameters.

The total stack size allocated to the application model and platform library can be adjusted through the RTW options, see System stack size. It is important to allocate sufficient stack space for the worst case function call tree through the application and platform code otherwise the ECU may not behave as expected. While developing a model, keep a track of the stack size used and, as the usage grows, grow the system stack size appropriately.

Note

The ECUs are configured by the platform software to reset when the stack overflows its allocation. The reset prevents the ECU from behaving unexpectedly.

When using RTW as the model auto-coder, be aware that RTW has two ways of allocating model data.

  • RTW can statically allocate the data, which means that the model data is allocated to a fixed address in memory and not to the stack. This form of allocation is preferred because at run time the stack usage will be low, and if the model becomes too large for the ECU's memory, the model will fail to build completely.

    Unselect the RTW Enable local block outputs option to have RTW statically allocate model data.

  • RTW can dynamically allocate the data to the stack. This means that the stack use can vary significantly at run time and the system stack size will need to be larger. This form of allocation is not preferred because to guarantee that the stack will not overflow will require detailed analysis of the RTW generated code.

    Select the RTW Enable local block outputs option to have RTW dynamically allocate model data to the stack.

5.1.106.4. Inports

5.1.106.5. Outports

  • used_bytes

    The number of used bytes from the system stack size since the ECU was powered on (or reset). Under simulation, if the Provide simulation inputs parameter isn't ticked, the outport is set to the minimum of its range.

    Range: 0 to system stack size specified in System stack size.

5.1.106.6. Mask parameters

  • Sample time

    The periodicity of the block execution.

    Range: [0.001, 3600] seconds

    Value type:Real
    Calibratable:No
  • Provide simulation inputs

    Tick to enable inport sim_used_bytes.

5.1.106.7. Notes

None.