Stateflow User's Guide Previous page   Next Page

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:

  1. Add a C function wrapper to your existing custom code. This wrapper function executes the C++ code that you are including.
  1. The C function wrapper should have the following form:

  1. Create a header file that prototypes the C function wrapper in the previous step.
  1. 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.

  1. Configure the Stateflow simulation target. You can access this dialog as follows:
    1. From the Stateflow chart, select Tools -> Open Simulation Target and click the Target Options button.
    2. Add the header file to the Include Code tab. Click Apply.
    3. Add the custom C++ files to the Include Paths or Source Files tabs. Click Apply.
    4. If you need to make additional configurations in this dialog, do so now. Click OK when you are done.
  2. Select C++ in the Language option of the Real-Time Workshop configuration dialog. You can access this dialog as follows:
    1. From the model, select Simulation -> Configuration Parameters.
    2. Select the Real-Time Workshop pane.
    1. Select C++ from the Language pull-down menu. Click Apply.
    2. 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:

  1. Be sure that you have performed the preceding procedure.
  2. Configure the Real-Time Workshop configuration set. You can access this dialog as follows:
    1. From the model, select Simulation -> Configuration Parameters.
    2. Select the Custom Code subpane under the Real-Time Workshop pane.
    3. Add the header file to the Header File option. Click Apply.
    4. Add the custom C++ files to the Include directories or Source files option. Click Apply.
    5. If you need to make additional configurations in this dialog, do so now. Click OK when you are done.

Previous page  Specifying Relative Paths for Custom Code Calling Graphical Functions from Custom Code Next page

© 1994-2005 The MathWorks, Inc.