Automatic S-Function Wrapper Generation

Overview

An S-function wrapper is an S-function that calls your C or C++ code from within a Simulink model. S-function wrappers provide a standard interface between a Simulink model and externally written code, allowing you to integrate your code into a model with minimal modification. This is useful for software-in-the-loop (SIL) code verification (validating your generated code using Simulink software), as well as for simulation acceleration purposes. For a complete description of wrapper S-functions, see the Simulink Writing S-Functions document.

Using the Real-Time Workshop Embedded Coder Create Simulink (S-Function) block option, you can build, in one automated step:

When the Create Simulink (S-Function) block option is on, the Real-Time Workshop build process generates an additional source code file, model_sf.c or .cpp, in the build directory. This module contains the S-function that calls the Real-Time Workshop Embedded Coder code that you deploy. You can use this S-function in a Simulink model.

The build process then compiles and links model_sf.c or .cpp with model.c or .cpp and the other Embedded Coder generated code modules, building a MEX-file. The MEX-file is named model_sf.mexext. (mexext is the file extension for MEX-files on your platform, as given by the MATLAB mexext command.) The MEX-file is stored in your working directory. Finally, the Real-Time Workshop build process creates and opens an untitled model containing the generated S-Function block.

Generating an ERT S-Function Wrapper

To generate an S-function wrapper for your Real-Time Workshop Embedded Coder code, open your ERT-based Simulink model and do the following:

  1. Open the Configuration Parameters dialog box.

  2. Select the Interface pane.

  3. Select the Create Simulink (S-Function) block option, as shown in this figure.

  4. Configure the other code generation options as required.

  5. To ensure that memory for the S-Function is initialized to zero, you should deselect the following options in the Data Initialization subpane of the Optimization pane:

  6. Select the Real-Time Workshop pane and click the Build button.

  7. When the build process completes, an untitled model window opens. This model contains the generated S-Function block.

  8. Save the new model.

  9. The generated S-Function block is now ready to use with other Simulink blocks or models.

S-Function Wrapper Generation Limitations

The following limitations apply to Real-Time Workshop Embedded Coder S-function wrapper generation:

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS