Use multiple Function-Call Generator blocks with distinct sample times and let Simulink® schedule the function-call components for simulation. This strategy is useful when the rate-monotonic scheduling behavior in Simulink is similar to the target OS behavior.
Create a new Simulink model.
Add a Model block that references the export-function model.
Specify function-call events using Function-Call Generator blocks.
Specify data inputs.
To create the model for this example, see Create Export-Function Model.
Referencing an export-function model from a Model block allows the addition of function-call events and logging of data signals for testing without changing the model itself.
Add a Model block to a new Simulink model. In the Model name box, enter
Add Outport blocks to the output_100ms and output_10ms ports on the Model block.
Add a Sine Wave block to provide data input. Set
2 and Sample
0.01. Connect the block to the
input_10ms input port on the Model block.
You use a Simulink test model only for simulation. After simulation testing, generate code from the export-function model, and then integrate exported function code with an externally coded scheduler.
Add a Function-Call Generator block. Set Sample
0.1. Connect the block to the
function_call_100ms input port.
Add a second Function-Call Generator block. Set Sample
0.01. Connect the block to the
function_call_10ms input port.
If a test model references an export-function model, there are some restrictions to ensure consistency with simulation results.
For the test model:
You cannot use two Function-Call Generator blocks with the same sample time.
Function-calls to the input ports on the Model block must follow the execution order of the root-level function-call Inport blocks in the referenced export-function model. Function-Call Generator blocks with smaller sample times execute first.
If the test model calls the referenced model functions out of order at any time step, Simulink displays an error. For information on sorted execution order, see Control and Display the Execution Order. To disable this restriction, clear the check box for the configuration parameter Enable strict scheduling checks for referenced model.
You can use a Mux block to connect signals from the Function-Call Generator blocks with different sample times before connecting them to the referenced export-function model. In the Configuration Parameters dialog box, clear the check box for the parameter Treat each discrete rate as a separate task.
For the export-function model:
The sample times for the root-level function-call Inport blocks
must be set to inherited (
-1) or match the sample time of the
Function-Call Generator blocks that drive them.
Simulate the export-function model to test and observe its behavior before generating code.
Simulink does not simulate preempting function-calls.
Set configuration parameters for the test model. On the Modeling tab and from the Setup section, select Model Settings . Select the Model Reference pane. Clear the check box for the configuration parameter Enable strict scheduling check for referenced models.
Verify the configuration parameters for Solver Type is set to
Fixed-step, Solver set to
continuous states), and Fixed-step size (fundamental sample time) set to
Set up logging of signals. Right-click output port signals and select Log selected signal.
Open the Simulation Data Inspector by clicking the toolstrip icon .
After you test your model, you can generate code for the functions. See Generate Code for Export-Function Model.