Main Content

Configure AUTOSAR Packages

In Simulink®, you can modify the hierarchical AUTOSAR package structure, as defined by the AUTOSAR standard, that Embedded Coder® exports to AUTOSAR XML (ARXML) files.

AUTOSAR Package (AR-PACKAGE) Structure

The AUTOSAR standard defines AUTOSAR packages (AR-PACKAGEs). AR-PACKAGEs contain groups of AUTOSAR elements and reside in a hierarchical AR-PACKAGE structure. In an AUTOSAR authoring tool (AAT) or in Simulink, you can configure an AR-PACKAGE structure to:

  • Conform to an organizational or standardized AR-PACKAGE structure.

  • Establish a namespace for elements in a package.

  • Provide a basis for relative references to elements.

The ARXML importer imports AR-PACKAGEs, their elements, and their paths into Simulink. The model configuration preserves the packages for subsequent export to ARXML files. In general, the software preserves AUTOSAR packages across round-trips between an AUTOSAR authoring tool and Simulink.

If your AUTOSAR component originated in Simulink, at component creation, the AUTOSAR component builder creates an initial default AR-PACKAGE structure, containing these packages:

  • Software components

  • Data types

  • Port interfaces

  • Implementation

For example, create a Simulink model configured for an AUTOSAR platform, for a specific workflow see Create and Configure AUTOSAR Software Component. When you build the model, its initial AR-PACKAGE structure resembles the following figure.

After component creation, you can use the XML Options view in the AUTOSAR Dictionary to specify additional AR-PACKAGEs. Each AR-PACKAGE represents an AUTOSAR element category. During code generation, the ARXML exporter generates a package if any elements of its category exist in the model. For each package, you specify a path, which defines its location in the AR-PACKAGE structure.

For more information about configuring XML options, see Configure AUTOSAR XML Options or Configure AUTOSAR Adaptive XML Options.

Using XML options, you can configure AUTOSAR packages for the following categories of AUTOSAR elements:

  • Application data types

  • Software base types

  • Data type mapping sets

  • Constants and values

  • Physical data constraints (referenced by application data types or data prototypes)

  • System constants

  • Software address methods

  • Mode declaration groups

  • Computation methods

  • Units and unit groups

  • Software record layouts (for application data types of category CURVE, MAP, CUBOID, or COM_AXIS)

  • Internal data constraints (referenced by implementation data types)

Note

  • For packages that you define in XML options, the ARXML exporter generates a package only if the model contains an element of the package category. For example, the exporter generates a software address method package only if the model contains a software address method element.

  • You can specify separate packages for listed elements, like application data types. Implementation data types are aggregated in the main data types package.

The AR-PACKAGE structure changes depending on if you choose single-file or modular-file partitioning for ARXML export by using XML option Exported XML file packaging.

Configure AUTOSAR Packages and Paths

If you import an AR-PACKAGE structure into Simulink, the ARXML importer preserves package-element relationships and package paths defined in imported ARXML files. The importer also populates packaging properties in the component and XML Options views in the AUTOSAR Dictionary. If the imported ARXML descriptions do not assign AUTOSAR elements to packages based on category, the importer uses heuristics to determine an optimal category association for each package. However, only one package can be associated with a category.

Suppose that you start with a non-AUTOSAR Simulink model and configure the model for AUTOSAR code generation. For example, open the AUTOSAR Component Designer App to launch the Quick Start for configuring AUTOSAR code generation. The software creates an initial default AR-PACKAGE structure. After component creation, the component view in the AUTOSAR Dictionary displays Component XML Options, including package paths for the component, internal behavior, and implementation.

AUTOSAR Dictionary. Component mySWC is selected, exposing it's XML Options and package paths.

The XML Options view displays paths for AUTOSAR data type and interface packages, and additional packages.

AUTOSAR Dictionary. XML Options is selected and the options are displayed.

By using the Additional Packages section, you can populate path fields for additional packages or leave them empty. If you leave a package field empty, and if the model contains packageable elements of that category, the ARXML exporter uses internal rules to calculate the package path. The application of internal rules is backward-compatible with earlier releases. The following table lists the XML option packaging properties and their rule-based default package paths.

Property NamePackage Paths Based on Internal Rules
InternalBehaviorQualifiedName/Components/InternalBehaviors/modelname_IB
ImplementationQualifiedName/Components/SwcImplementations/modelname_Impl
ComponentQualifiedName/Components/modelname
(The dialog box displays the component path without the short name.)
DataTypePackage

/DataTypes
(Data type packaging is affected by the property settings for AUTOSAR Platform Types. See AUTOSAR Platform Types for more information.)

Note

The DataTypePackage path must be different from the paths of these packages:

  • ApplicationDataTypePackage

  • PlatformDataTypePackage

  • SwBaseTypePackage

InterfacePackage/Interfaces
PlatformDataTypePackage

The PlatformDataTypePackage path must be different from the DataTypePackage path. For information about specifying the PlatformDataTypePackage path, see AUTOSAR Platform Types.

ApplicationDataTypePackage

DataTypePackage/ApplDataTypes

Note

The ApplicaionDataTypePackage path must be different from the DataTypePackage path.

SwBaseTypePackage

DataTypePackage/SwBaseTypes
(Software base type packaging is affected by the property settings for AUTOSAR Platform Types. See AUTOSAR Platform Types for more information.)

Note

The SwBaseTypePackage path must be different from the DataTypePackage path.

DataTypeMappingPackageDataTypePackage/DataTypeMappings
ConstantSpecificationPackageDataTypePackage/Constants
DataConstraintPackageApplicationDataTypePackage/DataConstrs
SystemConstantPackageDataTypePackage/SystemConstants
SwAddressMethodPackageDataTypePackage/SwAddrMethods
ModeDeclarationGroupPackageDataTypePackage/ModeDeclarationGroups
CompuMethodPackageDataTypePackage/CompuMethods
UnitPackageDataTypePackage/Units
SwRecordLayoutPackageDataTypePackage/SwRecordLayouts
InternalDataConstraintPackageDataTypePackage/DataConstrs

To programmatically set a packaging property use an autosar.api.getAUTOSARProperties object like the following:

hModel = "autosar_swc_counter";
openExample(hModel);
arProps=autosar.api.getAUTOSARProperties(hModel);
set(arProps,"XmlOptions",ApplicationDataTypePackage="/Company/Powertrain/DataTypes/ADTs"));

get(arProps,"XmlOptions","ApplicationDataTypePackage")
ans =

    '/Company/Powertrain/DataTypes/ADTs'

For a sample script configuring XML Options, see Configure AUTOSAR XML Options. For an example configuring and exporting AUTOSAR packages, see Export AUTOSAR Packages.

Control AUTOSAR Elements Affected by Package Path Modifications

When you modify an AUTOSAR package path, and packageable elements of that category are affected, you can:

  • Move the elements from the existing package to the new package.

  • Set the new package path without moving the elements.

For example, if you modify the XML option ConstantSpecification Package from path value /pkg/dt/Ground to /pkg/misc/MyGround, the software opens the following dialog box.

To move AUTOSAR constant specification elements to the new package, click OK. To set the new package path without moving the elements, click Cancel.

If you programmatically modify a package path, and there are affected packageable category elements, you can use the MoveElements name-value argument to specify how the elements are handled. The MoveElements name-value argument can be set to "All" (the default), "None", or "Alert".

  • "All" — Moves all affected elements to the specified package path.

  • "None" — Changes the package path to the specified package path, but does not move any affected elements to the specified package path.

  • "Alert" — A dialog box opens with OK and Cancel buttons, where OK moves all affected elements to the specified package path, and Cancel changes the package path, but does not move the elements to the new package path.

For example, the following code sets a new constant specification package path without moving existing constant specification elements to the new package.

hModel = "autosar_swc_expfcns";
openExample(hModel);
arProps = autosar.api.getAUTOSARProperties(hModel);
set(arProps,"XmlOptions",ConstantSpecificationPackage="/pkg/misc/MyGround",...
    MoveElements="None");

Export AUTOSAR Packages

This example shows how to configure and export AUTOSAR packages for an AUTOSAR software component that originated in Simulink.

  1. Open a model of an AUTOSAR software component configured for an AUTOSAR platform. This example uses the example model autosar_swc_expfcns.

    openExample("autosar_swc_expfcns");

  2. Open the AUTOSAR Dictionary and select XML Options. Here are initial settings for some of the AUTOSAR package parameters.

    In this example, Exported XML file packaging is set to Single file, which generates a single, unified ARXML file. If you prefer multiple, modular ARXML files, change the setting to Modular.

  3. Configure packages for one or more AUTOSAR elements that your model exports to ARXML files. For each package, enter a path to define its location in the AR-PACKAGE structure. Click Apply.

    This example exports multiple AUTOSAR constant specifications. This example changes the ConstantSpecification Package parameter from /pkg/dt/Ground to /pkg/misc/MyGround.

  4. Generate code and export ARXML for the model.

  5. Open the generated file modelname.arxml. (If you set Exported XML file packaging to Modular, open the generated file modelname_datatype.arxml.)

  6. Search the XML code for the packages that you configured, for example, using the text AR-PACKAGE or an element name. For the example model, searching autosar_swc_expfcns.arxml for the text MyGround finds the constant specification package and any references to it.

    ARXML file output. MyGround is highlighted in an AR-PACKAGE structure. The package path for the CONSTANT-SPECIFICATION is /pkg/misc/.

AR-PACKAGE Location in Exported ARXML Files

Grouping AUTOSAR elements into AUTOSAR packages (AR-PACKAGEs) is logically distinct from the ARXML output file packaging that the AUTOSAR configuration parameter Exported XML file packaging controls. Whether you set Exported XML file packaging to Single file or Modular, ARXML export preserves the configured AR-PACKAGE structure.

For example, after following the steps in Export AUTOSAR Packages, configure example model autosar_swc_expfcns with the following AR-PACKAGE structure. In this configuration, the path of the constant specification package has been changed from the initial model setting, /pkg/dt/Ground, to /pkg/misc/myGround.

If you export this AR-PACKAGE structure into a single file, the exported ARXML code preserves the configured AR-PACKAGE structure. To export a single ARXML file, set XML Option Exported XML file packaging to Single file in the AUTOSAR Dictionary.

autosar_swc_expfcns.arxml:

<AR-PACKAGES>
    <AR-PACKAGE>
        <SHORT-NAME>pkg</SHORT-NAME>
        ...
                <SHORT-NAME>swc</SHORT-NAME>
                ...
                <SHORT-NAME>if</SHORT-NAME>
                ...
                <SHORT-NAME>dt</SHORT-NAME>
                ...
                        <SHORT-NAME>SwBaseTypes</SHORT-NAME>
                     ...
                <SHORT-NAME>misc</SHORT-NAME>
                ...
                        <SHORT-NAME>MyGround</SHORT-NAME>
                        ...
                <SHORT-NAME>imp</SHORT-NAME>
                ...
    </AR-PACKAGE>
</AR-PACKAGES>

If you export the same AR-PACKAGE structure into multiple files (XML Option Exported XML file packaging is set to Modular), the exported ARXML code preserves the configured AR-PACKAGE structure, distributed across multiple files.

The exporter maps packageable AUTOSAR elements to ARXML files based on element category, not package path. For example, the exporter maps the data-type-oriented ConstantSpecification package, /pkg/misc/myGround, to the data types ARXML file, autosar_swc_expfcns_datatype.arxml.

autosar_swc_expfcns_component.arxml:

<AR-PACKAGES>
    <AR-PACKAGE>
        <SHORT-NAME>pkg</SHORT-NAME>
        ...
                <SHORT-NAME>swc</SHORT-NAME>
                ...
    </AR-PACKAGE>
</AR-PACKAGES>

autosar_swc_expfcns_datatype.arxml:

<AR-PACKAGES>
    <AR-PACKAGE>
        <SHORT-NAME>pkg</SHORT-NAME>
        ...
                <SHORT-NAME>dt</SHORT-NAME>
                ...
                        <SHORT-NAME>SwBaseTypes</SHORT-NAME>
                        ...
                <SHORT-NAME>misc</SHORT-NAME>
                ...
                        <SHORT-NAME>MyGround</SHORT-NAME>
                        ...   
    </AR-PACKAGE>
</AR-PACKAGES>

autosar_swc_expfcns_implementation.arxml:

<AR-PACKAGES>
    <AR-PACKAGE>
        <SHORT-NAME>pkg</SHORT-NAME>
        ...
                <SHORT-NAME>imp</SHORT-NAME>
                ...
    </AR-PACKAGE>
</AR-PACKAGES>

autosar_swc_expfcns_interface.arxml:

<AR-PACKAGES>
    <AR-PACKAGE>
        <SHORT-NAME>pkg</SHORT-NAME>
        ...
                <SHORT-NAME>if</SHORT-NAME>
                ...
    </AR-PACKAGE>
</AR-PACKAGES>

See Also

Topics