S-Function Features and Limitations
S-Function Features
The following tables give overviews of the features supported by different types of S-functions. The first table focuses on handwritten S-functions. The second table compares the features of S-functions automatically generated by the S-Function Builder or Legacy Code Tool.
Features of Hand-Written S-Functions
Feature | Level-2 MATLAB S-Function | Handwritten C MEX S-Function |
---|---|---|
Data types | Supports any data type supported by Simulink® software, including fixed-point types. | Supports any data type supported by Simulink software, including fixed-point types. |
Numeric types | Supports real and complex signals. | Supports real and complex signals. |
Frame support | Supports framed and unframed signals. | Supports framed and unframed signals. |
Port dimensions | Supports scalar, 1-D, and multidimensional input and output signals. | Supports scalar, 1-D, and multidimensional input and output signals. |
S-function API | Supports a larger set of the S-function API. See Level-2 MATLAB S-Function Callback Methods for a list of supported methods. | Supports the entire S-function API. |
Code generation support | Requires a handwritten TLC file to generate code. | Natively supports code generation. Requires a handwritten TLC file to inline the S-function during code generation. |
Simulink Accelerator mode | Provides the option to use a TLC file in Accelerator mode, instead of running interpretively. | Provides the option to use a TLC or MEX file in Accelerator mode. |
Model reference | Supports Normal and Accelerator mode simulations when used in a referenced model. Requires a TLC file for Accelerator mode. | Provides options for sample time inheritance and Normal mode support when used in a referenced model. See Model Reference Requirements and Limitations. |
Simulink. and
Simulink. support | Supports Simulink.NumericType and
Simulink.AliasType classes (see Configure Custom Data Types). | Supports all of these classes (see Configure Custom Data Types). |
Bus input and output signals | Does not support bus input or output signals. | Supports nonvirtual bus input or output signals. |
Tunable and run-time parameters | Supports tunable and run-time parameters. | Supports tunable and run-time parameters. |
Work vectors | Supports DWork vectors (see Using DWork Vectors in Level-2 MATLAB S-Functions). | Supports all work vector types (see Types of DWork Vectors). |
Features of Automatically Generated S-Functions
Feature | S-Function Builder | Legacy Code Tool |
---|---|---|
Data types | Supports any data type supported by Simulink software, including fixed-point types. | Supports all built-in data types. To use a fixed-point data type, you must
specify the data type as a Simulink.NumericType . You cannot use
a fixed-point type with unspecified scaling. |
Numeric types | Supports real and complex signals. | Supports complex signals only for built-in data types. |
Frame support | Supports framed and unframed signals. | Does not support frame-based signals. |
Port dimensions | Supports scalar, 1-D, and multidimensional input and output signals. | Supports scalar, 1-D, and multidimensional input and output signals. |
S-function API | Supports creation of custom mdlInitializeSizes ,
mdlInitializeSampleTimes , mdlDerivatives ,
mdlUpdate , and mdlOutputs . Also allows for
automatic generation of mdlStart and
mdlTerminate . | Supports mdlInitializeSizes ,
mdlInitializeSampleTimes , mdlStart ,
mdlInitializeConditions , mdlOutputs , and
mdlTerminate . |
Code generation support | Natively supports code generation. Also, automatically generates a TLC file for inlining the S-function during code generation. | Natively supports code generation optimized for embedded systems. Also, automatically generates a TLC file that supports expression folding for inlining the S-function during code generation. |
Accelerator mode | Uses a TLC file in Accelerator mode, if the file was generated. Otherwise, uses the MEX file. | Provides the option to use a TLC or MEX file in Accelerator mode. |
Model reference | Uses default behaviors when used in a referenced model. | Uses default behaviors when used in a referenced model. |
Simulink.AliasType and
Simulink.NumericType | Does not support these classes. | Supports Simulink.AliasType and
Simulink.NumericType . |
Bus input and output signals | Supports bus input and output signals. See sfbuilder_bususage for an example. | Supports bus input and output signals. You must define a
Simulink.Bus object in the MATLAB® workspace that is equivalent to the structure of the input or output
used in the legacy code. Does not support bus parameters. |
Tunable and run-time parameters | Supports tunable parameters only during simulation. Supports run-time parameters. | Supports tunable and run-time parameters. |
Work vectors | Does not provide access to work vectors. | Supports DWork vectors with the usage type
SS_DWORK_USED_AS_DWORK . See Types of DWork Vectors for a discussion on the different DWork vector
usage types. |
S-Function Limitations
The following table summarizes the major limitations of the different types of S-functions.
Implementation | Limitations |
---|---|
Level-2 MATLAB S-functions |
|
Handwritten C MEX S-function | Supports model reference with some limitations. See S-Functions in Referenced Models. |
S-Function Builder |
Note S-functions with one input and one output port can have dynamically-sized signals. |
Legacy Code Tool |
|