Main Content

cgsl_0402: Signal interfaces for component deployment

ID: Titlecgsl_0402: Signal interfaces for component deployment
Description

At the root level of a component, signal interfaces shall be modeled by using only one type of ports:

  • Name-based ports — In Bus Element and Out Bus Element blocks

  • Index-based ports — Inport and Outport blocks

Using name-based ports:

  • Improves model clarity by reducing wiring and complexity.

  • Avoids issues caused by port reordering with index-based ports.

A

For structured signals that use In Bus Element and Out Bus Element blocks, set block parameters as follows:

  • Set Data type to Bus: <object name>.

  • Set Bus virtuality to nonvirtual.

Configure the interface for each name-based port individually.

B

For structured signals that use Inport and Outport blocks, set block parameters as follows:

  • Set Data type to Bus: <object name>.

  • Specify that the output bus is nonvirtual at the root level by selecting Outport block parameter Output as nonvirtual bus in parent model.

  • Specify that the output for a top-level Inport block used to load bus data is nonvirtual by selecting Inport block parameter Output as nonvirtual bus.

C

To select signal elements in a way that minimizes memory usage, reduce the number of data copies by passing an entire virtual or nonvirtual bus into an atomic subsystem, even when the subsystem uses only a subset of the bus. To select an element of the bus from the interface, use anIn Bus Element block.

A data copy is created when an atomic subsystem interface receives only part of a bus. For example, a data copy is created when a bus element is selected from the bus, then that bus element is passed into the subsystem.

This table describes the data copy creation when an atomic subsystem receives a bus element instead of the entire bus.

Function PackagingFunction InterfaceData Copy
Non-reusable functionvoid_voidIn the global block I/O structure that the function uses, the software creates a copy of the input bus element.
Non-reusable functionAllow arguments (Optimized)In a local variable that is passed to the function, the software creates a copy of the input bus element.
Reusable functionN/AIn a local variable that is passed to the function, the software creates a copy of the input bus element.
Notes
  • Do not use datastore memory for signal interfaces.

  • Depending on Embedded Coder® settings (for example, optimizations), predecessor blocks, signal storage classes, and actual results might differ from the tables.

  • Virtual buses do not support global data.

  • If Function packaging is set to Inline for the subsystem, data copies do not occur.

Rationale

Using In Bus Element and Out Bus Element blocks reduces wiring and the name-based approach avoids issues with port reordering.

Reduces complexity and provides model clarity.

Model Advisor CheckVerify this guideline by using Model Advisor check Check signal interfaces (Embedded Coder).
Last ChangedR2023b
Example

In this model, an In Bus Element block selects a vector from a nonvirtual bus. The selected vector enters an atomic subsystem that has function packaging set to Reusable function.

Example model showing bus elements and generated code

Only the selected vector is passed to the function because the vector is selected before the subsystem interface. The function requires a data copy of the vector independent of the nonvirtual bus.

:

Version History

expand all

Introduced in R2022b