Main Content

Control AUTOSAR Variants with Predefined Value Combinations

To define the values that control variation points in an AUTOSAR software component, components use the following AUTOSAR elements:

  • SwSystemconst — Defines a system constant that serves as an input to control a variation point.

  • SwSystemconstantValueSet — Specifies a set of system constant values to apply to an AUTOSAR software component.

  • PredefinedVariant — Describes a combination of system constant values, among potentially multiple valid combinations, to apply to an AUTOSAR software component.

For example, in ARXML code, you can define SwSystemconsts for automobile features, such as Transmission, Headlight, Sunroof, and Turbocharge. Then a PredefinedVariant can map feature combinations to automobile model variants, such as Basic, Economy, Senior, Sportive, and Junior.

Suppose that you have an ARXML specification of an AUTOSAR software component. If the ARXML files also define a PredefinedVariant or SwSystemconstantValueSets for controlling variation points in the component, you can resolve the variation points at model creation time. Specify a PredefinedVariant or SwSystemconstantValueSets with which the importer can initialize SwSystemconst data.

Typical steps include:

  1. Get a list of the PredefinedVariants or SwSystemconstantValueSets defined in the ARXML file.

    >> obj = arxml.importer('mySWC.arxml');
    >> find(obj,'/','PredefinedVariant','PathType','FullyQualified');
    ans = 
       '/pkg/body/Variants/Basic'
       '/pkg/body/Variants/Economy'
       '/pkg/body/Variants/Senior'
       '/pkg/body/Variants/Sportive'
       '/pkg/body/Variants/Junior'
    >> obj = arxml.importer('mySWC.arxml');
    >> find(obj,'/','SystemConstValueSet','PathType','FullyQualified')
    ans = 
       '/pkg/body/SystemConstantValues/A'
       '/pkg/body/SystemConstantValues/B'
       '/pkg/body/SystemConstantValues/C'
       '/pkg/body/SystemConstantValues/D'
  2. Create a model from the ARXML file, and specify a PredefinedVariant or one or more SwSystemconstantValueSets.

    This example specifies PredefinedVariant Senior, which describes a combination of values for Transmission, Headlight, Sunroof, and Turbocharge.

    >> createComponentAsModel(obj,compNames{1},'ModelPeriodicRunnablesAs','AtomicSubsystem',...
       'PredefinedVariant','/pkg/body/Variants/Senior');

    This example specifies SwSystemconstantValueSets A and B, which together provide values for SwSystemconsts in the AUTOSAR software component.

    >> createComponentAsModel(obj,compNames{1},'ModelPeriodicRunnablesAs',...
           'AtomicSubsystem','SystemConstValueSets',...
           {'/pkg/body/SystemConstantValues/A','/pkg/body/SystemConstantValues/B'});
  3. During model creation, the ARXML importer creates AUTOSAR.Parameter data objects, with Storage class set to SystemConstant. The importer initializes the system constant data with values based on the specified PredefinedVariant or SwSystemconstantValueSets.

After model creation, you can run simulations and generate code based on the combination of variation point input values that you specified.

In Simulink®, you can redefine the SwSystemconst data that controls variation points without recreating the model. Call the AUTOSAR property function createSystemConstants, and specify a different imported PredefinedVariant or a different cell array of SwSystemconstantValueSets. The function creates a set of system constant data objects with the same names as the original objects. You can run simulations and generate code based on the revised combination of variation point input values.

This example creates a set of system constant data objects with names and values based on imported PredefinedVariant '/pkg/body/Variants/Economy'.

arProps = autosar.api.getAUTOSARProperties(hModel);
createSystemConstants(arProps,'/pkg/body/Variants/Economy');

Building the model exports previously imported PredefinedVariants and SwSystemconstantValueSets to ARXML code.

Related Examples

More About