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,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
To create a function-call subsystem:
Add aFunction-Call Subsystemblock to your model.
Open the subsystem block. Add a block diagram defining the algorithm that is executed when the subsystem receives a function-call event.
设置初始和残疾的值Outportblocks. SeeConditional Subsystem Initial Output ValuesandConditional Subsystem Output Values When Disabled.
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.
Attach a function-call initiator to the function-call input port.
If you attach 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 totriggered
orperiodic
.
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 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:
Add aSignal Conversionblock and aSignal Specificationblock after the source port.
Set theOutputof theSignal Conversionblock to
Signal copy
.Specify the minimum and maximum values for theSignal Specificationblock instead of specifying them on the source port.
Model Examples
See Also
Blocks
- Function-Call Feedback Latch|Function-Call Generator|Function-Call Split|Function-Call Subsystem|Subsystem|Trigger
Related Examples
- Export-Function Models Overview
- Generate Component Source Code for Export to External Code Base(Embedded Coder)
- Context-dependent inputs
- Check usage of function-call connections
- Check for potentially delayed function-call subsystem return values