Create an 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. See Export-Function Models Overview.
To open a completed export-function model, see
Designate Model as Export-Function Model and Satisfy Export-Function Model Requirements
Designate the model as an export-function model. Click the canvas to clear the selection from any blocks, then open the Property Inspector and go to the Execution tab. Select the Set execution domain check box and, from the Domain list, select
Open the Configuration Parameters dialog box. On the Modeling tab and from the Setup section, 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.
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.
Attach Inport blocks to the
function()input ports on the Function-Call Subsystem blocks.
Specify sample times. Open the Inport block dialogs and select the Signal Attributes tab. Select the Output function call check box. 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, Simulink 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.
After you create an export-function model, you can test it with simulations. Choose one of these simulation testing methods: Test Export-Function Model Simulation Using Input Matrix, Test Export-Function Model Simulation Using Function-Call Generators, or Test Export-Function Model Simulation Using Stateflow Chart.
- Export-Function Models Overview
- Test Export-Function Model Simulation Using Input Matrix
- Test Export-Function Model Simulation Using Function-Call Generators
- Test Export-Function Model Simulation Using Stateflow Chart
- Test Export-Function Model Simulation Using Schedule Editor
- Generate Code for Export-Function Model