Writing S-Functions | ![]() ![]() |
Process View
The following figures show the order in which Simulink invokes an S-function's callback methods. Solid rectangles indicate callbacks that always occur during model initialization and/or at every time step. Dotted rectangles indicate callbacks that may occur during initialization and/or at some or all time steps during the simulation loop. See the documentation for each callback method in S-Function Callback Methods to determine the exact circumstances under which Simulink invokes the callback.
Calling Structure for the Real Time Workshop
When generating code, the Real-Time Workshop does not go through the entire calling sequence outlined above. After initializing the model as outlined in the preceding section, Simulink calls mdlRTW
, an S-function routine unique to the Real-Time Workshop, mdlTerminate
, and exits.
For more information about the Real-Time Workshop and how it interacts with S-functions, see the Real-Time Workshop User's Guide and the Target Language Compiler Reference Guide.
Alternate Calling Structure for External Mode
When you are running Simulink in external mode, the calling sequence for S-function routines changes. This picture shows the correct sequence for external mode.
Simulink calls mdlRTW
once when it enters external mode and again each time a parameter changes or when you select Update Diagram under your model's Edit menu.
Note Running Simulink in external mode requires the Real-Time Workshop. For more information about external mode, see the Real-Time Workshop User's Guide. |
![]() | How Simulink Interacts with C S-Functions | Data View | ![]() |