Main Content

Configure AUTOSAR Data for Calibration and Measurement

In Simulink®, you can import and export AUTOSAR software data definition properties and modify the properties for some forms of AUTOSAR data.

About Software Data Definition Properties (SwDataDefProps)

Embedded Coder® supports ARXML import and export of the following AUTOSAR software data definition properties (SwDataDefProps):

  • Software calibration access (SwCalibrationAccess) — Specifies calibration and measurement tool access to a data object.

  • Display format (DisplayFormat) — Specifies calibration and measurement display format for a data object.

  • Software address method (SwAddrMethod) — Specifies a method to access a data object (for example, a measurement or calibration parameter) according to a given address. Used to group data in memory for access by run-time calibration and measurement tools.

  • Software alignment (SwAlignment) — Specifies the intended alignment of a data object within a memory section.

  • Software implementation policy (SwImplPolicy) — Specifies the implementation policy for a data object, regarding consistency mechanisms of variables.

  • Software record layout (SwRecordLayout) — Specifies how to serialize data in the memory of an AUTOSAR ECU.

In the Simulink environment, you can directly modify software data definition properties for some forms of AUTOSAR data. You cannot modify the SwImplPolicy or SwRecordLayout properties, but the properties are exported in ARXML code.

For more information, see Configure SwCalibrationAccess, Configure DisplayFormat, Configure SwAddrMethod, Configure SwAlignment, Export SwImplPolicy, and Export SwRecordLayout for Lookup Table Data.

Configure SwCalibrationAccess

You can specify the SwCalibrationAccess property for measurement variables, calibration parameters, and signal and parameter data objects. The valid values are:

  • ReadOnly — Data element appears in the generated description file with read access only.

  • ReadWrite — Data element appears in the generated description file with both read and write access.

  • NotAccessible — Data element appears in the generated description file and is not accessible with calibration and measurement tools.

If you open a model with signals and parameters, you can specify the SwCalibrationAccess property in the following ways:

Specify SwCalibrationAccess for AUTOSAR Data Elements

You can use either the AUTOSAR Dictionary or MATLAB® function calls to specify the SwCalibrationAccess property for the following AUTOSAR data elements:

  • Sender-receiver interface data elements

  • Nonvolatile interface data elements

  • Client-server arguments

  • Inter-runnable variables

For example:

  1. Open a model that is configured for AUTOSAR.

  2. Open the AUTOSAR Dictionary. Navigate to one of the following views:

    • S-R or NV interface, DataElements view

    • C-S interface, Arguments view

    • Atomic component, IRV view

  3. Use the SwCalibrationAccess drop-down list to select the level of calibration and measurement tool access to allow for the data element.

Alternatively, you can use the AUTOSAR property functions to specify the SwCalibrationAccess property for AUTOSAR data elements. For example, the following code opens the autosar_swc_fcncalls example model and sets calibration and measurement access to inter-runnable variable IRV2 to ReadWrite.

hModel = 'autosar_swc_fcncalls';
openExample(hModel)
arProps = autosar.api.getAUTOSARProperties(hModel);
get(arProps,'/Company/Powertrain/Components/ASWC/ASWC_IB/IRV2','SwCalibrationAccess')

set(arProps,'/Company/Powertrain/Components/ASWC/ASWC_IB/IRV2','SwCalibrationAccess','ReadWrite');
get(arProps,'/Company/Powertrain/Components/ASWC/ASWC_IB/IRV2','SwCalibrationAccess')
ans =
    'ReadOnly'

ans =
    'ReadWrite'

Here is a sample call to the AUTOSAR properties set function to set SwCalibrationAccess for an S-R interface data element in the same model.

set(arProps,'/Company/Powertrain/Interfaces/InIf/In1','SwCalibrationAccess','ReadWrite');
get(arProps,'/Company/Powertrain/Interfaces/InIf/In1','SwCalibrationAccess')
ans =
    'ReadWrite'

Specify Default SwCalibrationAccess for Application Data Types

The AUTOSAR XML options include SwCalibrationAccess DefaultValue (property SwCalibrationAccessDefault), which defines the default SwCalibrationAccess value for AUTOSAR application data types in your model. You can use the AUTOSAR property functions to modify the default. For example, the following code opens the autosar_swc_fcncalls example model and changes the default calibration and measurement access for AUTOSAR application data types from ReadOnly to ReadWrite.

hModel = 'autosar_swc_fcncalls';
openExample(hModel)
arProps = autosar.api.getAUTOSARProperties(hModel);
get(arProps,'XmlOptions','SwCalibrationAccessDefault')

set(arProps,'XmlOptions','SwCalibrationAccessDefault','ReadWrite');
get(arProps,'XmlOptions','SwCalibrationAccessDefault')
ans =
    'ReadOnly'

ans =
    'ReadWrite'

Configure DisplayFormat

AUTOSAR display format specifications control the width and precision display for calibration and measurement data. You can import and export AUTOSAR display format specifications, and edit the specifications in Simulink. You can specify display format for the following AUTOSAR elements:

  • Inter-runnable variables

  • Sender-receiver interface data elements

  • Client-server interface operation arguments

  • CompuMethods

The display format specification is a subset of ANSI® C printf specifiers, with the following form:

%[flags][width][.precision]type
FieldDescription
flags
(optional)

Characters specifying flags supported by AUTOSAR schemas:

  • (''): Insert a space before the value.

  • -: Left-justify.

  • +: Display plus or minus sign, even for positive numbers.

  • #:

    • For types o, x, and X, display 0, 0x, or 0X prefix.

    • For types e, E, and f, display decimal point even if the precision is 0.

    • For types g and G, do not remove trailing zeros or decimal point.

width
(optional)

Positive integer specifying the minimum number of characters to display.

precision
(optional)

Positive integer specifying the precision to display:

  • For integer type values (d, i, o, u, x, and X), specifies the minimum number of digits.

  • For types e, E, and f, specifies the number of digits to the right of the decimal point.

  • For types g and G, specifies the number of significant digits.

type

Characters specifying a numeric conversion type supported by AUTOSAR schemas:

  • d: Signed decimal integer.

  • i: Signed decimal integer.

  • o: Unsigned octal integer.

  • u: Unsigned decimal integer.

  • x: Unsigned hexadecimal integer, using characters "abcdef".

  • X: Unsigned hexadecimal integer, using characters "ABCDEF”.

  • e: Signed floating-point value in exponential notation. The value has the form [-]d.dddd e [sign]ddd.

    • d is a single decimal digit.

    • dddd is one or more decimal digits.

    • ddd is exactly three decimal digits.

    • sign is + or -.

  • E: Identical to the e format except that E, rather than e, introduces the exponent.

  • f: Signed floating-point value in fixed-point notation. The value has the form [-]dddd.dddd.

    • dddd is one or more decimal digits.

    • The number of digits before the decimal point depends on the magnitude of the number.

    • The number of digits after the decimal point depends on the requested precision.

  • g: Signed value printed in f or e format, whichever is more compact for the given value and precision. Trailing zeros are truncated, and the decimal point appears only if one or more digits follow it.

  • G:  Identical to the g format, except that E, rather than e, introduces the exponent (where required).

For example, the format specifier %2.1d specifies width 2, precision 1, and type signed decimal, producing a displayed value such as 12.2.

The DisplayFormat attribute appears in dialog boxes for AUTOSAR elements to which it applies. You can specify display format in a dialog box or with an element API that can modify attributes.

hModel = 'autosar_swc_counter';
openExample(hModel);
slMap = autosar.api.getSimulinkMapping(hModel);
mapParameter(slMap,'INC','ConstantMemory','DisplayFormat','%2.6f')

If you specify a display format, exporting ARXML code generates a corresponding DISPLAY-FORMAT specification.

<PARAMETER-DATA-PROTOTYPE UUID="...">
    <SHORT-NAME>INC</SHORT-NAME>
    <CATEGORY>VALUE</CATEGORY>
    <SW-DATA-DEF-PROPS>
        <SW-DATA-DEF-PROPS-VARIANTS>
            <SW-DATA-DEF-PROPS-CONDITIONAL>
                <SW-CALIBRATION-ACCESS>READ-WRITE</SW-CALIBRATION-ACCESS>
                <DISPLAY-FORMAT>%2.6f</DISPLAY-FORMAT>
                <SW-IMPL-POLICY>STANDARD</SW-IMPL-POLICY>
            </SW-DATA-DEF-PROPS-CONDITIONAL>
        </SW-DATA-DEF-PROPS-VARIANTS>
    </SW-DATA-DEF-PROPS>
    ...
</PARAMETER-DATA-PROTOTYPE>

Configure SwAddrMethod

AUTOSAR software components use software address methods (SwAddrMethods) to group data and functions into memory sections for access by run-time calibration and measurement tools. For a Simulink model mapped to an AUTOSAR software component, you can associate SwAddrMethods with these elements:

  • Model parameter or lookup table mapped to:

    • AUTOSAR constant memory

    • AUTOSAR internal calibration parameter

    • AUTOSAR port parameter

  • Signal, state, or data store mapped to:

    • AUTOSAR static memory

    • AUTOSAR per-instance memory

  • Model entry-point function mapped to AUTOSAR runnable

  • Internal data inside a model entry-point function

To create and use SwAddrMethods in an AUTOSAR model:

  1. Import SwAddrMethods from ARXML files or create SwAddrMethods in Simulink.

    • To import SwAddrMethods from ARXML files, use an arxml.importer function – createComponentAsModel or createCompositionAsModel for a new model, or updateModel or updateAUTOSARProperties for an existing model.

    • To create SwAddrMethods in an existing model, open the AUTOSAR Dictionary, SwAddrMethods view, and click the Add button . Alternatively, use equivalent AUTOSAR property functions. For more information, see Create SwAddrMethods in Simulink.

  2. Associate SwAddrMethods with model data and functions. Open the Code Mappings editor and select the Parameters, Data Stores, Signals/States, or Functions tab. Select an element within that tab. To set the SwAddrMethod attribute, click the Icon to configure additional code mappings properties icon. Alternatively, use the equivalent AUTOSAR map function. For more information, see Associate SwAddrMethod with Model Data or Function.

  3. Generate code for your AUTOSAR model. (This example uses a signal mapped to AUTOSAR static memory in the model autosar_swc_counter.) In the generated files:

    • Exported ARXML files contain SwAddrMethod descriptions and references.

      <VARIABLE-DATA-PROTOTYPE UUID="...">
          <SHORT-NAME>SM_equal_to_count</SHORT-NAME>
          <CATEGORY>VALUE</CATEGORY>
          <SW-DATA-DEF-PROPS>
              <SW-DATA-DEF-PROPS-VARIANTS>
                  <SW-DATA-DEF-PROPS-CONDITIONAL>
                      <SW-ADDR-METHOD-REF DEST="SW-ADDR-METHOD">
                      /Company/Powertrain/DataTypes/SwAddrMethods/VAR
                      </SW-ADDR-METHOD-REF>
                      <SW-CALIBRATION-ACCESS>READ-ONLY</SW-CALIBRATION-ACCESS>
                      <SW-IMPL-POLICY>STANDARD</SW-IMPL-POLICY>
                  </SW-DATA-DEF-PROPS-CONDITIONAL>
              </SW-DATA-DEF-PROPS-VARIANTS>
          </SW-DATA-DEF-PROPS>
          <TYPE-TREF DEST="IMPLEMENTATION-DATA-TYPE">
          /Company/Powertrain/DataTypes/Boolean_volatile_my_qualifier</TYPE-TREF>
      </VARIABLE-DATA-PROTOTYPE>
    • AUTOSAR-compliant C code contains comments and #define and #include statements that provide a wrapper around data or function definitions belonging to each SwAddrMethod memory section.

      /* Static Memory for Internal Data */
      
      /* SwAddrMethod VAR for Internal Data */
      #define autosar_swc_counter_START_SEC_VAR
      #include "autosar_swc_counter_MemMap.h"
      
      volatile my_qualifier boolean SM_equal_to_count;
      
      #define autosar_swc_conter_STOP_SEC_VAR
      #include "autosar_swc_counter_MemMap.h"

Create SwAddrMethods in Simulink

To create SwAddrMethods in an existing model, open the AUTOSAR Dictionary, SwAddrMethods view, and click the Add button .

Alternatively, use equivalent AUTOSAR property functions. This code adds SwAddrMethods myCODE and myVAR to an AUTOSAR component model.

hModel = 'autosar_swc_counter';
openExample(hModel)
arProps = autosar.api.getAUTOSARProperties(hModel);
addPackageableElement(arProps,'SwAddrMethod',...
    '/Company/Powertrain/DataTypes/SwAddrMethods','myCODE',...
    'SectionType','Code')
swAddrPaths = find(arProps,[],'SwAddrMethod','PathType','FullyQualified',...
    'SectionType','Code')
addPackageableElement(arProps,'SwAddrMethod',...
    '/Company/Powertrain/DataTypes/SwAddrMethods','myVAR',...
    'SectionType','Var')
swAddrPaths = find(arProps,[],'SwAddrMethod','PathType','FullyQualified',...
    'SectionType','Var')
swAddrPaths =
    {'/Company/Powertrain/DataTypes/SwAddrMethods/CODE'}
    {'/Company/Powertrain/DataTypes/SwAddrMethods/myCODE'}

swAddrPaths =
    {'/Company/Powertrain/DataTypes/SwAddrMethods/VAR'}
    {'/Company/Powertrain/DataTypes/SwAddrMethods/myVAR'}

Associate SwAddrMethod with Model Data or Function

To associate SwAddrMethods with model data and functions, open the Code Mappings editor and select the Parameters, Data Stores, Signals/States, or Functions tab. Select an element within that tab. To set the SwAddrMethod attribute, click the Icon to configure additional code mappings properties icon. In this example, SwAddrMethod VAR is selected for signal equal_to_count, which is mapped to AUTOSAR static memory.

Alternatively, use the equivalent AUTOSAR map function. For more information, see the reference page for mapFunction, mapParameter, mapSignal, mapState, or mapDataStore.

Configure SwAlignment

The SwAlignment property describes the intended alignment of AUTOSAR data within a memory section. SwAlignment defines a quantity of bits. Valid values include 8, 12, 32, UNKNOWN (deprecated), UNSPECIFIED, and BOOLEAN. For numeric data, typical SwAlignment values are 8, 16, and 32.

If you do not define the SwAlignment property, the swBaseType size and the memoryAllocationKeywordPolicy of the referenced SwAlignment determine the alignment.

You can use the AUTOSAR property function set to set SwAlignment for S-R interface data elements and inter-runnable variables. For example:

interfacePath = '/A/B/C/Interfaces/If1/';
dataElementName = 'El1';
swAlignmentValue = '32';
set(dataObj,[interfacePath dataElementName],'SwAlignment',swAlignmentValue);

To support the round-trip workflow, the ARXML importer imports and preserves the SwAlignment property for the following AUTOSAR data:

  • Per-instance memory

  • Software component parameters

  • Parameter interface data elements

  • Client-server interface operation arguments

  • Static and constant memory

Export SwImplPolicy

The SwImplPolicy property specifies the implementation policy for a data element, regarding consistency mechanisms of variables. You cannot modify the SwImplPolicy property, but the property is set to standard or queued for AUTOSAR data in exported ARXML code. The value is set to:

  • standard for

    • Per-instance memory

    • Inter-runnable variables

    • Software component parameters

    • Parameter interface data elements

    • Client-server interface operation arguments

    • Static and constant memory

  • standard or queued for

    Sender-receiver interface data elements

Export SwRecordLayout for Lookup Table Data

AUTOSAR software components use software record layouts (SwRecordLayouts) to specify how to serialize data in the memory of an AUTOSAR ECU. The ARXML importer imports and preserves the SwRecordLayout property for AUTOSAR data.

You can import SwRecordLayouts from ARXML files in either of two ways:

  • If you create your AUTOSAR model from ARXML files using importer function createComponentAsModel, include an ARXML file that contains SwRecordLayout definitions in the import. The imported SwRecordLayouts are preserved and later exported in ARXML code.

  • If you create your AUTOSAR model in Simulink, you can import shared definitions of SwRecordLayouts from ARXML files. Use importer function updateAUTOSARProperties. For example:

    importerObj = arxml.importer(arxmlFileName);
    updateAUTOSARProperties(importerObj,modelName);

    When you generate model code, the exported ARXML code contains references to the imported read-only SwRecordLayout elements, but not their definitions.

    For more information, see Import and Reference Shared AUTOSAR Element Definitions.

Related Examples

More About