Main Content

Configure AUTOSAR Data Types Export

The AUTOSAR standard defines an approach to AUTOSAR data types in which base data types are mapped to implementation data types and application data types. Application and implementation data types separate application-level physical attributes, such as real-world range of values, data structure, and physical semantics, from implementation-level attributes, such as stored-integer minimum and maximum and specification of a primitive-type (integer, Boolean, real, and so on). For information about modeling data types, see Model AUTOSAR Data Types.

The software supports AUTOSAR data types in Simulink® originated and round-trip workflows:

  • For AUTOSAR components originated in Simulink, the software generates AUTOSAR application, implementation, and base types to preserve the information contained within Simulink data types.

  • For round-trip workflows involving AUTOSAR components originated outside MATLAB®, the ARXML importer and exporter preserve data type information and mapping for each imported AUTOSAR data type.

For AUTOSAR data types originated in Simulink, you can control some aspects of data type export. For example, you can control when application data types are generated, specify the AUTOSAR package and short name exported for AUTOSAR data type mapping sets, or force ARXML export of internal data constraints for AUTOSAR implementation data types.

Control Application Data Type Generation

For AUTOSAR data types created in Simulink, by default, the software generates application base types only for fixed-point data types and enumerated date types with storage types. If you want to override the default behavior for generating application types, you can configure the ARXML exporter to generate an application type, along with the implementation type and base type, for each exported AUTOSAR data type. Use the XML options parameter ImplementationDataType Reference (XMLOptions property ImplementationDataTypeReference), for which you can specify the following values:

  • Allowed (default) — Allow direct reference of implementation types in the generated ARXML code. If an application data type is not strictly required to describe an AUTOSAR data type, use an implementation data type reference.

  • NotAllowed — Do not allow direct reference of implementation data types in the generated ARXML code. Generate an application data type for each AUTOSAR data type.

To set the ImplementationDataTypeReference property in the MATLAB Command Window, use an AUTOSAR property set function call similar to the following:

hModel = 'autosar_swc_expfcns';
addpath(fullfile(matlabroot,'/examples/autosarblockset/main'));
open_system(hModel);
arProps=autosar.api.getAUTOSARProperties(hModel);
set(arProps,'XmlOptions','ImplementationTypeReference','NotAllowed');
get(arProps,'XmlOptions','ImplementationTypeReference')

To set the ImplementationDataTypeReference property in the AUTOSAR Dictionary, select XML Options. Select a value for parameter ImplementationDataType Reference. Click Apply.

Configure DataTypeMappingSet Package and Name

For AUTOSAR software components created in Simulink, you can control the AUTOSAR package and short name exported for AUTOSAR data type mapping sets. To configure the data type mapping set package for export, set the XMLOptions property DataTypeMappingPackage using the AUTOSAR Dictionary or the AUTOSAR property set function.

hModel = 'autosar_swc_expfcns';
addpath(fullfile(matlabroot,'/examples/autosarblockset/main'));
open_system(hModel);
arProps=autosar.api.getAUTOSARProperties(hModel);
set(arProps,'XmlOptions','DataTypeMappingPackage','/pkg/dt/DataTypeMappings');
get(arProps,'XmlOptions','DataTypeMappingPackage')

The exported ARXML code uses the specified package. The default mapping set short-name is the component name ASWC prefixed to DataTypeMappingsSet.

<DATA-TYPE-MAPPING-REFS>
    <DATA-TYPE-MAPPING-REF DEST="DATA-TYPE-MAPPING-SET">
      /pkg/dt/DataTypeMappings/ASWCDataTypeMappingsSet</DATA-TYPE-MAPPING-REF>
</DATA-TYPE-MAPPING-REFS>
...
<AR-PACKAGE>
    <SHORT-NAME>DataTypeMappings</SHORT-NAME>
    <ELEMENTS>
        <DATA-TYPE-MAPPING-SET UUID="...">
            <SHORT-NAME>ASWCDataTypeMappingsSet</SHORT-NAME>
...
        </DATA-TYPE-MAPPING-SET>
    </ELEMENTS>
</AR-PACKAGE>

You can specify a short name for a data type mapping set using the AUTOSAR property function addPackageableElement. The following example specifies a custom data type mapping set package and name using MATLAB commands.

% Add a new data type mapping set
modelName = 'autosar_swc_expfcns';
addpath(fullfile(matlabroot,'/examples/autosarblockset/main'));
open_system(modelName);
propObj = autosar.api.getAUTOSARProperties(modelName);
newMappingSetPath = '/myPkg/mySubpkg/MyMappingSets';
newMappingSetName = 'MappingSetName';
newMappingSet = [newMappingSetPath '/' newMappingSetName];
addPackageableElement(propObj,'DataTypeMappingSet',newMappingSetPath,newMappingSetName);

% Configure the component behavior to use the new data type mapping set
swc = get(propObj,'XmlOptions','ComponentQualifiedName');
ib = get(propObj,swc,'Behavior','PathType','FullyQualified');
set(propObj,ib,'DataTypeMapping',newMappingSet);

% Force generation of application data types
set(propObj,'XmlOptions','ImplementationTypeReference','NotAllowed');

% Build
slbuild(modelName);

The exported ARXML code uses the specified package and name, as shown below.

<INTERNAL-BEHAVIORS>
    <SWC-INTERNAL-BEHAVIOR UUID="...">
        <SHORT-NAME>IB</SHORT-NAME>
        <DATA-TYPE-MAPPING-REFS>
            <DATA-TYPE-MAPPING-REF DEST="DATA-TYPE-MAPPING-SET">
              /myPkg/mySubpkg/MyMappingSets/MappingSetName</DATA-TYPE-MAPPING-REF>
        </DATA-TYPE-MAPPING-REFS>
...
    </SWC-INTERNAL-BEHAVIOR>
</INTERNAL-BEHAVIORS>

Initialize Data with ApplicationValueSpecification

To initialize AUTOSAR data objects typed by application data type, the AUTOSAR standard (R4.1 or later) requires AUTOSAR application value specifications (ApplicationValueSpecifications). Embedded Coder® provides the following support:

  • The ARXML importer uses ApplicationValueSpecifications found in imported ARXML files to initialize the corresponding data objects in the Simulink model.

  • Code generation exports ARXML code that uses ApplicationValueSpecifications to specify initial values for AUTOSAR data.

For AUTOSAR parameters typed by implementation data type, code generation exports ARXML code that uses NumericalValueSpecifications and (for enumerated types) TextValueSpecifications to specify initial values. If initial values for parameters specify multiple values, generated code uses ArrayValueSpecifications.

Configure AUTOSAR Internal Data Constraints Export

AUTOSAR applications use data constraints to implement limits on data types and provide a controlled range of possible values. Internal data constraints represent minimum and maximum values for implementation data types, reflecting the internal or machine view of the data.

By default, code generation does not export internal data constraint information for AUTOSAR implementation data types in ARXML code. If you want to force export of internal data constraints for implementation data types, select the XML option Internal DataConstraints Export.

If you select Internal DataConstraints Export, the exporter generates internal data constraints into an AUTOSAR package with a default name, DataConstrs, at a fixed location under the AUTOSAR data type package. Optionally, use the XML option Internal DataConstraints Package to specify a different AUTOSAR package name and path.

To configure export of AUTOSAR internal data constraint information in your model:

  1. Open the AUTOSAR Dictionary. On the AUTOSAR tab, select Code Interface > AUTOSAR Dictionary.

  2. Select XML Options. In the XML options view, under Additional Options, select Internal DataConstraints Export.

  3. Optionally, under Additional Packages, enter a package path for Internal DataConstraints Package.

  4. Build the model and inspect the generated code. Here is an example of an AUTOSAR internal data constraint exported to ARXML code.

    <AR-PACKAGE>
        <SHORT-NAME>IDC</SHORT-NAME>
        <ELEMENTS>
            ...
            <DATA-CONSTR UUID="...">
                <SHORT-NAME>DC_SInt8</SHORT-NAME>
                <DATA-CONSTR-RULES>
                    <DATA-CONSTR-RULE>
                        <INTERNAL-CONSTRS>
                            <LOWER-LIMIT INTERVAL-TYPE="CLOSED">-128</LOWER-LIMIT>
                            <UPPER-LIMIT INTERVAL-TYPE="CLOSED">127</UPPER-LIMIT>
                        </INTERNAL-CONSTRS>
                    </DATA-CONSTR-RULE>
                </DATA-CONSTR-RULES>
            </DATA-CONSTR>
        </ELEMENTS>
    </AR-PACKAGE>

Alternatively, you can programmatically configure the AUTOSAR XML options Internal DataConstraints Export and Internal DataConstraints Package. For example:

arProps = autosar.api.getAUTOSARProperties(hModel);
set(arProps,'XmlOptions','InternalDataConstraintExport',true);
set(arProps,'XmlOptions','InternalDataConstraintPackage','/pkg/misc/IDC');

For more information, see Configure AUTOSAR XML Options.

Related Examples

More About