Using Function-Call Subsystems

A Function-Call Subsystem block is a conditionally executed subsystem that runs each time the control signal receives a function-call event. A Stateflow® chart, Function-Call Generator block, or an S-function block can provide function call events.

A function-call subsystem is analogous to a function in a procedural programming language. Invoking a function-call subsystem executes the output methods of the blocks within the subsystem in sorted order. For an explanation of Function-Call Subsystem blocks parameters, see Subsystem, Atomic Subsystem, Nonvirtual Subsystem, CodeReuse Subsystem

Creating a Function-Call Subsystem

To create a function-call subsystem:

  1. Add a Function-Call Subsystem block to your model.

  2. Open the subsystem block. Add a block diagram defining the algorithm that is executed when the subsystem receives a function-call event.

  3. Set initial and disabled values for the Outport blocks. See Conditional Subsystem Initial Output Values and Conditional Subsystem Output Values When Disabled.

  4. Set how subsystem states are handled when subsystem is executed.

    Open the subsystem block, and then open the block parameters dialog box for the Trigger block. From the States when enabling drop-down list, select:

    • held — States maintain their most recent values.

    • reset — States set to their initial conditions.

    • inherit — Use the held or reset setting from the parent subsystem initiating the function-call.

    For nested subsystems whose Function-Call Subsystem blocks have different parameter settings, the settings for the child subsystem override the settings inherited from the parent subsystem.

  5. Attach a function-call initiator to the function-call input port.

    If you attach an Inport block, open the block, select the Signal Attributes pane, and then select the Output function call check box.

Sample Time Propagation in a Function-Call Subsystem

Configure a Function-Call Subsystem block by setting the Sample time type of its Trigger port block to triggered or periodic.

  • A triggered (aperiodic) function-call subsystem can execute zero, one, or multiple times during a time step.

    If a function-call subsystem is executed by a root-level function-call Inport block with a discrete sample time, multiple function-calls during a time step are not allowed. To allow multiple function-calls, set Sample time to -1 (inherited), and set the sample time for all blocks in the function-call subsystem to -1 (inherited).

  • A periodic function-call subsystem executes once during a time step and must receive periodic function-calls. If the function-calls are aperiodic, the simulation stops and an error message is displayed. Set the sample time for all blocks in the function-call subsystem to -1 (inherited).

Note

During range checking, the minimum and maximum parameter settings are back-propagated to the actual source port of the function-call subsystem, even when the function-call subsystem is not enabled.

To prevent this back propagation:

  1. Add a Signal Conversion block and a Signal Specification block after the source port.

  2. Set the Output of the Signal Conversion block to Signal copy.

  3. Specify the minimum and maximum values for the Signal Specification block instead of specifying them on the source port.

Model Examples

See Also

Blocks

Related Examples

More About