Main Content

Access Custom C Code in All Charts in Model

You can integrate custom code written in C or C++ with Stateflow® charts in Simulink® models. By sharing data and functions between your custom code and your Stateflow chart, you can augment the capabilities of Stateflow and leverage the software to take advantage of your preexisting code. For more information, see Reuse Custom Code in Stateflow Charts.

To integrate custom C code that applies to all charts for simulation, perform the tasks that follow.

Task 1: Include Custom C Code in the Simulation Target for the Main Model

Specify custom code options in the simulation target for your main model:

  1. Open the Model Configuration Parameters dialog box.

  2. In the Model Configuration Parameters dialog box, select the Simulation Target pane.

    The custom code options appear.

  3. Specify your custom code in the subpanes.

    Follow the guidelines in Specify Relative Paths to Your Custom Code.

    Note

    See Task 1: Include Custom C Code in the Simulation Target for descriptions of the custom code options.

  4. Click OK.

    By default, settings in the Simulation Target pane for the main model apply to all charts contributed by library models.

Tip

If you want to rebuild the target to include custom code changes, in the Apps tab, select Simulink Coder. The C Code tab appears. Click Build.

Task 2: Ensure That Custom C Code for the Main Model Applies to Library Charts

Configure the simulation target for each library model that contributes a chart to your main model:

  1. In the Modeling tab, select Model Settings. Open the Simulation Target pane.

  2. Clear the Use local custom code settings (do not inherit from main model) check box.

    This step ensures that library charts inherit the custom code settings of your main model.

  3. Click OK.

Task 3: Simulate the Model

Simulate your model by clicking the play button in the toolbar of the editor.

For information on setting simulation options using the command-line API, see Command-Line API to Set Simulation and Code Generation Parameters.

Related Topics