This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Generate Code for Export-Function Model with Rate-Based Model

You can generate code from a model that includes both function-call subsystems and scheduled subsystems. Create a rate-based model with scheduled subsystems, and then add the model to an export-function model by reference from a Model block.

Create Export-Function Model with Scheduled Subsystems

Create a model with function-call and scheduled subsystems.

  1. Begin by creating a rate-based model with scheduled subsystems. In this example, the Sample time for the Scheduled Subsystem is set to 0.01. See Create A Rate-Based Model.

  2. Create an export-function model with function-call subsystems. See Create Export-Function Model.

  3. Include the rate-based model in the export-function model by reference from a Model block.

  4. Display periodic event ports on the Model block by selecting the Schedule rates check box.

    Connect Inport blocks to the periodic event ports.

  5. In the Inport block dialog box, select the Output function-call parameter check box and specify the Sample time with the same sample time from the scheduled subsystem. In this example, the Sample time for the function-call 10ms Inport block is set to 0.01


Generate Code for Exported Functions

Generate code from the model that contains the functions.

  1. From the menu, select Simulation > Model Configuration Parameters.

  2. In the Solver pane, set Solver Type to Fixed-step.

  3. In the Code generation pane, set System target file to ert.tlc. Requires an Embedded Coder® license.

  4. From the Simulink menu, Select Code > C/C++ Code > Build Model. Wait for the code building process to complete.

  5. Select Code > C/C++ Code > Code Generation Report

In the generated code, each root-level function-call Inport block generates a void-void function. The function name is the name of the output signal from the block. If there is no signal name, then the function name is derived from the name of the block. In this example, the function name was derived from the block name.