| Stateflow User's Guide |
 |
Including Custom C++ Code
You specify custom C code for Stateflow targets as described in Specifying Custom Code Options for Stateflow Targets. Use the following procedure to include custom C++ code with a target:
- Add a C function wrapper to your existing custom code. This wrapper function executes the C++ code that you are including.
- The C function wrapper should have the following form:
- Create a header file that prototypes the C function wrapper in the previous step.
- The header file should have the following form:
The value _cplusplus is defined if your compiler supports C++ code. The extern "C" wrapper specifies C linkage with no name mangling.
- Configure the Stateflow simulation target. You can access this dialog as follows:
- From the Stateflow chart, select Tools -> Open Simulation Target and
click the Target Options button.
- Add the header file to the Include Code tab. Click Apply.
- Add the custom C++ files to the Include Paths or Source Files tabs.
Click Apply.
- If you need to make additional configurations in this dialog, do so now.
Click OK when you are done.
- Select
C++ in the Language option of the Real-Time Workshop configuration dialog. You can access this dialog as follows:
- From the model, select Simulation -> Configuration Parameters.
- Select the Real-Time Workshop pane.
- Select
C++ from the Language pull-down menu. Click Apply.
- If you need to make additional configurations in this dialog, do so now.
Click OK when you are done.
The preceding procedure describes how to include custom C++ code with a target for a simulation. If you also want to generate code with Real-Time Workshop, use the following procedure to duplicate the Stateflow chart header file and C++ file entries for Real-Time Workshop:
- Be sure that you have performed the preceding procedure.
- Configure the Real-Time Workshop configuration set. You can access this dialog as follows:
- From the model, select Simulation -> Configuration Parameters.
- Select the Custom Code subpane under the Real-Time Workshop pane.
- Add the header file to the Header File option. Click Apply.
- Add the custom C++ files to the Include directories or Source files
option. Click Apply.
- If you need to make additional configurations in this dialog, do so now.
Click OK when you are done.
| Specifying Relative Paths for Custom Code | | Calling Graphical Functions from Custom Code |  |
© 1994-2005 The MathWorks, Inc.