Real-Time Workshop User's Guide    

Automatic S-Function Wrapper Generation

An S-function wrapper is an S-function that calls your C code from within Simulink. S-function wrappers provide a standard interface between Simulink and externally written code, allowing you to integrate your code into a model with minimal modification. For a complete description of wrapper S-functions, see the Writing S-Functions manual.

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

This is useful for code validation and simulation acceleration purposes.

When Create Simulink (S-Function) block option is on, the Real-Time Workshop generates an additional source code file, model_sf.c, in the build directory. This module contains the S-function that calls the Real-Time Workshop Embedded Coder code that you deploy. This S-function can be used within Simulink.

The build process then compiles and links model_sf.c with model.c and the other Real-Time Workshop 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 creates and opens an untitled model containing the generated S-Function block.

Limitations

It is not possible to create multiple instances of a Real-Time Workshop Embedded Coder generated S-Function block within a model, because the code uses static memory allocation.

To generate an S-function wrapper for your Real-Time Workshop Embedded Coder code:

  1. Select the Real-Time Workshop tab of the Simulation Parameters dialog box. Then select ERT advanced options from the Category menu.
  2. Enable the Create Simulink (S-Function) block option, as shown.

  1. Configure the other code generation options as required.
  2. Click the Build button.
  3. When the build process completes, an untitled model window opens. This model contains the generated S-Function block.

  4. Save the new model.
  5. The generated S-Function block is now ready to use with other blocks or models in Simulink.

 Model Entry Points Optimizing the Generated Code