Generate and Package AUTOSAR Composition XML Descriptions and Component Code
If you have Simulink® Coder™ and Embedded Coder® software, from an AUTOSAR architecture model, you can:
Export composition and component AUTOSAR XML (ARXML) descriptions and generate component code.
Optionally, create a ZIP file to package build artifacts from the model hierarchy, for example, for relocation and integration.
Optionally, for AUTOSAR ECU configuration, export an ECU extract that maps the software components in a composition to an AUTOSAR ECU.
You can export an entire architecture model, a nested composition, or a single component. If you initiate an export that encompasses a composition, the export includes XML descriptions of the composition, component prototypes, and composition ports and connectors.
Configure Composition XML Options
To prepare for exporting ARXML files, examine and modify XML options. XML options specified at the architecture model level are inherited during export by each component in the model.
Open an architecture model, such as example model
autosar_tpc_composition
. (To open the model in a local
working folder, use
openExample('autosar_tpc_composition')
.)
To examine XML options at the architecture model level, from the Modeling tab, select Export > Configure XML Options. The AUTOSAR Dictionary opens in the XML Options view.
Modifications you make are inherited by every component in the hierarchy. For more information, see Configure AUTOSAR XML Options.
The System Package option applies only to the composition level. If you export an ECU extract for a composition in the architecture model, System Package specifies the system package path to generate in the composition ARXML. For more information, see Export Composition ECU Extract.
Export Composition XML and Component Code
To export ARXML files and generate code for an architecture model:
Open an architecture model, such as example model
autosar_tpc_composition
. (To open the model in a local working folder, useopenExample('autosar_tpc_composition')
.)To export the architecture model, from the Modeling tab, select Export > Generate Code and ARXML. In the Export Composition dialog box:
Specify the name of the ZIP file in which to package the generated files.
Optionally, specify a path to a folder in which to place the exported ARXML files.
If you want to export an ECU extract from the composition, select Export ECU extract. For more information, see Export Composition ECU Extract.
To begin the export, click OK.
As the architecture model builds, you can view the build log in the Diagnostic Viewer. First the component models build, each as a standalone top-model build. Finally, composition ARXML is exported. When the build is complete, the current folder contains build folders for the architecture model and each component model in the hierarchy, and the specified ZIP file.
Expand the ZIP file. Its content is organized in
arxml
andsrc
folders.Examine the
arxml
folder. Each AUTOSAR component has component and implementation description files, while the architecture model has composition, datatype, interface, and timing description files. The composition file includes XML descriptions of the composition, component prototypes, and composition ports and connectors. The datatype, interface, and timing files aggregate elements from the entire architecture model hierarchy.Examine the
src
folder. Each component model has a build folder that contains artifacts from a standalone model build.
To export a nested composition or a single component in an architecture model, use composition or component block cues or right-click options. For example, right-click a component block and select Export Component. Components exported from an architecture model inherit the XML options specified at the architecture model level.
In an architecture model, for export, AUTOSAR schema versions must match between the architecture model and the component models in the hierarchy. If export flags a version difference, fix the discrepancy in the component model or in the architecture model. To view the architecture model schema version, open the Configuration Parameters dialog box. In the Modeling tab, select Model Settings. In the dialog box, navigate to the AUTOSAR code generation options pane.
To export from an architecture model hierarchy programmatically, use the
architecture function export
. For example, to generate and package ARXML files and code
for example model autosar_tpc_composition
:
% Load AUTOSAR architecture model archModel = autosar.arch.loadModel('autosar_tpc_composition'); % Export ARXML descriptions and code into ZIP file export(archModel,'PackageCodeAndARXML','myArchModel.zip');
Export Composition ECU Extract
You can export ECU extracts from compositions in an AUTOSAR architecture model. ECU extracts are an important input to AUTOSAR ECU configuration. In an AUTOSAR architecture, a top-level composition can model the software components mapped to one AUTOSAR ECU. To create a software description of the ECU-scoped system, you export an ECU extract from the composition.
In an open architecture model, you can export ARXML by using the Simulink Toolstrip, the software architecture canvas, or the export
function. For example, from the Modeling
tab, select Export > Generate Code and ARXML. In the Export Composition dialog box, select the option
Export ECU extract. To begin the export, click
OK.
To generate the ECU extract, the software automatically maps the software
components in the composition to an ECU. If the composition contains nested
compositions, the software uses a flattened version of the composition hierarchy,
containing only components. For example, these function calls export an ECU extract
for the AUTOSAR example architecture model
autosar_tpc_composition
, which contains a nested
composition.
% Load and export AUTOSAR architecture model, generating ECU extract addpath(fullfile(matlabroot,'/examples/autosarblockset/main')); archModel = autosar.arch.loadModel('autosar_tpc_composition'); open(archModel); % Open loaded model in the editor (optional) export(archModel,'ExportECUExtract',true);
The export
function call generates the ECU extract into the
file System.arxml
, which is located in the composition folder.
The ECU extract for autosar_tpc_composition
maps components from
both the top-level composition and a nested Sensors
composition
to one ECU.
<SYSTEM UUID="..."> <SHORT-NAME>EcuExtract</SHORT-NAME> <CATEGORY>ECU_EXTRACT</CATEGORY> <MAPPINGS> <SYSTEM-MAPPING UUID="..."> <SHORT-NAME>SystemMapping</SHORT-NAME> <SW-MAPPINGS> <SWC-TO-ECU-MAPPING UUID="..."> <SHORT-NAME>SwcToEcuMapping</SHORT-NAME> <COMPONENT-IREFS> <COMPONENT-IREF> <TARGET-COMPONENT-REF DEST="SW-COMPONENT-PROTOTYPE"> /Components/TPC_Composition/Ctrl </TARGET-COMPONENT-REF> </COMPONENT-IREF> ... <COMPONENT-IREF> <TARGET-COMPONENT-REF DEST="SW-COMPONENT-PROTOTYPE"> /Components/TPC_Composition/PedalSensor </TARGET-COMPONENT-REF> </COMPONENT-IREF> </COMPONENT-IREFS> <ECU-INSTANCE-REF DEST="ECU-INSTANCE"> /System/EcuInstance </ECU-INSTANCE-REF> </SWC-TO-ECU-MAPPING> </SW-MAPPINGS> </SYSTEM-MAPPING> </MAPPINGS> <ROOT-SOFTWARE-COMPOSITIONS> <ROOT-SW-COMPOSITION-PROTOTYPE UUID="..."> <SHORT-NAME>RootSwCompositionPrototype</SHORT-NAME> <SOFTWARE-COMPOSITION-TREF DEST="COMPOSITION-SW-COMPONENT-TYPE"> /Components/TPC_Composition </SOFTWARE-COMPOSITION-TREF> </ROOT-SW-COMPOSITION-PROTOTYPE> </ROOT-SOFTWARE-COMPOSITIONS> </SYSTEM> <ECU-INSTANCE UUID="..."> <SHORT-NAME>EcuInstance</SHORT-NAME> </ECU-INSTANCE>
To specify the AUTOSAR package path for the system package that contains the ECU extract, use the composition XML option System Package. To view the System Package path value, from the Modeling tab, select Export > Configure XML Options.
Alternatively, configure the AUTOSAR system package path by using the AUTOSAR
property functions get
and set
.
% Set the AUTOSAR system package path addpath(fullfile(matlabroot,'/examples/autosarblockset/main')); archModel = autosar.arch.loadModel('autosar_tpc_composition'); arProps = autosar.api.getAUTOSARProperties('autosar_tpc_composition'); set(arProps,'XmlOptions','SystemPackage','/System'); systemPackage = get(arProps,'XmlOptions','SystemPackage');
For more information about the hierarchical AUTOSAR package structure, see Configure AUTOSAR Packages.
See Also
Software Composition | Software Component | export