Test Export-Function Model Simulation Using Function-Call Generators - MATLAB & Simulink (original) (raw)

Main Content

Use multiple Function-Call Generator blocks with distinct sample times and let the software schedule the function-call components for simulation. This strategy is useful when the rate-monotonic scheduling behavior in Simulink® software is similar to the target OS behavior.

  1. Create a Simulink model.
  2. Add a Model block that references the export-function model.
  3. Specify function-call events using Function-Call Generator blocks.
  4. Specify data inputs.
  5. Run a simulation.

Reference an Export-Function Model

Referencing an export-function model from a Model block allows you to add function-call events and signal logging for testing without changing the model itself.

  1. Add a Model block to a new Simulink model. In the Model name box, enter the name of an export-function model. For example, use the export-function model created in Create Export-Function Model.
  2. Add and connect Outport blocks to theoutput_100ms and output_10ms ports on theModel block.
  3. Add a Sine Wave block to provide data input. SetAmplitude to 2 and Sample time to 0.01. Connect the block to theinput_10ms input port on the Model block.
    Model block that references export-function model and has input and output ports connected

Create Test Model (Harness) for Simulation

Use a Simulink test model only for simulation. After simulation testing, generate code from the export-function model. 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 thefunction_call_100ms input port.
  2. Add a second Function-Call Generator block. Set Sample time to 0.01. Connect the block to thefunction_call_10ms input port.
    Model block that references export-function model and has function-call ports connected

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:

For the export-function model:

Prepare Export-Function Model for Simulation

Before you test the export-function model, configure model settings and specify signals to log.

  1. On the Modeling tab, click Model Settings .
  2. On the Model Referencing pane, clear the configuration parameter Enable strict scheduling check for referenced models.
  3. Verify the settings for these configuration parameters on theSolver pane:
    • Type is set toFixed-step.
    • Solver is set to discrete (no continuous states).
    • Fixed-step size (fundamental sample time) is set toauto.
  4. Set up logging for signals. Right-click a signal you want to log. Then, selectLog selected signal. In this example, the export-function model output signals are logged because they connect to Outport blocks.

Note

The software does not simulate preempting function-calls.

Test Export-Function Model with Function-Call Generator Blocks

To test and observe the export-function model behavior before generating code, simulate the completed test model.

Optionally, open and simulate the completed test model named ex_export_function_test_model_with_function_call_generators.

To view the simulation results, open the Simulation Data Inspector. On the Simulation tab, click Data Inspector.

After you test your model, you can generate code for the functions. See Generate Code for Export-Function Model.

See Also

Function-Call Subsystem

Topics