Getting Started with AUTOSAR Code Generation

Generate AUTOSAR-compliant C code and export AUTOSAR XML (arxml) descriptions from a Simulink® model.

Embedded Coder® software supports AUTomotive Open System ARchitecture (AUTOSAR), an open and standardized automotive software architecture. Automobile manufacturers, suppliers, and tool developers jointly develop AUTOSAR components. To develop AUTOSAR components in Simulink, follow this general workflow:

  1. Create a Simulink representation of an AUTOSAR component.

  2. Develop the component by refining the AUTOSAR configuration and creating algorithmic model content.

  3. Generate arxml descriptions and algorithmic C code for testing in Simulink or integration into the AUTOSAR Runtime Environment (RTE).

Prerequisites

The Embedded Coder Support Package for AUTOSAR Standard is required for working with the model in this example.

Prepare Model for AUTOSAR Code Generation

To see the steps for generating AUTOSAR-compliant C code and exporting arxml descriptions from an AUTOSAR model, open a model and prepare the model for AUTOSAR code generation.

Open a model from which you want to generate AUTOSAR code and descriptions. The model can be unconfigured or only partially configured for code generation. This example uses demo model rtwdemo_autosar_swc.

To prepare the model for AUTOSAR code generation, use Embedded Coder Quick Start. In the model window, click Code > C/C++ Code > Embedded Coder Quick Start.

Work through the quick-start procedure. In the Output window, select output option C 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 already selected, the software sets model configuration parameter System target file to autosar.tlc and Generate XML for schema version to a default schema value.

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

  3. Performs a model build.

In the last window, when you click Finish, your model opens in the AUTOSAR code perspective. AUTOSAR code perspective displays a help panel, a Property Inspector panel, and directly below the model, the Code Mapping Editor.

Develop Simulink Representation of AUTOSAR Software Component

After you create an AUTOSAR software component model in Simulink, use the Code Mapping Editor and AUTOSAR Dictionary to further develop the AUTOSAR component. For more information, see AUTOSAR Component Configuration (Embedded Coder).

In a tabbed table format, the Code Mapping Editor displays Simulink model elements, such as inports, outports, entry-point functions, and data transfers. Use the editor to map Simulink model elements to AUTOSAR component elements from a Simulink model perspective. AUTOSAR component elements are defined in the AUTOSAR standard, and include ports, runnable entities, and inter-runnable variables (IRVs).

In the AUTOSAR code perspective view of your model, select the Inports tab of the Code Mapping Editor, and select a model inport. The attributes of the selected inport appear in the Property Inspector panel. This example selects Simulink inport In1_1s, which is mapped to AUTOSAR port ReceivePort and data element In1 with data access mode ImplicitReceive. In each Code Mapping Editor tab, you can select model elements and modify their AUTOSAR mapping and attributes. Your modifications are reflected in the generated arxml descriptions and C code.

If you are using demo model rtwdemo_autosar_swc with this example, modify the communication attributes for the mapped Simulink inport In1_1s. In the Property Inspector, change the AliveTimeout attribute from 60 to 30, change HandleNeverReceived from false to true, and change InitValue from 0 to 1.

To configure the AUTOSAR properties of the mapped AUTOSAR software component, open AUTOSAR Dictionary. In Code Mapping Editor, click the AUTOSAR Dictionary button, which is the leftmost button. AUTOSAR Dictionary opens in the AUTOSAR view that corresponds to the Simulink element that you last selected and mapped in Code Mapping Editor. If you selected and mapped a Simulink inport, the dictionary opens in ReceiverPorts view and displays the AUTOSAR port to which you mapped the inport.

In a tree format, AUTOSAR Dictionary displays the mapped AUTOSAR component and its elements, communication interfaces, computation methods, software address methods, and XML options. Use the dictionary to configure AUTOSAR elements and properties from an AUTOSAR component perspective.

In the ReceiverPorts view, select the AUTOSAR receiver port to which the Simulink inport was mapped in the Code Mapping Editor. If an AUTOSAR element has additional undisplayed attributes, selecting the element displays them. In each AUTOSAR element view, you can add or rename AUTOSAR elements and modify their displayed properties. Your modifications are reflected in the generated arxml descriptions and C code.

If you are using demo model rtwdemo_autosar_swc with this example, rename the AUTOSAR receiver port from ReceivePort to RequirePort. To initiate the edit, click in the Name value field.

Generate C Code and ARXML Descriptions

Building the AUTOSAR model generates AUTOSAR-compliant C code and exports arxml descriptions. In the model window, press Ctrl+B, or click the Code menu and select C/C++ Code > Build Model.

When the build completes, a code generation report opens. Examine the report. Verify that your Code Mapping Editor and AUTOSAR Dictionary changes are reflected in the C code and arxml descriptions. For example, use the Find field to search for the name of the AUTOSAR receiver port that you modified and renamed.

The generated C code encodes the AUTOSAR receiver port name in AUTOSAR Runtime Environment (RTE) API read calls.

The generated arxml description of the AUTOSAR receiver port uses the modified port name and the modified values for port communication attributes AliveTimeout, HandleNeverReceived, and InitValue.

Related Links

Was this topic helpful?