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:
![]() | Model Entry Points | Optimizing the Generated Code | ![]() |