Main Content

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 relocation and integration.

  • Optionally, for architecture models configured for the AUTOSAR Classic Platform with an 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 your XML options. XML options specified at the architecture model level are inherited during export by each component in the model.

To view XML options:

  1. Open an AUTOSAR architecture model.

    For example, to open the model autosar_tpc_composition, enter:

    openExample("autosar_tpc_composition")

  2. From the Modeling tab, select Export > Configure XML Options. The XML Options dialog box opens.

    This dialog box shows XML options for the classic architecture model. Modifications you make to these options are inherited by every component in the hierarchy.

XML options for an AUTOSAR classic architecture model

The System Package option applies only to the composition level. If you export an ECU extract for a composition in a classic architecture model, System Package specifies the system package path to generate in the composition ARXML. For more information, see Export Composition ECU Extract.

In R2023a: XML option Exported XML File Packaging is supported for exporting architecture models.

Setting the Exported XML File Packaging parameter allows you to specify the granularity of XML file packaging for AUTOSAR elements created in Simulink. Selecting Single file exports XML into a single file. Selecting Modular exports XML into multiple files, named according to the type of information contained.

For more information about each XML option, see Configure AUTOSAR XML Options for classic architecture model options and Configure AUTOSAR Adaptive XML Options for adaptive architecture options.

Export Composition XML and Component Code

To export ARXML files and generate code for an architecture model:

  1. Open an architecture model.

    For this example, open the example classic model autosar_tpc_composition, enter:

    openExample("autosar_tpc_composition")

  2. 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 to package the generated files in.

    • Optionally, specify a path to a folder to contain the exported ARXML files.

    • To export an ECU extract from a classic 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. Then, 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.

  3. Expand the ZIP file. Its content is organized in arxml and src folders.

  4. 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 and interface files aggregate elements from the entire architecture model hierarchy.

    Note

    Timing files are not generated for referenced compositions within the architecture model hierarchy.

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

When exporting an architecture model, 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 classic architecture model. ECU extracts are an important input to AUTOSAR ECU configuration. In an AUTOSAR classic 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.

% Open and export AUTOSAR architecture model, generating ECU extract
archModel = 'autosar_tpc_composition';
openExample(archModel);
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.

openExample('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.

Generate Report for AUTOSAR Software Architectures Using Simulink Report Generator

If you have System Composer™ and Simulink Report Generator™ licenses, you can generate a report for an AUTOSAR architecture model and its artifacts. For more information, see System Composer Report Generation for Software Architectures (System Composer).

See Also

| |

Related Topics