Main Content

Generate AUTOSAR C Code and XML Descriptions

Generate AUTOSAR-compliant C code and export AUTOSAR XML (ARXML) descriptions from AUTOSAR component model.

If you have Simulink Coder and Embedded Coder software, you can build AUTOSAR component models. Building a classic component model generates algorithmic C code and exports ARXML descriptions that comply with AUTOSAR Classic Platform specifications. Use the generated C code and ARXML descriptions for testing in Simulink or integration into an AUTOSAR run-time environment.

Prepare AUTOSAR Component Model for Code Generation

Open a component model from which you want to generate AUTOSAR C code and ARXML descriptions. This example uses AUTOSAR example modelautosar_swc.

open_system('autosar_swc');

Optionally, to refine model configuration settings for code generation, you can use the Embedded Coder Quick Start (recommended). This example uses the Embedded Coder Quick Start. From theAppstab, open the AUTOSAR Component Designer app. On the汽车tab, clickQuick Start.

Work through the quick-start procedure. In the Output window, select output optionC code compliant with AUTOSAR.

The quick-start software takes the following steps to configure an AUTOSAR software component model:

  1. Configures code generation settings for the model. If the AUTOSAR target is not selected, the software sets model configuration parameterSystem target filetoautosar.tlcandGenerate XML for schema versionto a default value.

  2. If no AUTOSAR mapping exists, the software creates a mapped AUTOSAR software component for the model.

  3. Performs a model build.

In the last window, when you click结束, your model opens in the AUTOSAR code perspective.

Inspect XML Options in AUTOSAR Dictionary

Before generating code, open the AUTOSAR Dictionary and examine the settings of AUTOSAR XML export parameters. On the汽车tab, selectCode Interface>汽车Dictionary. In the AUTOSAR Dictionary, selectXML Options.

The XML options view in the AUTOSAR Dictionary displays XML export parameters and their values. You can configure:

  • XML file packaging for AUTOSAR elements created in Simulink

  • Autosar软件包路径

  • Aspects of exported AUTOSAR XML content

This example setsExported XML file packagingtoModular, so that ARXML is exported into modular files, includingmodelname_component.arxml,modelname_datatype.arxml, andmodelname_interface.arxml.

Generate AUTOSAR C Code and XML Descriptions

生成AUTOSAR C代码和XMLsoftware descriptions that comply with Classic Platform specifications, build the model. In the model window, pressCtrl+B. The build process generates C code and ARXML descriptions to the model build folder,autosar_swc_autosar_rtw. Data types and related elements that are not used in the model are removed from the exported ARXML files. When the build completes, a code generation report opens.

Related Links