Writing S-Functions | ![]() ![]() |
Basic Files Required for Implementation
This section briefly describes what files and functions you'll need to create noninlined, wrapper, and fully inlined S-functions.
sfunction
.c
.
sfunction
.tlc
file.
sfunction
.tlc
file. Fully inlined S-functions produce the optimal code for a parameterized S-function. This is an S-function that operates in a specific mode dependent upon fixed S-function parameters that do not change during model execution. For a given operating mode, the sfunction
.tlc
file specifies the exact code that is generated to implement the algorithm for that mode. For example, the direct-index lookup table S-function at the end of this chapter contains two operating modes -- one for evenly spaced x-data
and one for unevenly spaced x-data
.
mdlRTW
routine in your S-function MEX-file sfunction
.c
. The mdlRTW
routine lets you place information in model
.rtw
, which is the file that is processed by the Target Language Compiler prior to executing sfunction
.tlc
when generating code. This is useful when you want to introduce nontunable parameters into your TLC file.
For S-functions to work correctly in the Simulink environment, a certain amount of overhead code is necessary. When the Real-Time Workshop generates code from models that contain S-functions (without sfunction
.tlc
files), it embeds some of this overhead code in the generated C code. If you want to optimize your real-time code and eliminate some of the overhead code, you must inline (or embed) your S-functions. This involves writing a TLC (sfunction
.tlc
) file that directs the Real-Time Workshop to eliminate all overhead code from the generated code. The Target Language Compiler, which is part of the Real-Time Workshop, processes sfunction
.tlc
files to define how to inline your S-function algorithm in the generated code.
![]() | Types of S-Functions | Noninlined S-Functions | ![]() |