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 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 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
Inport block is set to
Generate code from the model that contains the functions.
From the menu, select Simulation > Model Configuration Parameters.
In the Solver pane, set Solver Type to
In the Code generation pane, set System target file to
ert.tlc. Requires an Embedded Coder® license.
From the Simulink menu, Select Code > C/C++ Code > Build Model. Wait for the code building process to complete.
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.