| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Stateflow |
| Contents | Index |
| Learn more about Stateflow |
Generate embeddable code for your model in one of these ways:
Use the keyboard shortcut Ctrl-B or Command-B.
Click Build in the Real-Time Workshop pane of the Configuration Parameters dialog box.
See Generated Code Files for Targets You Build for details about the embeddable code you generate for your model and the folder structure.
For information on setting code generation options using the command-line API, see Using the Command-Line API to Set Parameters for Simulation and Embeddable Code Generation.
Note You cannot generate embeddable code only for the Stateflow blocks in a library model. You must first create a link to the library block in your main model and then generate code for the main model. |
To integrate custom C++ code for embeddable code generation, perform the tasks that follow.
Prepare your custom C++ code for Real-Time Workshop code generation.
Add a C function wrapper to your custom code. This wrapper function executes the C++ code that you are including.
The C function wrapper should have this form:
int my_c_function_wrapper()
{
.
.
.
//C++ code
.
.
.
return result;
}
Create a header file that prototypes the C function wrapper in the previous step.
The header file should have this form:
int my_c_function_wrapper();
The value _cplusplus exists if your compiler supports C++ code. The extern "C" wrapper specifies C linkage with no name mangling.
To include custom C++ code for Real-Time Workshop code generation, perform these steps:
In the Stateflow Editor, select Simulation > Configuration Parameters.
In the Configuration Parameters dialog box, select the Real-Time Workshop pane.
Select C++ from the Language menu. Click Apply.
Select the Real-Time Workshop > Custom Code pane.
Add your custom header file in the Header file subpane. Click Apply.
Add your custom C++ files in the Source files subpane.
Click OK.
For instructions, see Choosing a Compiler.
For instructions, see Generating Code.
To integrate custom C code that applies to nonlibrary charts for embeddable code generation, perform the tasks that follow.
Specify custom code options for Real-Time Workshop code generation of your model:
In the Stateflow Editor, select Simulation > Configuration Parameters.
In the Configuration Parameters dialog box, select Real-Time Workshop > Custom Code.
The custom code options appear.

Specify your custom code in the subpanes.
Follow the guidelines in Specifying Relative Paths for Custom Code.
For instructions, see Generating Code.
To integrate custom C code that applies only to library charts for embeddable code generation, perform the tasks that follow.
Specify custom code options in the embeddable target for each library model that contributes a chart to your main model:
In the Stateflow Editor, select Tools > Open RTW Target.
The Configuration Parameters dialog box appears.

In the Real-Time Workshop pane, select Use local custom code settings (do not inherit from main model).
This action ensures that each library model retains its own custom code settings during Real-Time Workshop code generation.
Specify your custom code in the subpanes.
Follow the guidelines in Specifying Relative Paths for Custom Code.
For instructions, see Generating Code.
To integrate custom C code that applies to all charts for embeddable code generation, perform the tasks that follow.
Specify custom code options for Real-Time Workshop code generation of your main model:
In the Stateflow Editor, select Simulation > Configuration Parameters.
In the Configuration Parameters dialog box, select Real-Time Workshop > Custom Code.
The custom code options appear.

Specify your custom code in the subpanes.
Follow the guidelines in Specifying Relative Paths for Custom Code.
Configure the embeddable target for each library model that contributes a chart to your main model:
In the Stateflow Editor, select Tools > Open RTW Target.
In the Real-Time Workshop pane, clear the Use local custom code settings (do not inherit from main model) check box.
This action ensures that library charts inherit the custom code settings of your main model.
Click OK.
For instructions, see Generating Code.
![]() | Choosing a Procedure to Generate Embeddable Code for a Model | Optimizing Generated Code | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |