Main Content

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:

  1. Click the canvas to clear the selection from any blocks.

  2. Open the Property Inspector and go to the Execution tab.

  3. Select the Set execution domain parameter.

  4. From the Domain list, select Export function.

To satisfy export-function model requirements:

  1. Open the Configuration Parameters dialog box. On the Modeling tab, select Model Settings .

  2. In the Solver pane, set solver selection Type to Fixed-step, Solver to auto, and Fixed-step size to auto.

  3. 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.

  1. Add two Function-Call Subsystem blocks.

  2. In the first subsystem, model a unit delay that increments by 0.05 at each time step.

    Function-call subsystem contents with Unit Delay, Bias, and Outport blocks

  3. In the second subsystem, model the square of an input signal.

    Function-call subsystem contents with Inport, Square, and Outport blocks

  4. At the top level of the model, add Inport and Outport blocks.

    Model with two function-call subsystems with input and output ports connected

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.

  1. Connect Inport blocks to the function() input ports on the Function-Call Subsystem blocks.

  2. 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 0.01 (10 ms).

    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 -1 and 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.

  3. Rename blocks. The names help to identify signals in the generated code.

  4. Update the model (Ctrl+D). Dotted-and-dashed lines identify function-call signals.

    Model with function-call signals connected to function ports of function-call subsystems

Export-Function Model with Unit Delay and Square Functions

To open the completed export-function model, open the model named export_function_model.

The model contains two function-call subsystems. One subsystem contains a Unit Delay block, while the other subsystem contains a Square block.

Test Model

After you create an export-function model, test it with simulations. Choose one of these simulation testing methods:

See Also

Related Topics