Real-Time Workshop Embedded Coder | ![]() ![]() |
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 Simulink Writing S-Functions documentation.
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 the Create Simulink (S-Function) block option is on, 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, Real-Time Workshop creates and opens an untitled model containing the generated S-Function block.
Generating an S-Function Wrapper
To generate an S-function wrapper for your Real-Time Workshop Embedded Coder code:
ERT code generation options (2)
from the Category menu.
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.
![]() | Generating a Code Generation Report | Other Code Generation Options | ![]() |