Hauptinhalt

Configure AUTOSAR Data Types Export

AUTOSAR data types enable consistent and reliable data exchange between AUTOSAR software components. When you import an AUTOSAR component from ARXML files, you import AUTOSAR data types and create corresponding Simulink® data types by using arxml.importer. During code generation, Embedded Coder® exports ARXML descriptions for data types used in the component model and generates AUTOSAR data types in C code. For information about modeling data types, see Model AUTOSAR Data Types.

The software supports AUTOSAR data types in Simulink-originated (bottom-up), round-trip, and top-down workflows:

  • When you export ARXML and generate code for AUTOSAR models, the exported ARXML contains descriptions of application data types, implementation data types, and software base types that generally correspond to and preserve information contained within the Simulink data types in the model.

  • For round-trip and top-down workflows involving AUTOSAR components that originate outside Simulink, the ARXML importer and exporter preserve data type information and data type map for each imported AUTOSAR data type.

You can control some aspects of AUTOSAR data types in the exported ARXML files. Specifically you can control how application data types are exported to ARXML. You can set the AUTOSAR package path and short name for data type mapping sets. You can specify if internal data constraints are included in the implementation data type descriptions in the exported ARXML.

Control Application Data Type Generation

By default, each Simulink data type used in your model is represented by an implementation data type and a software base type in the exported ARXML. In addition to these types, you can configure the ARXML exporter to also generate an application data type for each Simulink data type that is used in the model. To control if Simulink data types have application data types included in their ARXML descriptions, set the XML options parameter ImplementationDataType Reference to one of these 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 a Simulink data type, then do not create one and use an implementation data type reference.

    Note

    This setting does not remove application data types that were generated by selecting NotAllowed on a prior model build.

  • 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.

The following Simulink data types have application data types generated when they are exported to ARXML:

  • Fixed-point data types

  • Enumerated data types with specified storage types

  • Simulink.ValueType objects

  • Simulink.Bus objects that contain an element whose data type is any of the types listed above

  • Simulink.LookupTable and Simulink.Breakpoint objects

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

AUTOSAR Dictionary. XML Options. Additional Options. ImplementationDataType Reference option list is expanded showing Allowed and NotAllowed.

For more information about setting this parameter programmatically, see AUTOSAR XML Options Settings.

Configure Data Type Mapping Set Package Path and Short Name

For AUTOSAR software components created in Simulink, you can control the AUTOSAR package path and short name that are exported for AUTOSAR data type mapping sets. To configure the data type mapping set package path, in the AUTOSAR Dictionary, select XML Options navigate to Additional Packages and enter the package path for the data type mapping package in the DataTypeMappingSet Package.

AUTOSAR Dictionary. XML Options. Additional Packages section. DatatTypeMappingSet Package field is set to /pkg/dt/DataTypeMappings.

Alternatively, set the XmlOptions property DataTypeMappingPackage programmatically by using the AUTOSAR property set function.

hModel = "autosar_swc_expfcns";
openExample(hModel);
arProps = autosar.api.getAUTOSARProperties(hModel);
set(arProps,"XmlOptions","DataTypeMappingPackage","/pkg/dt/DataTypeMappings");
get(arProps,"XmlOptions","DataTypeMappingPackage")
ans =

    '/pkg/dt/DataTypeMappings'

When you run this code and then export ARXML, the exported ARXML, uses the specified package path to store data type mapping sets. The default mapping set short name is the component name prefixed to DataTypeMappingsSet. In this case, the short name is ASWCDataTypeMappingSet.

<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>

Programmatically Set DataTypeMappingSet Package Path

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 path and name using MATLAB® commands.

If not already open, open example model autosar_swc_expfcns.

modelName = "autosar_swc_expfcns";
openExample(modelName);

Add a new data type mapping set to the model.

arProp = autosar.api.getAUTOSARProperties(modelName);
newMappingSetPath = '/myPkg/mySubpkg/MyMappingSets';
newMappingSetName = 'MappingSetName';
newMappingSet = [newMappingSetPath '/' newMappingSetName];
addPackageableElement(arProps,"DataTypeMappingSet",newMappingSetPath,newMappingSetName);

Configure the component behavior to use the new data type mapping set.

swc = get(arProps,"XmlOptions","ComponentQualifiedName");
ib = get(arProps,swc,"Behavior","PathType","FullyQualified");
set(arProps,ib,"DataTypeMapping",newMappingSet);

Force all the AUTOSAR interface elements to reference application data types and generate code.

set(arProps,"XmlOptions","ImplementationTypeReference","NotAllowed");
slbuild(modelName);

The exported ARXML files use the specified package path and short name.

<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 Application Value Specifications

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

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

  • The ARXML exporter uses application value specifications to specify initial values for AUTOSAR data in ARXML descriptions.

For AUTOSAR parameters typed by implementation data types, the code generator exports ARXML descriptions that use numerical value specifications and for enumerated types text value specifications to specify initial values. If initial values for parameters specify multiple values, the exported ARXML may use both array value specifications and record value specifications for structures.

Configure AUTOSAR Internal Data Constraints for 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. Physical data constraints are explicitly mapped to application data types, and in Simulink are specified as minimum value, maximum value, and dimensions of Simulink data type objects used in the model.

By default, the software does not export internal data constraint information for AUTOSAR implementation data types in ARXML descriptions. You can force the export of internal data constraints for implementation data types by selecting the XML option Internal DataConstraints Export in the AUTOSAR Dictionary.

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

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. Generate code and export ARXML. Inspect the exported ARXML files. For example, this is an ARXML description of an AUTOSAR internal data constraint with underlying type sint8 with upper and lower limits 127 and -128 respectively.

    <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, programmatically configure the XML options InternalDataConstraintExport and InternalDataConstraintPackage by using the AUTOSAR property set function. 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 and AUTOSAR XML Options Settings.

Configure AUTOSAR Physical Constraints and Application Data Types for Export

In models configured for the AUTOSAR Classic Platform, the software maps minimum and maximum values for Simulink data types to the corresponding physical constraint values for AUTOSAR application data types.

When you import ARXML files, the software imports physical constraint values of application data types and sets the Min and Max values of the corresponding Simulink data objects and root-level I/O signals. If the physical constraint values on an application data type match the lower and upper limits of the internal constraints for the associated implementation data type, then the software sets the Simulink Min and Max values to match the internal constraints of the implementation data type.

When you export ARXML files from a model configured for the AUTOSAR Classic Platform, the software represents the Min and Max values specified on Simulink data type objects and root-level input and output signals by exporting them as physical constraints (PhysConstr) of the corresponding application data type.

On export, if the Simulink Min and Max values for a data type are not specified, the software exports default lower and upper limit values for that type (for example, 0 and 1 for a boolean software base type) to the ARXML physical constraint description in the exported ARXML file.

For example, consider Simulink.ValueType object EngSpeed with specified minimum and maximum values and underlying data type uint32.

EngSpeed = Simulink.ValueType;
EngSpeed.Min = 0;
EngSpeed.Max = 200;
EngSpeed.DataType = "uint32";

When data type EngSpeed is used in a model configured for the AUTOSAR Classic Platform and ARXML is exported from that model these ARXML descriptions are generated in the exported ARXML files. The underlying data type uint32 is used to define the implementation data type. The application data type contains references to the data constraints of the Simulink.ValueType object, which list the minimum and maximum values as LOWER-LIMIT and UPPER-LIMIT values in the data constraint description.

...
<IMPLEMENTATION-DATA-TYPE UUID="...">
    <SHORT-NAME>uint32</SHORT-NAME>
    <CATEGORY>VALUE</CATEGORY>
    <SW-DATA-DEF-PROPS>
        ...
        <BASE-TYPE-REF DEST="SW-BASE-TYPE">/DataTypes/SwBaseTypes/uint32</BASE-TYPE-REF>
        ...
    </SW-DATA-DEF-PROPS>
</IMPLEMENTATION-DATA-TYPE>
...
</APPLICATION-PRIMITIVE-DATA-TYPE>
<APPLICATION-PRIMITIVE-DATA-TYPE UUID="...">
    <SHORT-NAME>EngSpeed</SHORT-NAME>
    <CATEGORY>VALUE</CATEGORY>
    <SW-DATA-DEF-PROPS>
        ...
        <SW-CALIBRATION-ACCESS>READ-WRITE</SW-CALIBRATION-ACCESS>
        <COMPU-METHOD-REF DEST="COMPU-METHOD">/DataTypes/CompuMethods/Identcl</COMPU-METHOD-REF>
        <DATA-CONSTR-REF DEST="DATA-CONSTR">/DataTypes/ApplDataTypes/DataConstrs/DC_EngSpeed</DATA-CONSTR-REF>
        ...
    </SW-DATA-DEF-PROPS>
</APPLICATION-PRIMITIVE-DATA-TYPE>
...
<DATA-CONSTR UUID="...">
    <SHORT-NAME>DC_EngSpeed</SHORT-NAME>
    <DATA-CONSTR-RULES>
        <DATA-CONSTR-RULE>
            <PHYS-CONSTRS>
                <LOWER-LIMIT INTERVAL-TYPE="CLOSED">0</LOWER-LIMIT>
                <UPPER-LIMIT INTERVAL-TYPE="CLOSED">200</UPPER-LIMIT>
                <UNIT-REF DEST="UNIT">/DataTypes/Units/NoUnit</UNIT-REF>
            </PHYS-CONSTRS>
        </DATA-CONSTR-RULE>
    </DATA-CONSTR-RULES>
</DATA-CONSTR>
...

See Also

Topics