Sorting Rules for Explicitly Scheduled Model Components - MATLAB & Simulink (original) (raw)

Simulink® determines the execution order for model components, that is, subsystems and referenced models.

Export-Function Models

Export-function models include Function-Call Subsystem blocks, function-call Model blocks, Simulink Function blocks at the root level, and S-Function blocks invoked by function-call rootInport blocks.

Root function-call Inport blocks are sorted with the following rules:

Root Simulink Function blocks are sorted after root function-callInport blocks.

Test Harness for Export Function Models with Strict Scheduling

Reference the export-function model in a test harness and connect ports toFunction Generator blocks.

If you select the check box for the configuration parameter Enable strict scheduling checks for referenced models, both compile time and run-time checks ensure initiators will invoke function-calls based on the pre-defined scheduling order. Initiators are sorted based on their sample time priorities. For this example, the scheduling order and the sample time priorities do not match. The modelmHarness_ExpFcnMdl displays an error.

Test Harness for Export-Function Models Without Strict Scheduling

Reference the export-function model in a test harness and connect ports toFunction-Call Generator blocks.

If you clear the check box for the configuration parameter Enable strict scheduling checks for a referenced model and the test harness model is in signal taking mode, the function-call initiators are sorted based on their sample time priorities. For this example, the execution order is FcnCallGen0p1 >FcnCallGen0p2 > FcnCallGen0p3 >FcnCallGen0p1.

Data Dependency Error Caused by Data Sorting Rules

Consider a model where the output from one function-call initiator is the input to another.

The function-call initiator FcnCallGen0p3 should be executed beforeFcnCallGen0p4 based on their sample times. However, becauseFcnCallGen0p4 is also a source for FcnCallGen0p3 a data dependency occurs and Simulink displays an error.

Test Harness for Models with Initialize, Reset, and Terminate Function Blocks

If a Model block references a model that has an initialize, reset, or terminate ports, the function-call initiators connected to these ports have a higher priority than other function-call input ports. For example, export-function models, rate-based models, and JMAAB-B (Simulink Coder) models can have other function-call input ports. Simulink sorts function-call initiators in the following order:

Initiators for Model Block in Test Harness

Add function-call event ports to a Model block in a test harness that references a rate-based model or JMAAB-B model by selecting the Model block parameter Schedule rates.

In a single tasking model, all discrete rates are in the same task. In a multi-tasking model, discrete rates with the same value execute in the same task. Simulink sorts test harness initiators in the same task in the following order:

In a single tasking model, all initiators are in the same task:

In a multi-tasking model, initiators of the same color are in the same task.