S-Functions with Model Referencing

S-Function Support for Model Referencing

Each kind of S-function provides its own level of support for model referencing.

Type of S-FunctionSupport for Model Referencing
Level-1 MATLAB S-functionNot supported
Level-2 MATLAB S-function
  • Supports Normal and Accelerator mode

  • Accelerator mode requires a TLC file

Handwritten C MEX S-function
  • Supports Normal and Accelerator mode

  • May be inlined with TLC file

S-Function Builder

Supports Normal and Accelerator mode

Legacy Code Tool

Supports Normal and Accelerator mode

Sample Times

Simulink® software assumes that the output of an S-function does not depend on an inherited sample time unless the S-function explicitly declares a dependence on an inherited sample time.

You can control inheriting sample time by using ssSetModelReferenceSampleTimeInheritanceRule in different ways, depending on whether an S-function permits or precludes inheritance. For details, see Inherited Sample Time for Referenced Models.

S-Functions with Accelerator Mode Referenced Models

For a referenced model that executes in Accelerator mode, set the Configuration Parameters > Model Referencing > Total number of instances allowed per top model to One if the model contains an S-function that is either:

  • Inlined, but has not set the SS_OPTION_WORKS_WITH_CODE_REUSE flag

  • Not inlined

Inlined S-Functions with Accelerator Mode Referenced Models

For Accelerator mode referenced models, if the referenced model contains an S-function that should be inlined using a Target Language Compiler file, the S-function must use the ssSetOptions macro to set the SS_OPTION_USE_TLC_WITH_ACCELERATOR option in its mdlInitializeSizes method. The simulation target does not inline the S-function unless the S-function sets this option.

A referenced model cannot use noninlined S-functions in the following cases:

  • The model uses a variable-step solver.

  • Simulink Coder™ generated the S-function.

  • The S-function supports use of fixed-point numbers as inputs, outputs, or parameters.

  • The model is referenced more than once in the model reference hierarchy. To work around this limitation, use Normal mode.

  • The S-function uses string parameters.

Using C S-Functions in Normal Mode Referenced Models

Under certain conditions, when a C S-function appears in a referenced model that executes in Normal mode, successful execution is impossible. For details, see S-Functions in Normal Mode Referenced Models.

Use the ssSetModelReferenceNormalModeSupport SimStruct function to specify whether an S-function can be used in a Normal mode referenced model.

You may need to modify S-functions that are used by a model so that the S-functions work with multiple instances of referenced models in Normal mode. The S-functions must indicate explicitly that they support multiple exec instances. For details, see Supporting the Use of Multiple Instances of Referenced Models That Are in Normal Mode.

Protected Models

A protected model cannot use noninlined S-functions directly or indirectly.

Simulink Coder Considerations

A referenced model in Accelerator mode cannot use S-functions generated by the Simulink Coder software.

Noninlined S-functions in referenced models are supported when generating Simulink Coder code.

The Simulink Coder S-function target does not support model referencing.

For general information about using Simulink Coder and model referencing, see Referenced Models.

Was this topic helpful?