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, seeCreate Reusable Subcomponents by Using Atomic Subcharts(Stateflow).

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 selectProperties.

  2. In the dialog box, specify these parameters:

    1. SetCode generation function packagingtoReusable function.

    2. SetCode generation file name optionstoUser specified.

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

  3. Open the Configuration Parameters dialog box.

  4. In theCode Generationpane, set theSystem target fileparameter toert.tlc.

  5. (OPTIONAL) Customize the generated function names for atomic subcharts. In theCode Generation>Identifierspane, set theSubsystem methodsparameter. 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, seeGenerate Separate Code for an Atomic Subchart(Stateflow).

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. 右键单击库表并选择Block Parameters.

  4. In the dialog box, specify these parameters:

    1. On theMaintab, selectTreat as atomic unit.

    2. On theCode Generation选项卡,设置Function packagingtoReusable function.

    3. SetFile name optionstoUser specified.

    4. ForFile name, enter the name of the file with no extension.

  5. In theCode Generation选项卡,设置theSystem target fileparameter toert.tlc.

  6. (OPTIONAL) Customize the generated function names for atomic subcharts. In theCode Generation>Identifiers选项卡,设置theSubsystem methodsparameter. 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