Skip to Main Content Skip to Search
Product Documentation

Function-Call Subsystems

You can create a triggered subsystem whose execution is determined by logic internal to a C MEX S-function instead of by the value of a signal. A subsystem so configured is called a function-call subsystem. You cannot trigger a function-call subsystem from a Level-2 MATLAB S-function. To implement a function-call subsystem:

Function-call subsystems are not executed directly by the Simulink engine; rather, the S-function determines when to execute the subsystem. When the subsystem completes execution, control returns to the S-function. This figure illustrates the interaction between a function-call subsystem and an S-function.

In this figure, ssCallSystemWithTid executes the function-call subsystem that is connected to the first output port element. ssCallSystemWithTid returns 0 if an error occurs while executing the function-call subsystem or if the output is unconnected. After the function-call subsystem executes, control is returned to your S-function.

Function-call subsystems can only be connected to S-functions that have been properly configured to accept them.

To configure an S-function to call a function-call subsystem:

See sfun_fcncall.c for an example that executes a function-call subsystem on the first and second elements of the first S-function output. The following Simulink model (sfcndemo_sfun_fcncall) uses this S-function.

The first function-call subsystem provides a sine wave output. The second function-call subsystem is a simple feedback loop containing a Unit Delay block.

When the Pulse Generator emits its upper value, the function-call subsystem connected to the first element of the first S-function output port is triggered. Similarly, when the Pulse Generator emits its lower value, the function-call subsystem connected to the second element is triggered. The simulation output is shown on the following Scope.

Function-call subsystems are a powerful modeling construct. You can configure Stateflow® blocks to execute function-call subsystems, thereby extending the capabilities of the blocks. For more information, see the Stateflow documentation.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS