Main Content

Test Export-Function Model Simulation Using Function-Call Generators

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

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

    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:

  • 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, the software displays an error. For information on sorted execution order, see Control and Display Execution Order. To disable this restriction, clear the Enable strict scheduling checks for referenced model configuration parameter.

  • 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 Treat each discrete rate as a separate task parameter.

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.

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 the Solver pane:

    • Type is set to Fixed-step.

    • Solver is set to discrete (no continuous states).

    • Fixed-step size (fundamental sample time) is set to auto.

  4. Set up logging for signals. Right-click a signal you want to log. Then, select Log 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

Related Topics