Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Subsystem, Atomic Subsystem, Nonvirtual Subsystem, CodeReuse Subsystem

Represent system within another system

Library

Ports & Subsystems

Description

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

In nonvirtual subsystems, you can control when the contents of the subsystem are evaluated. Nonvirtual subsystems are executed as a single unit (atomic execution). You can create conditionally executed nonvirtual subsystems that execute only when a transition occurs on a triggering, function-call, action, or enabling input (see Conditional Subsystems).

A subsystem is virtual if the block is neither conditionally executed nor atomic.

    Tip   To determine if a subsystem is virtual, use the get_param function for the Boolean block parameter IsSubsystemVirtual.

An Atomic Subsystem block is a subsystem block in which Treat as atomic unit is selected by default.

A CodeReuse Subsystem block is a subsystem block in which Treat as atomic unit is selected and Function packaging is set to Reusable function, specifying the function code generation format for the subsystem. (see Function packaging for details).

To create a subsystem, do one of the following:

  • Copy a subsystem block from the Ports & Subsystems library into your model. Then add blocks to the subsystem by opening the subsystem block and copying blocks into it.

  • Select all blocks and lines that make up the subsystem, and select Diagram > Subsystem & Model Reference > Create Subsystem from Selection. Simulink® replaces the blocks with a subsystem block, along with the necessary Inport and Outport blocks to reflect signals entering and leaving the subsystem.

The number of input ports drawn on the subsystem block's icon corresponds to the number of Inport blocks in the subsystem. Similarly, the number of output ports drawn on the block corresponds to the number of Outport blocks in the subsystem.

The subsystem block supports signal label propagation through subsystem Inport and Outport blocks.

See Create a Subsystem for more information.

Data Type Support

See Inport for information on the data types accepted by a subsystem's input ports. See Outport for information on the data types output by a subsystem's output ports.

For more information, see Data Types Supported by Simulink in the Simulink documentation.

Parameters and Dialog Box

    Note:   Parameters on the Code Generation tab require a Simulink Coder™ or Embedded Coder® license. For more information, see the parameter sections.

Show port labels

Cause Simulink software to display labels for the subsystem's ports on the subsystem's icon.

Settings

Default: FromPortIcon

none

Does not display port labels on the subsystem block.

FromPortIcon

If the corresponding port icon displays a signal name, display the signal name on the subsystem block. Otherwise, display the port block's name.

FromPortBlockName

Display the name of the corresponding port block on the subsystem block.

SignalName

If a name exists, display the name of the signal connected to the port on the subsystem block; otherwise, the name of the corresponding port block.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Read/Write permissions

Control user access to the contents of the subsystem.

Settings

Default: ReadWrite

ReadWrite

Enables opening and modification of subsystem contents.

ReadOnly

Enables opening but not modification of the subsystem. If the subsystem resides in a block library, you can create and open links to the subsystem and can make and modify local copies of the subsystem but cannot change the permissions or modify the contents of the original library instance.

NoReadOrWrite

Disables opening or modification of subsystem. If the subsystem resides in a library, you can create links to the subsystem in a model but cannot open, modify, change permissions, or create local copies of the subsystem.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Name of error callback function

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

Settings

Default: ' '

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

Command-Line Information

See Block-Specific Parameters for the command-line information.

Permit hierarchical resolution

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

Settings

Default: All

All

Resolve all names of workspace variables used by this subsystem, including those used to specify block parameter values and Simulink data objects (for example, Simulink.Signal objects).

ExplicitOnly

Resolve only names of workspace variables used to specify block parameter values, data store memory (where no block exists), signals, and states marked as "must resolve".

None

Do not resolve any workspace variable names.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Treat as atomic unit

Causes Simulink software to treat the subsystem as a unit when determining the execution order of block methods.

Settings

Default: Off

On

Cause Simulink software to treat the subsystem as a unit when determining the execution order of block methods. For example, when it needs to compute the output of the subsystem, Simulink software invokes the output methods of all the blocks in the subsystem before invoking the output methods of other blocks at the same level as the subsystem block.

Off

Cause Simulink software to treat all blocks in the subsystem as being at the same level in the model hierarchy as the subsystem when determining block method execution order. This can cause execution of methods of blocks in the subsystem to be interleaved with execution of methods of blocks outside the subsystem.

Dependencies

This parameter enables:

Command-Line Information

See Block-Specific Parameters for the command-line information.

Minimize algebraic loop occurrences

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

Settings

Default: Off

On

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

Off

Do not try to eliminate any artificial algebraic loops that include the atomic subsystem.

Dependency

Treat as atomic unit enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Propagate execution context across subsystem boundary

Enable execution context propagation across the boundary of this subsystem.

Settings

Default: Off

On

Enables execution context propagation across this subsystem's boundary.

Off

Does not enable execution context propagation across this subsystem's boundary.

Dependency

Conditional execution of the subsystem enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Warn if function-call inputs are context-specific

Simulink displays a warning if it has to compute any of this function-call subsystem's inputs directly or indirectly during execution of a function-call.

Settings

Default: Off

On

Simulink displays a warning if it has to compute any of this function-call subsystem's inputs directly or indirectly during execution of a function-call.

Off

Simulink does not display a warning if it has to compute any of this function-call subsystem's inputs directly or indirectly during execution of a function-call.

Dependency

Use of a function-call subsystem enables this parameter.

The option is effective only when the Context-dependent inputs diagnostic on the Diagnostics > Connectivity pane of the Configuration Parameters dialog box is set to Use local settings.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Sample time (-1 for inherited)

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

Settings

Default: -1

  • -1

    Specify the inherited sample time. Use this sample time if the blocks in the subsystem can run at different rates.

  • [Ts 0]

    Specify periodic sample time.

Tips

  • If the blocks in the subsystem can run at different rates, specify the subsystem's 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 subsystem's Sample time parameter.

  • If any of the blocks in the subsystem specify a different sample time (other than -1 or inf), Simulink 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, 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, or inf, Simulink software displays an error when you update or simulate the model.

Dependency

Treat as atomic unit enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Function packaging

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

Settings

Default: Auto

Auto

Simulink Coder software chooses the optimal format for you based on the type and number of instances of the subsystem that exist in the model.

Inline

Simulink Coder software inlines the subsystem unconditionally.

Nonreusable function

Simulink Coder software explicitly generates a separate function in a separate file. Subsystems with this setting generate functions that might have arguments depending on the Function interface parameter setting. You can name the generated function and file using parameters Function name and File name (no extension). These functions are not reentrant.

Reusable function

Simulink Coder software generates a function with arguments that allows reuse of subsystem code when a model includes multiple instances of the subsystem.

This option also generates a function with arguments that allows subsystem code to be reused in the generated code of a model reference hierarchy that includes multiple instances of a subsystem across referenced models. In this case, the subsystem must be in a library.

Tips

  • When you want multiple instances of a subsystem to be represented as one reusable function, you can designate each one of them as Auto or as Reusable function. It is best to use one or the other, as using both creates two reusable functions, one for each designation. The outcomes of these choices differ only when reuse is not possible. Selecting Auto does not allow control of the function or file name for the subsystem code.

  • The Reusable function and Auto options both try to determine if multiple instances of a subsystem exist and if the code can be reused. The difference between the options' behavior is that when reuse is not possible:

    • Auto yields inlined code, or if circumstances prohibit inlining, separate functions without arguments for each subsystem instance.

    • Reusable function yields a separate function with arguments for each subsystem instance in the model.

  • If you select Reusable function while your generated code is under source control, set File name options to Use subsystem name, Use function name, or User specified. Otherwise, the names of your code files change whenever you modify your model, which prevents source control on your files.

Dependencies

Command-Line Information

See Block-Specific Parameters for the command-line information.

Function name options

Specify how Simulink Coder software is to name the function it generates for the subsystem.

Settings

Default: Auto

Auto

Assign a unique function name using the default naming convention, model, _subsystem(), where model is the name of the model and subsystem is the name of the subsystem (or that of an identical one when code is being reused).

If you select Reusable function for the Function packaging parameter and there are multiple instances of the reusable subsystem in a model reference hierarchy, in order to generate reusable code for the subsystem, Function name options must be set to Auto.

Use subsystem name

Use the subsystem name as the function name.

    Note   When a subsystem is a library block and the subsystem parameter Function packaging is set to Reusable function, if you set the Use subsystem name option, the code generator uses the name of the library block for the subsystem's function name and file name.

User specified

This option enables the Function name field. Enter any legal C or C++ function name, which must be unique.

Dependencies

  • This parameter requires a Simulink Coder license.

  • Setting Function packaging to Nonreusable function or Reusable function enables this parameter.

  • Setting this parameter to User specified enables the Function name parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Function name

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

Settings

Default: ' '

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.

Dependencies

  • This parameter requires a Simulink Coder license.

  • Setting Function name options to User specified enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

File name options

Specify how Simulink Coder software names the separate file for the function it generates for the subsystem.

Settings

Default: Auto

Auto

Depending on the configuration of the subsystem and how many instances are in the model, Auto yields different results:

  • If the code generator does not generate a separate file for the subsystem, the subsystem code is generated within the code module generated from the subsystem's parent system. If the subsystem's parent is the model itself, the subsystem code is generated within model.c or model.cpp.

  • If you select Reusable function for the Function packaging parameter and your generated code is under source control, consider specifying a File name options value other than Auto. This prevents the generated file name from changing due to unrelated model modifications, which is problematic for using source control to manage configurations.

  • If you select Reusable function for the Function packaging parameter and there are multiple instances of the reusable subsystem in a model reference hierarchy, in order to generate reusable code for the subsystem, File name options must be set to Auto.

Use subsystem name

The code generator generates a separate file, using the subsystem (or library block) name as the file name.

    Note   When File name options is set to Use subsystem name, the subsystem file name is mangled if the model contains Model blocks, or if a model reference target is being generated for the model. In these situations, the file name for the subsystem consists of the subsystem name prefixed by the model name.

Use function name

The code generator uses the function name specified by Function name options) as the file name.

User specified

This option enables the File name (no extension) text entry field. The code generator uses the name you enter as the file name. Enter any file name, but do not include the .c or .cpp (or any other) extension. This file name need not be unique.

    Note   While a subsystem source file name need not be unique, you must avoid giving nonunique names that result in cyclic dependencies (for example, sys_a.h includes sys_b.h, sys_b.h includes sys_c.h, and sys_c.h includes sys_a.h).

Dependencies

  • This parameter requires a Simulink Coder license.

  • Setting Function packaging to Nonreusable function or Reusable function enables this parameter.

  • Setting this parameter to User specified enables the File name (no extension) parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

File name (no extension)

Specify how Simulink Coder software is to name the file for the function it generates for the subsystem.

Settings

Default: ' '

  • 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, and sys_c.h includes sys_a.h).

Dependencies

  • This parameter requires a Simulink Coder license.

  • Setting File name options to User specified enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Function with separate data

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.

Settings

Default: Off

On

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. The subsystem data structure is declared independently from the parent model data structures. A subsystem with separate data has its own block I/O and DWork data structure. As a result, the generated code for the subsystem is easier to trace and test. The data separation also tends to reduce the maximum size of global data structures throughout the model, because they are split into multiple data structures.

Off

Do not 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.

Dependencies

Command-Line Information

See Block-Specific Parameters for the command-line information.

Function interface

For this subsystem, specify whether the generated function uses arguments.

Settings

Default: void_void

void_void

Generate a function without arguments and passes data as global variables. For example:

void subsystem_function(void)
Allow arguments

Generate a function that uses arguments instead of passing data as global variables. This specification reduces global RAM. It might reduce code size and improve execution speed, and allow the code generator to apply additional optimizations. For example:

void subsystem_function(real_T rtu_In1, real_T rtu_In2, 
                        real_T *rty_Out1)

Dependencies

  • This parameter requires an Embedded Coder license and an ERT-based system target file.

  • Setting Function packaging to Nonreusable function enables this parameter.

Command-Line Information

For the command-line information, see Block-Specific Parameters.

Memory section for initialize/terminate functions

Indicate how the Embedded Coder software is to apply memory sections to the subsystem's initialization and termination functions.

Settings

Default: Inherit from model

Inherit from model

Apply the root model's memory sections to the subsystem's function code

Default

Not apply memory sections to the subsystem's system code, overriding any model-level specification

The memory section of interest

Apply one of the model's memory sections to the subsystem

Tips

  • The possible values vary depending on what (if any) package of memory sections you have set for the model's configuration. See About Memory Sections, Configure Memory Sections, and Code Generation Pane: Memory Sections in the Embedded Coder documentation.

  • If you have not configured the model with a package, Inherit from model is the only value that appears. Otherwise, the list includes Default and all memory sections the model's package contains.

  • These options can be useful for overriding the model's memory section settings for the given subsystem.

Dependencies

  • This parameter requires a license for Embedded Coder software and an ERT-based system target file.

  • Setting Function packaging to Nonreusable function or Reusable function enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Memory section for execution functions

Indicate how the Embedded Coder software is to apply memory sections to the subsystem's execution functions.

Settings

Default: Inherit from model

Inherit from model

Apply the root model's memory sections to the subsystem's function code

Default

Not apply memory sections to the subsystem's system code, overriding any model-level specification

The memory section of interest

Apply one of the model's memory sections to the subsystem

Tips

  • The possible values vary depending on what (if any) package of memory sections you have set for the model's configuration. See About Memory Sections, Configure Memory Sections, and Code Generation Pane: Memory Sections in the Embedded Coder documentation.

  • If you have not configured the model with a package, Inherit from model is the only value that appears. Otherwise, the list includes Default and all memory sections the model's package contains.

  • These options can be useful for overriding the model's memory section settings for the given subsystem.

Dependencies

  • This parameter requires a license for Embedded Coder software and an ERT-based system target file.

  • Setting Function packaging to Nonreusable function or Reusable function enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Memory section for constants

Indicate how the Embedded Coder software is to apply memory sections to the subsystem's data.

Settings

Default: Inherit from model

Inherit from model

Apply the root model's memory sections to the subsystem's data

Default

Not apply memory sections to the subsystem's data, overriding any model-level specification

The memory section of interest

Apply one of the model's memory sections to the subsystem

Tips

  • Can be useful for overriding the model's memory section settings for the given subsystem.

  • The possible values vary depending on what (if any) package of memory sections you have set for the model's configuration. See Configure Memory Sections in the Embedded Coder documentation.

  • If you have not configured the model with a package, Inherit from model is the only value that appears. Otherwise, the list includes Default and all memory sections the model's package contains.

Dependencies

  • This parameter requires a license for Embedded Coder software and an ERT-based system target file.

  • Setting Function packaging to Nonreusable function and selecting the Function with separate data check box enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Memory section for internal data

Indicate how the Embedded Coder software is to apply memory sections to the subsystem's data.

Settings

Default: Inherit from model

Inherit from model

Apply the root model's memory sections to the subsystem's data

Default

Not apply memory sections to the subsystem's data, overriding any model-level specification

The memory section of interest

Apply one of the model's memory sections to the subsystem

Tips

  • Can be useful for overriding the model's memory section settings for the given subsystem.

  • The possible values vary depending on what (if any) package of memory sections you have set for the model's configuration. See Configure Memory Sections in the Embedded Coder documentation.

  • If you have not configured the model with a package, Inherit from model is the only value that appears. Otherwise, the list includes Default and all memory sections the model's package contains.

Dependencies

  • This parameter requires a license for Embedded Coder software and an ERT-based system target file.

  • Setting Function packaging to Nonreusable function and selecting the Function with separate data check box enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Memory section for parameters

Indicate how the Embedded Coder software is to apply memory sections to the subsystem's data.

Settings

Default: Inherit from model

Inherit from model

Apply the root model's memory sections to the subsystem's function code

Default

Not apply memory sections to the subsystem's system code, overriding any model-level specification

The memory section of interest

Apply one of the model's memory sections to the subsystem

Tips

  • Can be useful for overriding the model's memory section settings for the given subsystem.

  • The possible values vary depending on what (if any) package of memory sections you have set for the model's configuration. See Configure Memory Sections in the Embedded Coder documentation.

  • If you have not configured the model with a package, Inherit from model is the only value that appears. Otherwise, the list includes Default and all memory sections the model's package contains.

Dependencies

  • This parameter requires a license for Embedded Coder software and an ERT-based system target file.

  • Setting Function packaging to Nonreusable function and selecting the Function with separate data check box enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Characteristics

Sample Time

Depends on the blocks in the subsystem

Dimensionalized

Depends on the blocks in the subsystem

Multidimensionalized

Depends on the blocks in the subsystem

Virtual

Yes, if the read-only property IsSubsystemVirtual is on

Zero Crossing

Yes, for enable and trigger ports if present

Was this topic helpful?