Main Content

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.

To open a completed model, see ex_export_function_model04.

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 an 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. On the Simulation tab and from the Prepare section, select Model Settings .

    In the Solver pane, set Solver Type to Fixed-step. In the Code generation pane, set System target file to ert.tlc. Requires an Embedded Coder® license.

  2. Display the C Code tab by selecting the Apps tab, and then in the Apps section, select Embedded Coder . On the C Code tab, select Generate Code . Wait for the code building process to complete.

  3. On the C Code tab, select Open Latest 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.