Stateflow Support

Simulink® Code Inspector™ supports a subset of Stateflow® objects for code inspection. The code inspector verifies the use of the supported objects. For the supported objects, some constraints may apply. Before code inspection, when you check the compatibility of your model with code inspection rules, the compatibility checker detects and reports violations of Stateflow constraints. Simulink Code Inspector supports the following Stateflow objects for code inspection:

  • Boxes

  • Charts

  • Data and Events

  • Graphical functions

  • Junctions

  • Non-Atomic Subcharts

  • Simulink functions

  • States

  • Transitions

  • Truth tables

  • For loop constructs, for example:

Stateflow Object Constraints present the Stateflow constraints. For each Stateflow object with a constraint, the section provides:

  • The object name. For information about the object, see Stateflow.

  • Constraints that apply to the object.

For each entry:

  • The Constraint column lists the Simulink Code Inspector constraint on the Stateflow block or object.

  • The FATAL / Nonfatal column identifies whether violation of the constraint terminates code inspection.

    • When you inspect code generated from models with a FATAL incompatibility, code inspection terminates. Code generated from models with FATAL incompatibilities cannot be verified.

    • When you inspect code generated from models with nonfatal incompatibilities, code inspection does not terminate. Although it might not be possible to fully verify the generated code, code inspection continues. The Simulink Code Inspector might partially verify the generated code. You can configure code inspection so that a nonfatal constraint violation terminates code inspection.

  • The Compatibility Check column lists the compatibility check that checks for violation of the constraint, and links to a description of the check.

Structured and Unstructured Types of Control Flow in Stateflow

For supported Stateflow objects, Simulink Code Inspector supports structured control flow, but not unstructured control flow. This is a FATAL constraint, which means violation of this constraint terminates code inspection. The subcheck Check that control flows are structured checks whether the control flow type of your Stateflow chart is supported and reports violation of the constraint.

Control flow in a Stateflow chart is the order of state and transition actions execution when a chart is active. State and transition actions are instructions that you write inside a state or next to a transition to define how a Stateflow chart behaves during simulation. You can use decision making, looping, and branching logic to control the order of actions execution. In structured control flow, the order of actions execution is predictable and specific. In unstructured control flow, the order of actions execution is unpredictable. The unpredictability arises from the use of unpredictable jumps to labels or instruction addresses that are determined at run-time. As a result, the flow of control can:

  • Jump to another junction

  • Skip over a portion of the flow graph

  • Cause an early exit from a branch

Example of Structured Control Flow in Stateflow Chart

This example shows the behavior of structured control flow in a Stateflow chart.

When the condition for transition 1 or 2 is true, the control flow follows transition path 1 and 2 respectively and goes to the terminating junction. When conditions for transition 1 and 2 are false, the control flow follows the transition path 3 and goes to the terminating junction. For every transition there is a specific pathway. There are no unpredictable jumps, skipping or early exit.

Example of Unstructured Control Flow in Stateflow Chart

This example shows the behavior of unstructured control flow in a Stateflow chart.

When conditions for transitions 1 and 2 are false, the control flow skips over the intermediate junction, follows transition path 3, and goes to the terminating junction directly. Because the conditions for transitions 1 and 2 can be evaluated only at run time, it is not possible to predict beforehand whether or not the control flow will go directly to the terminating junction, skipping the intermediate junction.

Related Topics