Create Export-Function Model
The first step for creating independent functions in the generated code from a Simulink® model is to define the functions in the context of an export-function model. For high-level information about export-function models, see Export-Function Models Overview.
Designate Model as Export-Function Model and Satisfy Export-Function Model Requirements
To designate a model as an export-function model:
Click the canvas to clear the selection from any blocks.
Open the Property Inspector and go to the Execution tab.
Select the Set execution domain parameter.
From the Domain list, select
To satisfy export-function model requirements:
Open the Configuration Parameters dialog box. On the Modeling tab, select Model Settings .
In the Solver pane, set solver selection Type to
Fixed-step, Solver to
auto, and Fixed-step size to
In the Code Generation pane, set System target file to
ert.tlc. This step requires an Embedded Coder® license.
Create Model Algorithms
At the top level of an export-function model, functions are modeled within Function-Call Subsystem, function-call Model, Simulink Function, and S-Function blocks. This example uses Function-Call Subsystem blocks to model two functions.
Add two Function-Call Subsystem blocks.
In the first subsystem, model a unit delay that increments by 0.05 at each time step.
In the second subsystem, model the square of an input signal.
At the top level of the model, add Inport and Outport blocks.
Add Function-Call Inputs
Inport blocks configured to output function-call signals control the execution of Function-Call Subsystem blocks during a simulation. The function-call Inport blocks also create an entry-point function in the generated code.
Connect Inport blocks to the
function()input ports on the Function-Call Subsystem blocks.
Specify sample times. Open the Inport block dialog boxes and select the Signal Attributes tab. Select the Output function call parameter. Set Sample time for the delay function to
0.1(100 ms) and the square function to
Setting the sample time is only for simulation testing. Sample time values do not affect the generated code. However, comments are added in the code identifying the rate you should call the functions.
You could set the sample times to
-1and allow any function-call rate (periodic or aperiodic) during simulation. By setting sample times, the software checks the calling rate with the specified rate and displays an error if there is a mismatch.
Rename blocks. The names help to identify signals in the generated code.
Update the model (Ctrl+D). Dotted-and-dashed lines identify function-call signals.
Export-Function Model with Unit Delay and Square Functions
To open the completed export-function model, open the model named
The model contains two function-call subsystems. One subsystem contains a Unit Delay block, while the other subsystem contains a Square block.
After you create an export-function model, test it with simulations. Choose one of these simulation testing methods: