Main Content

Variant Component

Conditional variations of AUTOSAR architecture models

Since R2025a

  • Variant Component block

Libraries:
AUTOSAR Blockset

Description

Use the Variant Component block to manage variations within an AUTOSAR architecture model.

Add variant choices to a Variant Component block by right-clicking the Variant Component block and selecting Add Variant Choice.

To control the active variant choice right-click the Variant Component block and select Variant > Label Mode Active Choice.

For AUTOSAR architecture models the active variant choice is treated as a top-level component or composition block. Upon generating code and exporting ARXML only the variant choices active at the time of export and code generation have descriptions.

Examples

expand all

This example shows how to use Variant Components in AUTOSAR architectures programmatically.

Create an AUTOSAR architecture model.

archModel = autosar.arch.createModel("AUTOSARArch");

Add a variant subsystem to the architecture and specify two choices: a composition, and a component.

component = addComponent(archModel,"ComponentChoice", ...
    VariantName="MyVariantSubsystem");
composition = addComposition(archModel,"CompositionChoice", ...
    VariantName="MyVariantSubsystem");

Link the CompositionChoice block to the autosar_tpc_composition model. Link the ComponentChoice block to the autosar_swc model.

linkToModel(composition,"autosar_tpc_composition");
linkToModel(component,"autosar_swc_variant");
linkDictionary(archModel,"tpc_interfaces.sldd");

Select the active choice by right clicking the variant subsystem and from the right-click context menu select Variant > Label Mode Active Choice > CompositionChoice (CompositionChoice).

variant_choice_select.png

Add input and output ports to the MyVariantSubsystem block to match that of the variant choices, ComponentChoice and CompositionChoice.

variant_subsystem_with_ports.png

By using the Interface Editor assign interfaces in the attached data dictionary to the relevant top level ports.

Port

Interface

APP_HwIO

APP_HwIO

TPS1_HwIO

TPS_HwIO

TPS2_HwIO

TPS_HwIO

ThrCmd_HwIO

ThrCmd_HwIO

Export ARXML for the AUTOSAR architecture. On the architecture modeling toolstrip click Share and then Generate Code and ARXML.

The generated code and ARXML files contain only the descriptions of the active variant choice, ComponentChoice, and not the inactive choice CompositionChoice.

Ports

Input

expand all

The inputs of the Variant Component block must match the inputs of the variant choices the block contains.

Output

expand all

The outputs of the Variant Component block must match the outputs of the variant choices the block contains.

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced in R2025a