This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Generate Reusable Code for Atomic Subcharts

An atomic subchart is a graphical object that helps you to create standalone subcomponents in a Stateflow® chart. Atomic subcharts are supported only in Stateflow charts in Simulink® models. For more information, see Create Reusable Subcomponents by Using Atomic Subcharts.

How to 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 the following 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. Click OK to apply the changes.

  5. (OPTIONAL) Customize the generated function names for atomic subcharts:

    1. Open the Model Configuration Parameters dialog box.

    2. On the Code Generation pane, set System target file to ert.tlc.

    3. Navigate to the Code Generation > Symbols pane.

    4. For Subsystem methods, specify the format of the function names using a combination of the following tokens:

      • $R — root model name

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

      • $N — block name

      • $H — subsystem index

      • $M — name-mangling text

    5. Click OK to apply the changes.

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

How to 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 the following 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.

    4. Click OK to apply the changes.

  3. (OPTIONAL) Customize the generated function names for atomic subcharts:

    1. Open the Model Configuration Parameters dialog box.

    2. On the Code Generation pane, set System target file to ert.tlc.

    3. Navigate to the Code Generation > Symbols pane.

    4. For Subsystem methods, specify the format of the function names using a combination of the following tokens:

      • $R — root model name

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

      • $N — block name

      • $H — subsystem index

      • $M — name-mangling text

    5. Click OK to apply the changes.

When you generate code for your model, a separate file stores the code for the atomic subchart. For more information, see Generate Reusable Code for Unit Testing.