| Level-1 M-file S-function | Use the following template to write a new Level-1 M-file S-function:sfuntmpl.m See Maintaining Level-1 M-File S-Functions for
more information. |
| Level-2 M-file S-function | Use the following template to write a new Level-2
M-file S-function: msfuntmpl_basic.m See Writing Level-2 M-File S-Functions for
more information. Write a Target Language Compiler (TLC) file for the
S-function if you need to generate code for a model containing the
S-function. The file, msfcn_times_two.tlcin
the directory is an example TLC file for the S-function msfcn_times_two.m. See Inlining M-File S-Functions in Real-Time Workshop Target Language Compiler for information
on writing TLC files for Level-2 M-file S-functions.
|
| Hand-written C MEX S-function | Use the following template to write a new C MEX S-function
(see Example of a Basic C MEX S-Function)
or to write a wrapper S-function that calls C, C++, or Fortran code: matlabroot/simulink/src/sfuntmpl_doc.c See Writing Wrapper S-Functions in the Real-Time Workshop User's
Guide for information on writing wrapper S-functions to
incorporate legacy C or C++ code.
See Constructing the Gateway for information on writing a wrapper
function to incorporate legacy Fortran code. Compile the S-function using the mex command
to obtain an executable to use during simulation. Write a TLC file for the S-function if you want to
inline the code during code generation (see Writing Fully Inlined S-Functions with the mdlRTW Routine in
the Real-Time Workshop User's Guide and Real-Time Workshop Target Language Compiler)
.
You do not need a TLC file if you are not inlining the S-function
in the generated code.
|
| S-Function Builder | Enter the S-function attributes into the S-Function
Builder dialog box (see S-Function Builder Dialog Box). Select the Generate wrapper TLC option
to generate a TLC file to inline the S-function during code generation. Click Build to generate the S-function,
TLC file, and an executable file to use during simulation.
|
| Legacy Code Tool | Use the legacy_code function to perform
the following steps (see Integrating Existing C Functions into Simulink Models
with the Legacy Code Tool):Initialize a data structure that describes the S-function
attributes in terms of the legacy function. lct_spec = legacy_code('initialize');Generate and compile the wrapper S-function. legacy_code('sfcn_cmex_generate', lct_spec);
legacy_code('compile', lct_spec);Instantiate an S-Function block that calls the S-function
wrapper. legacy_code('slblock_generate', lct_spec);Generate a TLC file to inline the S-function during
code generation. legacy_code('sfcn_tlc_generate', lct_spec);
|