Writing S-Functions | ![]() ![]() |
You can create a triggered subsystem whose execution is determined by logic internal to an S-function instead of by the value of a signal. A subsystem so configured is called a function-call subsystem. To implement a function-call subsystem:
ssCallSystemWithTid
macro to call the triggered subsystem.
Function-call subsystems are not executed directly by Simulink; 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:
mdlInitializeSampleTimes
. For example:
ssSetCallSystemOutput(S,0); /* call on 1st element */ ssSetCallSystemOutput(S,2); /* call on 3rd element */
mdlOutputs
or mdlUpdate
S-function routine. For example:
See simulink/src/sfun_fcncall.c
for an example.
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 on their use in Stateflow, see the Stateflow documentation.
![]() | Memory Allocation | Handling Errors | ![]() |