| Contents | Index |
An S-function wrapper is an S-function that calls your C or 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. This is useful for software-in-the-loop (SIL) code verification (validating your generated code in Simulink), as well as for simulation acceleration purposes (see Use a SIL or PIL Block). For a complete description of wrapper S-functions, see Developing S-Functions in the Simulink documentation.
Using the Create block parameter, on the Code Generation > SIL and PIL Verification pane, you can build in one automated step:
A noninlined C or C++ MEX S-function wrapper that calls generated code
A model with a SIL block. This block, which contains the generated S-function, is ready for use with other blocks or models
When the Create block parameter is set to SIL, the build process generates an additional source code file, model_sf.c or .cpp, in the build folder. This module contains the S-function that calls the generated code that you deploy. You can use this S-function within Simulink.
The build process then compiles and links model_sf.c or .cpp with model.c or .cpp and the other 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 folder. Finally, the build process creates and opens an untitled model containing the SIL block with the generated S-function.
Note To generate a wrapper S-function for a subsystem, you can use a right-click subsystem build. Right-click the subsystem block in your model, select Code Generation > Generate S-Function, and in the Generate S-Function dialog box, select Create Software-In-the-Loop (SIL) block and click Build. |
To create a SIL block with the S-function wrapper for your generated code, open your ERT-based Simulink model and do the following:
To initialize the memory for the S-function to zero, you must clear the following options in the Data initialization section of the Optimization > General pane:
When the build process completes, an untitled model window opens. This model contains a SIL block with the generated S-function.
You can now use the SIL block with other blocks or models in Simulink.
The following limitations apply to Embedded Coder S-function wrapper generation:
Continuous sample time is not supported. The Support continuous time option should not be selected when creating a SIL block.
Models that contain S-function blocks for which the S-function is not inlined with a TLC file are not supported when creating a SIL block.
You cannot use multiple instances of a SIL block within a model, because the code uses static memory allocation. Each instance potentially can overwrite global data values of the others.
SIL blocks can be used with other blocks and models for SIL code verification and simulation acceleration, but they cannot be used for code generation.
A MEX S-function wrapper must only be used in the version of MATLAB in which the wrapper is created.
![]() | External Code Integration | Export Code Generated from Model to External Application | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |