Main Content

Configure Variants for AUTOSAR Runnable Implementations

To vary the implementation of an AUTOSAR runnable, AUTOSAR software components can specify variant condition logic inside a runnable. In Simulink®, to model variant condition logic inside a runnable:

  • To represent variant implementations of a subsystem or model and define variant condition logic, use a Variant Subsystem, Variant Model, Variant Assembly Subsystem block.

  • To model AUTOSAR system constants, use AUTOSAR.Parameter data objects with storage class SystemConstant. The system constants represent the condition values that determine the active subsystem or model implementation.

For example, here is an AUTOSAR component model that contains a Variant Subsystem block, which models two variant implementations of a subsystem. You can open the model by running the following code at the MATLAB® command line.

open_system("mAutosarVariantSubsystem")

The variant choices are subsystems VAR1 and VAR2. The blocks are not connected because connectivity is determined during simulation, based on the active variant.

autosar_var_subsys_contents.png

To model an AUTOSAR system constant, the model defines AUTOSAR.Parameter data object rainSensor:

rainSensor = AUTOSAR.Parameter;
rainSensor.CoderInfo.StorageClass = 'Custom';
rainSensor.CoderInfo.CustomStorageClass = 'SystemConstant';
rainSensor.DataType = 'uint8';
rainSensor.Value = 2;

The Variant Subsystem block dialog box defines the variant condition logic, which is based on the system constant value. You can specify an expression or a Simulink.Variant object containing an expression.

autosar_var_subsys_dialog.png

When you generate code for the model:

  • In the ARXML code, the variant choices appear as VARIATION-POINT-PROXY entries with short-names c0 and c1. rainSensor appears as a system constant representing the associated condition value. For example:

<VARIATION-POINT-PROXYS>
    <VARIATION-POINT-PROXY UUID="...">
        <SHORT-NAME>c0</SHORT-NAME>
        <CATEGORY>CONDITION</CATEGORY>
        <CONDITION-ACCESS BINDING-TIME="PRE-COMPILE-TIME">
          <SYSC-REF DEST="SW-SYSTEMCONST">/vss_pkg/vss_dt/SystemConstants/rainSensor</SYSC-REF>
          == 1</CONDITION-ACCESS>
    </VARIATION-POINT-PROXY>
    <VARIATION-POINT-PROXY UUID="...">
        <SHORT-NAME>c1</SHORT-NAME>
        <CATEGORY>CONDITION</CATEGORY>
        <CONDITION-ACCESS BINDING-TIME="PRE-COMPILE-TIME">
          <SYSC-REF DEST="SW-SYSTEMCONST">/vss_pkg/vss_dt/SystemConstants/rainSensor</SYSC-REF>
          == 2</CONDITION-ACCESS>
    </VARIATION-POINT-PROXY>
</VARIATION-POINT-PROXYS>
  • In the RTE compatible C code, short-names c0 and c1 are encoded in the names of preprocessor symbols used in the variant condition logic. For example:

#if Rte_SysCon_c0
...
#elif Rte_SysCon_c1
...
#endif

See Also

|

Related Examples

More About