Technical data
Inlining an S-Function
3-31
Inlining an S-Function
When a Simulink model contains an S-function and a corresponding .tlc file, 
Real-Time Workshop inlines the S-function. Inlining an S-function can produce 
more efficient code by eliminating the S-function API layer from the generated 
code.
S-functions that are not inlined make calls to all of these seven functions, even 
if the routine is empty for the particular S-function:
By inlining an S-function, you can eliminate the calls to these possibly empty 
functions in the simulation loop. This can greatly improve the efficiency of the 
generated code. To inline an S-function called 
sfunc_name, you create a custom 
S-function block target file called 
sfunc_name.tlc and place it in the same 
directory as the S-function’s MEX-file. Then, at build time, the target file is 
executed instead of setting up function calls into the S-function’s 
.c file. The 
S-function target file “inlines” the S-function by directing the Target Language 
Compiler to insert only the statements defined in the target file.
S-Function Purpose
mdlInitializeSizes
Initialize the sizes array.
mdlInitializeSampleTimes
Initialize the sample times array.
mdlInitializeConditions
Initialize the states.
mdlOutputs
Compute the outputs.
mdlUpdate
Update discrete states.
mdlDerivatives
Compute the derivatives of continuous 
states.
mdlTerminate
Clean up when the simulation terminates.










