Subsystem - Group blocks to create model hierarchy - Simulink (original) (raw)

Group blocks to create model hierarchy

Libraries:
Simulink / Commonly Used Blocks
Simulink / Ports & Subsystems
HDL Coder / Ports & Subsystems

Alternative Configurations of Subsystem Block:
Atomic Subsystem | Subsystem Reference | Enabled Subsystem | Triggered Subsystem | Enabled and Triggered Subsystem | ...

Description

A Subsystem block contains a subset of blocks within a model or system. The Subsystem block can represent a virtual subsystem or a nonvirtual subsystem.

For information on the types of nonvirtual subsystems, see Explore Types of Subsystems.

To determine whether a subsystem is virtual or nonvirtual, use either of these strategies:

The ports on a Subsystem block correspond to blocks inside the subsystem. For more information, see Connect Subsystems.

The Subsystem block supports signal label propagation through subsystemInport and Outport blocks. For more information, see Signal Label Propagation.

Examples

expand all

You can create a subsystem by adding a Subsystem block, then adding contents to the subsystem.

Insert a Subsystem block into your model.

For example:

  1. Open the quick-insert menu by double-clicking the Simulink® canvas.
  2. In the search box, start typing the name of the block. For example, typesubsystem.
  3. In the list that appears, select the block for the type of subsystem that you want to implement in your model. Use the arrow keys and pressEnter or click the block.

To view or edit the contents of a subsystem, double-click theSubsystem block. To exit the subsystem, below the left end of the Simulink Toolbar, click the Back button . For more information on how to navigate the hierarchy of a model with subsystems, see Navigate Model Hierarchy.

You can create a subsystem by converting part of an existing model into a subsystem.

In the Simulink canvas, drag a selection box over the model elements that you want to include in the subsystem. An ellipsis appears next to the selection box.

Model contains a Transfer Fcn block and a Gain block selected, and an ellipsis next to the selection box

Pause on the ellipsis. An action bar expands.

Ellipsis replaced by an action bar, with the Create Subsystem option selected

In the action bar, click Create Subsystem or another subsystem option.

In the block diagram, the Transfer Fcn block and a Gain block are replaced by a single Subsystem block. The signal line that connected to the input port of the Transfer Fcn block now connects to the input port of the Subsystem block, and the signal line that connected to the output port of the Gain block now connects to the output port of the Subsystem block.

To provide an interface for signals entering and leaving the subsystem, theSubsystem block contains blocks that correspond to input and output ports.

When the selection contains blocks that correspond to input and output ports, the new subsystem includes copies of those blocks. The new subsystem does not contain copies of blocks that correspond to control ports.

To replace a Subsystem block with its contents, you can expand the subsystem.

Select the Subsystem block. Then, in the Simulink Toolstrip, on the Subsystem Block tab, clickExpand.

The contents of the subsystem appear in an area labeled with the name of the replaced block.

The top image show a Sine Wave block connected to a Subsystem block connected to a Scope block. The bottom image show the same block diagram with the Subsystem block replaced by its contents. The contents are in an area labeled Subsystem.

For more information, see Expand Subsystem Contents.

To determine whether a subsystem is virtual, use the get_param function with the Boolean block parameter IsSubsystemVirtual.

Open the example. Then, open the SubsystemExecution model.

open_system("SubsystemExecution");

Check whether the Subsystem block named discrete cruise controller is virtual.

get_param("SubsystemExecution/discrete cruise controller",... "IsSubsystemVirtual")

This subsystem is nonvirtual. The thick border of the block icon indicates that the subsystem is nonvirtual.

Check whether the Subsystem block named car dynamics is virtual.

get_param("SubsystemExecution/car dynamics","IsSubsystemVirtual")

This subsystem is virtual.

Extended Examples

Ports

Input

expand all

Placing a block such as an Inport or In Bus Element block in a subsystem adds an external input port to the Subsystem block.

Use Inport or In Bus Element blocks to get signals from the local environment.

For more information, see Connect Subsystems.

Data Types: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point | enumerated | bus | image
Complex Number Support: Yes

A reinitialize event port provides a function-call control signal that triggers a subsystem reinitialize event, which resets the states of the subsystem.

For versions prior to R2025a, the subsystem must contain a Reinitialize Function block that corresponds to each subsystem reinitialize event. To specify the port name, use theEvent name parameter of the Event Listener block in the Reinitialize Function block. For more information, see Reinitialize States of Blocks in Subsystem.

Note

Starting in R2025a, you no longer need to place a Reinitialize Function block inside an atomic subsystem to display its reinitialize event port.

Dependencies

To enable this type of port, select Treat as atomic unit, and then select Show subsystem reinitialize ports.

Output

expand all

Placing a block such as an Outport or Out Bus Element block in a subsystem adds an output port from theSubsystem block.

Use Outport or Out Bus Element blocks to send signals to the local environment.

For more information, see Connect Subsystems.

Data Types: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point | enumerated | bus | image
Complex Number Support: Yes

Parameters

expand all

To edit block parameters interactively, use theProperty Inspector. From the Simulink Toolstrip, on the Simulation tab, in thePrepare gallery, select Property Inspector.

Main

Select how to display port labels on the Subsystem block icon.

For port label editing on Subsystem blocks, see Edit Port Labels on Subsystem Blocks.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: ShowPortLabels
Values: 'FromPortIcon' (default) | 'FromPortBlockName' 'SignalName' 'none'

Control user access to the contents of the subsystem.

You do not receive a response if you attempt to view the contents of a subsystem whose Read/Write permissions parameter is set to NoReadOrWrite. For example, when double-clicking such a subsystem, the software does not open the subsystem and does not display any messages.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: Permissions
Values: 'ReadWrite' (default) | 'ReadOnly' 'NoReadOrWrite'

Enter the name of a function to be called if an error occurs while the software executes the subsystem.

The software passes two arguments to the function: the handle of the subsystem and a character vector that specifies the error type. If no function is specified, the software displays a generic error message if executing the subsystem causes an error.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: ErrorFcn
Values: '' (default) | function name in quotes
Data Types: char | string

Select whether to resolve names of workspace variables referenced by this subsystem.

For more information, see Symbol Resolution and Symbol Resolution Process.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: PermitHierarchicalResolution
Values: 'All' (default) | 'ExplicitOnly' 'None'

Selecting this parameter causes the software to treat the subsystem as a unit when determining the execution order of block methods.

The default value depends on the block configuration. For example, the default value for the Subsystem block is off. The default value for the Atomic Subsystem block is on.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: TreatAsAtomicUnit
Values: 'off' | 'on'

Select this parameter to display the reinitialize event ports. Clear this parameter to remove the ports.

Dependencies

To enable this parameter, select Treat as atomic unit.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: ShowSubsystemReinitializePorts
Values: 'off' (default) | 'on'

Try to eliminate any artificial algebraic loops that include the atomic subsystem

Dependencies

To enable this parameter, select Treat as atomic unit.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: MinAlgLoopOccurrences
Values: 'off' (default) | 'on'

Specify how to schedule the subsystem.

Dependencies

To enable this parameter, select Treat as atomic unit.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: ScheduleAs
Values: 'Sample time' (default) | 'Periodic partition' 'Aperiodic partition'

Specify the name of the partition for the subsystem.

Dependencies

To enable this parameter, select Treat as atomic unit and setSchedule as to Periodic partition orAperiodic partition.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: PartitionName
Values: '' (default) | partition name in quotes
Data Types: char | string

Specify whether all blocks in this subsystem must run at the same rate or can run at different rates.

If the blocks in the subsystem can run at different rates, specify the subsystem sample time as inherited (-1).

If all blocks must run at the same rate, specify the sample time corresponding to this rate as the value of the Sample time parameter.

If any of the blocks in the subsystem specify a different sample time (other than-1 or inf), the software displays an error message when you update or simulate the model. For example, suppose all the blocks in the subsystem must run 5 times a second. To ensure this rate, specify the sample time of the subsystem as 0.2. In this example, if any of the blocks in the subsystem specify a sample time other than 0.2, -1, orinf, the software displays an error when you update or simulate the model.

Dependencies

To enable this parameter, select Treat as atomic unit.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: SystemSampleTime
Values: '-1' (default) | '[Ts 0]'

Specify whether the software treats the subsystem as a unit when propagating variant conditions from Variant Source blocks or to Variant Sink blocks.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: TreatAsGroupedWhenPropagatingVariantConditions
Values: 'on' (default) | 'off'

Dependencies

To enable this parameter, clear the Treat as atomic unit parameter.

Code Generation

Parameters on the Code Generation tab require a Simulink Coder™ or Embedded Coder® license.

Select the code format to be generated for an atomic (nonvirtual) subsystem.

For more information, see:

The default value depends on the block configuration. For example, the default value for the Subsystem block is Auto. The default value for the CodeReuseSubsystem block isReusable function.

Tips

Dependencies

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: RTWSystemCode
Values: 'Auto' | 'Inline' 'Nonreusable function' 'Reusable function'

Select how the software names the function it generates for the subsystem.

If you have an Embedded Coder license, you can control function names with options on the Configuration Parameter > pane.

For more information, see Generate Subsystem Code as Separate Function and Files (Simulink Coder).

The default value depends on the block configuration. For example, the default value for the Subsystem block is Auto. The default value for the CodeReuseSubsystem block isUse subsystem name.

Dependencies

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: RTWFcnNameOpts
Values: 'Auto' | 'Use subsystem name' 'User specified'

Specify a unique, valid C or C++ function name for subsystem code.

Use this parameter if you want to give the function a specific name instead of allowing the Simulink Coder code generator to assign its own autogenerated name or use the subsystem name. For more information, see Generate Subsystem Code as Separate Function and Files (Simulink Coder).

Dependencies

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: RTWFcnName
Values: '' (default) | function name in quotes
Data Types: char | string

Select how the software names the separate file for the function it generates for the subsystem.

The default value depends on the block configuration. For example, the default value for the Subsystem block is Auto. The default value for the CodeReuseSubsystem block isUse function name.

Dependencies

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: RTWFileNameOpts
Values: 'Auto' | 'Use subsystem name' 'Use function name' 'User specified'

The filename that you specify does not have to be unique. However, avoid giving non-unique names that result in cyclic dependencies. For example,sys_a.h includes sys_b.h,sys_b.h includes sys_c.h, andsys_c.h includes sys_a.h.

For more information, see Generate Subsystem Code as Separate Function and Files (Simulink Coder).

Dependencies

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: RTWFileName
Values: '' (default) | filename in quotes
Data Types: char | string

Select how to use arguments with the generated function.

In some cases, when generating optimized code, the code generator might not generate a function that has arguments.

For more information, see:

Dependencies

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: FunctionInterfaceSpec
Values: 'void_void' (default) | 'Allow arguments (Optimized)' 'Allow arguments (Match graphical interface)'

Generate subsystem function code in which the internal data for an atomic subsystem is separated from its parent model and is owned by the subsystem.

For details on how to generate modular function code for an atomic subsystem, seeGenerate Modular Function Code for Nonvirtual Subsystems (Embedded Coder).

For details on how to apply memory sections to atomic subsystems, see Override Default Memory Placement for Subsystem Functions and Data (Embedded Coder).

Dependencies

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: FunctionWithSeparateData
Values: 'off' (default) | 'on'

Select how the software applies memory sections to the subsystem initialization and termination functions.

Tips

Dependencies

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: RTWMemSecFuncInitTerm
Values: 'Inherit from model' (default) | 'Default' model memory section in quotes

Select how Embedded Coder applies memory sections to the subsystem execution functions.

Tips

Dependencies

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: RTWMemSecFuncExecute
Values: 'Inherit from model' (default) | 'Default' model memory section in quotes

Select how the software applies memory sections to the subsystem constants.

Tips

Dependencies

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: RTWMemSecDataConstants
Values: 'Inherit from model' (default) | 'Default' model memory section in quotes

Select how the software applies memory sections to the subsystem internal data.

Tips

Dependencies

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: RTWMemSecDataInternal
Values: 'Inherit from model' (default) | 'Default' model memory section in quotes

Select how the software applies memory sections to the subsystem parameters.

Tips

Dependencies

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: RTWMemSecDataParameters
Values: 'Inherit from model' (default) | 'Default' model memory section in quotes

Subsystem Reference

Specify the subsystem file you want to reference. For information about subsystem references, see Create and Use Referenced Subsystems in Models.

Dependencies

To access this parameter, in the Subsystem Reference section, click Convert.

For more information on how to convert a subsystem to a referenced subsystem, see Convert Subsystem to a Referenced Subsystem.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: ReferencedSubsystem
Values: '' (default) | subsystem filename in quotes
Data Types: char | string

Block Characteristics

Data Types Booleana | busa doublea enumerateda fixed pointa halfa imagea integera singlea stringa
Direct Feedthrough no
Multidimensional Signals yesa
Variable-Size Signals yesa
Zero-Crossing Detection no
a Actual data type or capability support depends on block implementation.

Alternative Configurations

expand all

The Atomic Subsystem block selects the Treat as atomic unit parameter.

Libraries:
Simulink / Ports & Subsystems
HDL Coder / Ports & Subsystems

Libraries:
Simulink / Ports & Subsystems

Libraries:
Simulink / Ports & Subsystems
HDL Coder / Ports & Subsystems

The Triggered Subsystem is a template that contains a Trigger block with Trigger type set torising.

Libraries:
Simulink / Ports & Subsystems
HDL Coder / Ports & Subsystems

The Enabled and Triggered Subsystem is a template that contains an Enable block and a Trigger block with Trigger type set torising.

Libraries:
Simulink / Ports & Subsystems

Libraries:
Simulink / Ports & Subsystems

The If Action Subsystem is a template for creating a subsystem whose execution is controlled by an If block. The subsystem contains an Action Port block.

Libraries:
Simulink / Ports & Subsystems

The Switch Case Action Subsystem is a template for creating a subsystem whose execution is controlled by a Switch Case block. The subsystem contains an Action Port block.

Libraries:
Simulink / Ports & Subsystems

The Function-Call Subsystem is a template that contains a Trigger block with Trigger type set tofunction-call.

Libraries:
Simulink / Ports & Subsystems

Libraries:
Simulink / Ports & Subsystems

Libraries:
Simulink / Ports & Subsystems

Libraries:
Simulink / Ports & Subsystems
HDL Coder / Ports & Subsystems

Since R2022a

The Message Polling Subsystem is a template that contains a Trigger block withTrigger type set to message andTrigger time set to on sample time hit. The Trigger block replaces the Inport block.

Libraries:
Simulink / Messages & Events

Since R2022a

The Message Triggered Subsystem is a template that contains a Trigger block withTrigger type set to message andTrigger time set to on message available. The Trigger block replaces theInport block.

Libraries:
Simulink / Messages & Events

The CodeReuseSubsystem block selects the Treat as atomic unit parameter and sets Function packaging toReusable function.

Libraries:
Simulink / Ports & Subsystems

Since R2022b

Libraries:
Simulink / Matrix Operations

Tips

Extended Capabilities

expand all

Actual code generation support depends on block implementation.

HDL Coder™ provides additional configuration options that affect HDL implementation and synthesized logic.

HDL Architecture

Architecture Description
Module (default) Generate code for the subsystem and the blocks within the subsystem.
BlackBox Generate a black box interface. The generated HDL code includes only the input/output port definitions for the subsystem. Therefore, you can use a subsystem in your model to generate an interface to existing, manually written HDL code. The black-box interface generation for subsystems is similar to the Model block interface generation without the clock signals.
No HDL Remove the subsystem from the generated code. You can use the subsystem in simulation, however, treat it as a “no-op” in the HDL code.

HDL Block Properties

General
AdaptivePipelining Automatic pipeline insertion based on the synthesis tool, target frequency, and multiplier word-lengths. The default is inherit. See alsoAdaptivePipelining (HDL Coder).
ClockRatePipelining Insert pipeline registers at a faster clock rate instead of the slower data rate. The default is inherit. See also ClockRatePipelining (HDL Coder).
ConstrainedOutputPipeline Number of registers to place at the outputs by moving existing delays within your design. Distributed pipelining does not redistribute these registers. The default is0. For more details, see ConstrainedOutputPipeline (HDL Coder).
DistributedPipelining Pipeline register distribution, or register retiming. The default is inherit. See also DistributedPipelining (HDL Coder).
DSPStyle Synthesis attributes for multiplier mapping. The default is none. See also DSPStyle (HDL Coder).
FlattenHierarchy Remove subsystem hierarchy from generated HDL code. The default is inherit. See also FlattenHierarchy (HDL Coder).
InputPipeline Number of input pipeline stages to insert in the generated code. Distributed pipelining and constrained output pipelining can move these registers. The default is0. For more details, see InputPipeline (HDL Coder).
OutputPipeline Number of output pipeline stages to insert in the generated code. Distributed pipelining and constrained output pipelining can move these registers. The default is0. For more details, see OutputPipeline (HDL Coder).
SharingFactor Number of functionally equivalent resources to map to a single shared resource. The default is 0. See also Resource Sharing (HDL Coder).
StreamingFactor Number of parallel data paths, or vectors, that are time multiplexed to transform into serial, scalar data paths. The default is 0, which implements fully parallel data paths. See also Streaming (HDL Coder).

If this block is not the DUT, the block property settings in the Target Specification tab are ignored. In the HDL Workflow Advisor, if you use theIP Core Generation workflow, these target specification block property values are saved with the model. If you specify these target specification block property values using hdlset_param, when you open HDL Workflow Advisor, the fields are populated with the corresponding values.

Target Specification
AdditionalTargetInterfaces Additional target interfaces, specified as a character vector. To save this block property on the model, in the Set Target Interface task of the IP Core Generation workflow, corresponding to the DUT ports that you want to add more interfaces, select Add more.... You can then add more interfaces in the Add New Target Interfaces dialog box. Specify the type of interface, number of additional interfaces, and a unique name for each additional interface. Values: '' (default) | cell array of character vectors Example:'{{'AXI4-Stream','InterfaceID','AXI4-Stream1'}}'
ProcessorFPGASynchronization Processor/FPGA synchronization mode, specified as a character vector. To save this block property on the model, specify the Processor/FPGA Synchronization in the Set Target Interface task of the IP Core Generation workflow.Values: Free running (default) | Coprocessing - blockingExample: 'Free running'
TestPointMapping To save this block property on the model, specify the mapping of test point ports to target platform interfaces in the Set Target Interface task of the IP Core Generation workflow.Values: '' (default) | cell array of character vectorsExample: '{{'TestPoint','AXI4-Lite','x"108"'}}'
TunableParameterMapping To save this block property on the model, specify the mapping of tunable parameter ports to target platform interfaces in the Set Target Interface task of the IP Core Generation workflow.Values: '' (default) | cell array of character vectorsExample: '{{'myParam','AXI4-Lite','x"108"'}}'
AXI4RegisterReadback To save this block property on the model, specify whether you want to enable readback on AXI4 subordinate write registers in the Generate RTL Code and IP Core task of the IP Core Generation workflow. To learn more, see Model Design for AXI4 Slave Interface Generation (HDL Coder).Values: 'off' (default) |'on'
AXI4SlaveIDWidth To save this block property on the model, specify the number of AXI manager interfaces that you want to connect the DUT IP core to by using the AXI4 Slave ID Width setting in the Generate RTL Code and IP Core task of the IP Core Generation workflow. To learn more, see Define Multiple AXI Master Interfaces in Reference Designs to Access DUT AXI4 Slave Interface (HDL Coder). Values: 'off' (default) |'on'
RegisterInterfaceReadPipeline To save this block property on the model, Specify the number of pipeline stages to insert in the read address decoder path by using theRegister interface read pipeline setting in the Generate RTL Code and IP Core task of the IP Core Generation workflow. To learn more, see Model Design for AXI4 Slave Interface Generation (HDL Coder). Values: 0 (default) | character vector
GenerateDefaultAXI4Slave To save this block property on the model, specify whether you want to disable generation of default AXI4 subordinate interfaces in the Generate RTL Code and IP Core task of the IP Core Generation workflow.Values: 'on' (default) |'off'
IPCoreAdditionalFiles Verilog®, SystemVerilog, or VHDL® files for black boxes in your design. Specify the full path to each file, and separate file names with a semicolon (;).You can set this property in the HDL Workflow Advisor, in the Additional source files field.Values: '' (default) | character vectorExample: 'C:\myprojfiles\led_blinking_file1.vhd;C:\myprojfiles\led_blinking_file2.vhd;'
IPCoreName IP core name, specified as a character vector.You can set this property in the HDL Workflow Advisor, in the IP core name field. If this property is set to the default value, the HDL Workflow Advisor constructs the IP core name based on the name of the DUT.Values: '' (default) | character vectorExample: 'my_model_name'
IPCoreVersion IP core version number, specified as a character vector.You can set this property in the HDL Workflow Advisor, in the IP core version field. If this property is set to the default value, the HDL Workflow Advisor sets the IP core version.Values: '' (default) | character vectorExample: '1.3'
IPDataCaptureBufferSize FPGA Data Capture buffer size, specified as a character vector. Use FPGA Data Capture to observe signals in a design when running on an FPGA. The buffer size uses values that are 128*2^n, where n is an integer. By default, the buffer size is 128 (n=0). The maximum value of n is 13, which means that the maximum value for buffer size is 1048576 (=128*2^13). Values: '' (default) | character vector Example: '1.3'

Generate HDL Code with Algebraic Loops

To generate HDL code for models that contain Subsystem blocks:

Subsystem must be atomic to support PLC code generation.

PLC Block Properties

UseExternalDefinition Suppress block definition in generated code. The default isOff. See also UseExternalDefinition (Simulink PLC Coder).

Actual data type support depends on block implementation.

Version History

Introduced in R2007a