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
Create Export-Function Model with Scheduled Subsystems
Create a model with function-call and scheduled subsystems.
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.
Create an export-function model with function-call subsystems. See Create an Export-Function Model.
Include the rate-based model in the export-function model by reference from a Model block.
Display periodic event ports on the Model block by selecting the Schedule rates check box.
Connect Inport blocks to the periodic event ports.
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 10msInport block is set to
Generate Code for Exported Functions
Generate code from the model that contains the functions.
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.
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.
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.