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.
You can read and write the following C code variables directly in your charts that use MATLAB® as the action language.
Custom C Code Type | Description |
---|---|
double | Double-precision floating point |
single | Single-precision floating point |
int8 | Signed 8-bit integer |
uint8 | Unsigned 8-bit integer |
int16 | Signed 16-bit integer |
uint16 | Unsigned 16-bit integer |
int32 | Signed 32-bit integer |
uint32 | Unsigned 32-bit integer |
By right clicking on the Stateflow object that uses your custom code, you can access your custom code
variable. After right clicking on the object, hover over
Explore. Your custom code variable appears, denoted
by (C variable)
. Clicking the C variable allows you to access the
custom code from MATLAB.
You can use the following C function argument types directly in your charts that
use MATLAB as the action language without using coder.ceval
.
For information on calling external code from MATLAB code by using
coder.ceval
, see Call C/C++ Code from MATLAB Code (MATLAB Coder).
Custom C Function Argument Type | Description |
---|---|
double | Double-precision floating point |
single | Single-precision floating point |
int8 | Signed 8-bit integer |
uint8 | Unsigned 8-bit integer |
int16 | Signed 16-bit integer |
uint16 | Unsigned 16-bit integer |
int32 | Signed 32-bit integer |
uint32 | Unsigned 32-bit integer |
By right clicking on the Stateflow object that uses your custom code, you can access your custom code
function. After right clicking on the object, hover over
Explore. Your custom code function appears, denoted
by (C function)
. Clicking the C function allows you to access the
custom code from MATLAB.
In charts that use C as the action language, to include enumerations in your custom code, select Import custom code in the Simulation Target pane of the Configuration Parameters. After this option is selected, define your enumerations in a header file, and include your header file in the Insert custom C code in generated section of the Simulation Target pane.