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.
Specify custom code options in the simulation target for your main model:
Open the Model Configuration Parameters dialog box.
In the Model Configuration Parameters dialog box, select the Simulation Target pane.
The custom code options appear.
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.
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.
Configure the simulation target for each library model that contributes a chart to your main model:
In the Modeling tab, select Model Settings. Open the Simulation Target pane.
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.
Click OK.
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.