Configure AUTOSAR Packages
In Simulink®, you can modify the hierarchical AUTOSAR package structure, as defined by the AUTOSAR standard, that Embedded Coder® exports to ARXML code.
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 code. In general, the software preserves AUTOSAR packages across round-trips between an AAT and Simulink.
If your AUTOSAR component originated in Simulink, at component creation, the AUTOSAR component builder creates an initial default AR-PACKAGE structure, containing the following packages.
Software components
Data types
Port interfaces
Implementation
For example, suppose that you start with a simple Simulink model, such as CounterModel
. Rename it to
mySWC
. Configure the model for AUTOSAR code generation. (For
example, open the Embedded Coder Quick Start and select AUTOSAR code generation.) 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. (See Configure AUTOSAR XML Options or Configure AUTOSAR Adaptive XML Options.) 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.
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 the listed elements, for example, application data types. Implementation data types are aggregated in the main data types package.
The AR-PACKAGE structure is logically distinct from the single-file or modular-file partitioning that you can select for ARXML export, using the XML option Exported XML file packaging. For more information about AUTOSAR package export, see AR-PACKAGE Location in Exported ARXML Files.
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 the ARXML code. Also, the importer populates packaging properties in the component and XML Options views in the AUTOSAR Dictionary. If the ARXML code does not assign AUTOSAR elements to packages based on category, the importer uses heuristics to determine an optimal category association for a package. However, a maximum of 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 Embedded Coder Quick Start and select 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.
The XML Options view displays paths for AUTOSAR data type and interface packages, and additional packages.
Using the Additional Packages subpane, 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 with their rule-based default package paths.
Property Name | Package Paths Based on Internal Rules |
---|---|
InternalBehaviorQualifiedName | /Components/InternalBehaviors/ |
ImplementationQualifiedName | /Components/SwcImplementations/ |
ComponentQualifiedName | /Components/ (The dialog box displays the component path without the short name.) |
DataTypePackage |
Note The |
InterfacePackage | /Interfaces |
ApplicationDataTypePackage |
Note The |
SwBaseTypePackage |
(SW base type packaging is affected by the property settings for AUTOSAR Platform Types. See AUTOSAR Platform Types for more information.) |
DataTypeMappingPackage |
|
ConstantSpecificationPackage |
|
DataConstraintPackage |
|
SystemConstantPackage |
|
SwAddressMethodPackage |
|
ModeDeclarationGroupPackage |
|
CompuMethodPackage |
|
UnitPackage |
|
SwRecordLayoutPackage |
|
InternalDataConstraintPackage |
|
To set a packaging property in the MATLAB® Command Window or in a script, use an AUTOSAR property
set
function call similar to 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')
For a sample script, see Configure AUTOSAR XML Options.
For an example of configuring and exporting AUTOSAR packages, see Export AUTOSAR Packages.
Control AUTOSAR Elements Affected by Package Path Modifications
If you modify an AUTOSAR package path, and if 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.
If you modify a package path in the AUTOSAR Dictionary, and if packageable
elements of that category are affected, a dialog box opens. 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, you can use the
MoveElements
property to specify handling of affected
elements. The property can be set to All
(the default),
None
, or Alert
. If you specify
Alert
, and if packageable elements are affected, the software
opens the dialog box with OK and Cancel
buttons.
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.
Open a model that you configured for the AUTOSAR system target file and that models an AUTOSAR software component. This example uses the example model
autosar_swc_expfcns
.openExample('autosar_swc_expfcns');
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 toModular
.Configure packages for one or more AUTOSAR elements that your model exports to ARXML code. For each package, enter a path to define its location in the AR-PACKAGE structure. Click Apply.
The example model exports multiple AUTOSAR constant specifications. This example changes the ConstantSpecification Package parameter from
/pkg/dt/Ground
to/pkg/misc/MyGround
.Generate code for the model.
Open the generated file
. (If you set Exported XML file packaging tomodelname
.arxmlModular
, open the generated file
.)modelname
_datatype.arxmlSearch 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 textMyGround
finds the constant specification package and many references to it. Here is a sample code excerpt.
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.
Suppose that you configure the example model
autosar_swc_expfcns
with the following AR-PACKAGE structure.
(See the steps in Export AUTOSAR Packages). 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 (Exported XML
file packaging is set to Single file
), the
exported ARXML code preserves the configured AR-PACKAGE structure.
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
(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>
Related Examples
- Import AUTOSAR XML Descriptions Into Simulink
- Import AUTOSAR Adaptive Software Descriptions
- Configure AUTOSAR Package for Component, Interface, CompuMethod, or SwAddrMethod
- Configure AUTOSAR XML Options
- Configure AUTOSAR Adaptive XML Options
- Configure AUTOSAR XML Export
- Configure AUTOSAR Code Generation
- Configure AUTOSAR Adaptive Code Generation