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 the scheduled subsystems. Then, reference the rate-based model from an export-function model by using a Model block.
Create Export-Function Model with Scheduled Subsystems and Rate-Based Model
Create a rate-based model with scheduled subsystems. See Create Rate-Based Model.
In this example, the Sample time for the scheduled subsystem is set to
0.01
.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 referencing the rate-based model from a Model block.
Display periodic event ports on the Model block by selecting the Schedule rates block parameter.
Connect Inport blocks to the periodic event ports.
For Inport blocks connected to periodic event ports, select the Output function-call block parameter and specify the sample time with the same sample time from the scheduled subsystem.
In this example, the Sample time for the Inport block named
function-call 10ms
is set to0.01
.
The completed export-function model includes both a function-call subsystem and a scheduled subsystem.
Generate Code for Export-Function Model with Rate-Based Model
When you generate code for an export-function model that references a rate-based model, the generated code for the rate-based model is integrated into the generated code for the export-function model.
Optionally, open the completed export-function model named export_function_model_with_rate_based_model
.
To generate code for the exported functions:
In the Simulink® Toolstrip, on the Modeling tab, click Model Settings. The Configuration Parameters dialog box opens.
On the Solver pane, set Type to
Fixed-step
.On the Code Generation pane, set System target file to
ert.tlc
, which requires an Embedded Coder® license.In the Simulink Toolstrip, on the Apps tab, in the Apps gallery, select Embedded Coder.
On the C Code tab that opens, click Generate Code.
In the Code Generation Report dialog box that opens, under Code > Model files, select the C file.
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.