User`s guide

6 Program Architecture
6-34
automatically incorporates your non-inlined C code S-functions into the
program if they adhere to the S-function API described in the Simulink
documentation.
This format defines functions and a
SimStruct that are local to the S-function.
This allows you to have multiple instances of the S-function in the model. The
model’s
SimStruct contains a pointer to each S-function’s SimStruct.
Code Generation and S-Functions
If a model contains S-functions, the source code for the S-function must be on
the search path the
make utility uses to find other source files. The directories
that are searched are specified in the Rules section of the template makefile
that is used to build the program.
See Chapter 3, “Code Generation and the Build Process,” for more information
on how S-function source code is located
S-functions are implemented in a way that is directly analogous to the model
code. They contain their own public registration function (which is called by the
top-level model code) that initializes static function pointers in its
SimStruct.
When the top-level model needs to execute the S-function, it does so via the
function pointers in the S-function’s
SimStruct. The S-functions use the same
SimStruct data structure as the generated code; however, there can be more
than one S-function with the same name in your model. This is accomplished
by having function pointers to static functions.
Inlining S-Functions
You can incorporate C MEX S-functions, along with the generated code, into
the program executable. You can also write a target file for your C MEX
S-function to inline the S-function, thus improving performance by eliminating
function calls to the S-function itself. For more information on inlining
S-functions, see “Inlining an S-Function,” in Chapter 3 of the Target Language
Compiler Reference Guide.