Test Export-Function Model Simulation Using Function-Call Generators

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.

  • Run simulation.

To create the model for this example, see Create Export-Function Model.

Create Referenced 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.

  1. Add a Model block to a new Simulink model. In the Model name box, enter export_function_model.

  2. Add Outport blocks to the output_100ms and output_10ms ports on the Model block.

  3. Add a Sine Wave block to provide data input. Set Amplitude to 2 and Sample time to 0.01. Connect the block to the input_10ms input port on the Model block.

Create Test Model (Harness) for Simulation

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.

  1. Add a Function-Call Generator block. Set Sample time to 0.1. Connect the block to the function_call_100ms input port.

  2. Add a second Function-Call Generator block. Set Sample time to 0.01. Connect the block to the function_call_10ms input port.

Scheduling Restrictions for Referenced Export-Function Models

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 Export Function Model

Simulate the export-function model to test and observe its behavior before generating code.

Note

Simulink does not simulate preempting function-calls.

  1. 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.

  2. Verify the configuration parameters for Solver Type is set to Fixed-step, Solver set to discrete (no continuous states), and Fixed-step size (fundamental sample time) set to auto.

  3. Set up logging of signals. Right-click output port signals and select Log selected signal.

  4. Run simulation.

  5. 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.

See Also

Blocks

Related Topics