Products & Services Solutions Academia Support User Community Company

Learn more about Stateflow   

Procedures for Embeddable Code Generation

Generating Code

Generate embeddable code for your model in one of these ways:

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.

Integrating Custom C++ Code for Code Generation

To integrate custom C++ code for embeddable code generation, perform the tasks that follow.

Task 1: Prepare Code Files

Prepare your custom C++ code for Real-Time Workshop code generation.

  1. 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;
    }
    
  2. 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.

Task 2: Include Custom C++ Source and Header Files for Real-Time Workshop Code Generation

To include custom C++ code for Real-Time Workshop code generation, perform these steps:

  1. In the Stateflow Editor, select Simulation > Configuration Parameters.

  2. In the Configuration Parameters dialog box, select the Real-Time Workshop pane.

  3. Select C++ from the Language menu. Click Apply.

  4. Select the Real-Time Workshop > Custom Code pane.

  5. Add your custom header file in the Header file subpane. Click Apply.

  6. Add your custom C++ files in the Source files subpane.

  7. Click OK.

Task 3: Choose a C++ Compiler

For instructions, see Choosing a Compiler.

Task 4: Generate Code

For instructions, see Generating Code.

Integrating Custom C Code for Nonlibrary Charts for Code Generation

To integrate custom C code that applies to nonlibrary charts for embeddable code generation, perform the tasks that follow.

Task 1: Include Custom C Code for Embeddable Code Generation

Specify custom code options for Real-Time Workshop code generation of your model:

  1. In the Stateflow Editor, select Simulation > Configuration Parameters.

  2. In the Configuration Parameters dialog box, select Real-Time Workshop > Custom Code.

    The custom code options appear.

  3. Specify your custom code in the subpanes.

    Follow the guidelines in Specifying Relative Paths for Custom Code.

      Note   If you specified custom code settings for simulation, you can apply these settings to Real-Time Workshop code generation. To avoid entering the same information twice, select Use the same custom code settings as Simulation Target.

Task 2: Generate Code

For instructions, see Generating Code.

Integrating Custom C Code for Library Charts for Code Generation

To integrate custom C code that applies only to library charts for embeddable code generation, perform the tasks that follow.

Task 1: Include Custom C Code in Embeddable Targets for Library Models

Specify custom code options in the embeddable target for each library model that contributes a chart to your main model:

  1. In the Stateflow Editor, select Tools > Open RTW Target.

    The Configuration Parameters dialog box appears.

  2. 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.

  3. Specify your custom code in the subpanes.

    Follow the guidelines in Specifying Relative Paths for Custom Code.

      Note   If you specified custom code settings for simulation, you can apply these settings to Real-Time Workshop code generation. To avoid entering the same information twice, select Use the same custom code settings as Simulation Target.

  4. Click OK.

Task 2: Generate Code

For instructions, see Generating Code.

Integrating Custom C Code for All Charts for Code Generation

To integrate custom C code that applies to all charts for embeddable code generation, perform the tasks that follow.

Task 1: Include Custom C Code for Embeddable Code Generation of the Main Model

Specify custom code options for Real-Time Workshop code generation of your main model:

  1. In the Stateflow Editor, select Simulation > Configuration Parameters.

  2. In the Configuration Parameters dialog box, select Real-Time Workshop > Custom Code.

    The custom code options appear.

  3. Specify your custom code in the subpanes.

    Follow the guidelines in Specifying Relative Paths for Custom Code.

      Note   If you specified custom code settings for simulation, you can apply these settings to Real-Time Workshop code generation. To avoid entering the same information twice, select Use the same custom code settings as Simulation Target.

Task 2: Ensure That Custom C Code for the Main Model Applies to Library Charts

Configure the embeddable target for each library model that contributes a chart to your main model:

  1. In the Stateflow Editor, select Tools > Open RTW Target.

  2. 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.

  3. Click OK.

Task 3: Generate Code

For instructions, see Generating Code.

  


Related Products & Applications

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