Main Content

Using Function-Call Subsystems

AFunction-Call Subsystemblock is a conditionally executed subsystem that runs each time the control port receives a function-call event. A Stateflow®chart,Function-Call Generatorblock,MATLAB Functionblock,S-Functionblock, orHit Crossingblock 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 execution order. For an explanation of theFunction-Call Subsystemblock parameters, seeSubsystem.

Creating a Function-Call Subsystem

创建一个函数调用子系统:

  1. Add aFunction-Call Subsystemblock 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 theOutportblocks. SeeConditional Subsystem Initial Output ValuesandConditional Subsystem Output Values When Disabled.

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

    Open the subsystem block, then open the block parameters dialog box for theTriggerblock. From theStates when enablingdrop-down list, select an option:

    • 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 whoseFunction-Call Subsystemblocks have different parameter settings, the settings for the child subsystem override the settings inherited from the parent subsystem. SeeTrigger.

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

    如果你一个ttach anInportblock, open the block, select the Signal Attributes tab, then select theOutput function callcheck box.

Sample Time Propagation in a Function-Call Subsystem

Configure aFunction-Call Subsystemblock by setting theSample time typeof itsTrigger Portblock totriggeredorperiodic.

  • 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-callInportblock with a discrete sample time, multiple function-calls during a time step are not allowed. To allow multiple function-calls, setSample timeto-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 each time step when it receives a function-call signal, and does not execute at a time step when it does not receive a function-call signal. 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 aSignal Conversionblock and aSignal Specificationblock after the source port.

  2. Set theOutputof theSignal Conversionblock toSignal copy.

  3. Specify the minimum and maximum values for theSignal Specificationblock instead of specifying them on the source port.

Latched Input Data for Function-Call Subsystems

You can latch input data forInportblocks withinFunction-Call Subsystemblocks to ensure data integrity. To latch input data, in theInportblock parameters, selectLatch input for feedback signals of function-call subsystem outputs.

In the following model, input data for theInportblock in the function-call subsystemReadDSAndCal1is latched (indicated by

  • 我的理解是,t change during the execution of the subsystem. TheData Store ReadandData Store Writeblocks are called within each function-call subsystem. The first and second function-calls write data and the last function-call reads data to theData Store Memoryblock.

    Note

    The root-level dataInportblock connected to an internalInportblock is also latched if all of the blocks connected to the root-level block are latched. For more information, seeLatch input for feedback signals of function-call subsystem outputs.

    Note

    Data transfer signals are unprotected in the generated code by default. Use custom storage classes to prevent data corruption in these signals due to preemption of the current task in the target environment.

  • Model Examples

    See Also

    Blocks

    Related Examples

    More About