Main Content

Guidelines for Using Simulink Functions

Use Alphanumeric Characters and Underscores in Argument Names

By using alphanumeric characters for argument names, you ensure that the names of Inport and Output blocks are compatible with the identifier naming rules of Stateflow® charts.

Explicitly Set the Properties of Inport Blocks

The Inport blocks in a Simulink® function cannot inherit their data types and sizes. You must set the Data type and Port dimensions of each Inport block that is not a scalar of type double.

The Outport blocks in a Simulink function can inherit sizes and data types based on the connections inside the subsystem. You can specify the Data type and Port dimensions of these blocks as inherited.

Tip

To make it easier to update the properties of Inport blocks, you can specify data types and sizes as parameters.

Convert Discontiguous Signals to Contiguous Signals

Outport blocks in Simulink functions do not support discontiguous signals. If your function contains a block that outputs a discontiguous signal, insert a Signal Conversion (Simulink) block between the discontiguous output and the Outport block. This ensures that the output signal is contiguous.

Blocks that can output a discontiguous signal include the Bus Creator (Simulink) block and the Mux (Simulink) block. For the Bus Creator block, the output is discontiguous when the block outputs a virtual bus. If you select Output as nonvirtual bus, the output signal is contiguous and no conversion is necessary. For more information, see Create Nonvirtual Buses (Simulink).

Do Not Export Simulink Functions

Exporting a Simulink function results in a run-time error during simulation. To avoid this error, open the Chart Properties dialog box and clear the Export Chart Level Functions check box.

Do Not Use Simulink Functions in Moore Charts

You cannot use Simulink functions in Moore charts. This restriction prevents violations of Moore semantics during chart execution.

Do Not Call Simulink Functions in Default Transitions That Execute During Chart Initialization

If you select the chart property Execute (enter) Chart At Initialization, you cannot call Simulink functions in default transitions that execute the first time that the chart awakens. Otherwise, the chart generates a run-time error during simulation.

Do Not Call Simulink Functions in State During Actions Or Transition Conditions of Continuous-time Charts

In continuous-time charts, you cannot call Simulink functions during minor time steps. Instead, call Simulink functions in actions that occur during major time steps: state entry or exit actions and transition actions. Calling Simulink functions in state during actions or transition conditions results in a run-time error during simulation.

Do Not Generate HDL Code for Simulink Functions

Simulink functions do not support HDL code generation. Generating HDL code for charts that contain Simulink functions results in a run-time error during simulation.

Pass Arguments by Value

Passing an argument to a Simulink function by reference results in a run-time error during simulation.

Related Topics