Main Content

Generate Code from Atomic Subcharts

To unit test a Stateflow® chart in a Simulink® model, first break the chart into smaller, independent components by using atomic subcharts. When you generate code for your chart, a separate file stores the code for the atomic subchart. Generating reusable code from atomic subcharts is useful for testing individual parts of your Stateflow chart. For more information, see Create Reusable Subcomponents by Using Atomic Subcharts.

Generate Reusable Code for Unlinked Atomic Subcharts

To specify code generation parameters for an unlinked atomic subchart:

  1. In your chart, right-click the atomic subchart and select Properties.

  2. In the dialog box, specify these parameters:

    1. Set Code generation function packaging to Reusable function.

    2. Set Code generation file name options to User specified.

    3. For Code generation file name, enter the name of the file with no extension.

  3. Open the Configuration Parameters dialog box by pressing Ctrl+E.

  4. In the Code Generation tab, set the System target file parameter to ert.tlc.

  5. (OPTIONAL) Customize the generated function names for atomic subcharts. In the Configuration Parameters dialog box, in the Code Generation > Identifiers tab, set the Subsystem methods parameter. Specify the format of the function names by using a combination of these tokens:

    • $R — root model name

    • $F — type of interface function for the atomic subchart

    • $N — block name

    • $H — subsystem index

    • $M — name-mangling text

For more information, see Generate Separate Code for an Atomic Subchart.

Generate Reusable Code for Linked Atomic Subcharts

To specify code generation parameters for linked atomic subcharts from the same library:

  1. Open the library model that contains your atomic subchart.

  2. Unlock the library.

  3. Right-click the library chart and select Block Parameters.

  4. In the dialog box, specify these parameters:

    1. On the Main tab, select Treat as atomic unit.

    2. On the Code Generation tab, set Function packaging to Reusable function.

    3. Set File name options to User specified.

    4. For File name, enter the name of the file with no extension.

  5. In the Code Generation tab, set the System target file parameter to ert.tlc.

  6. (OPTIONAL) Customize the generated function names for atomic subcharts. In the Configuration Parameters dialog box, in the Code Generation > Identifiers tab, set the Subsystem methods parameter. Specify the format of the function names by using a combination of these tokens:

    • $R — root model name

    • $F — type of interface function for the atomic subchart

    • $N — block name

    • $H — subsystem index

    • $M — name-mangling text

When you generate code for your model, a separate file stores the code for linked atomic subcharts from the same library.

Related Topics