Confidential Prerelease Documentation — Subject to Nondisclosure Agreement
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:
Create a Simulink representation of an AUTOSAR component.
Develop the component by refining the AUTOSAR configuration and creating algorithmic model content.
Generate ARXML descriptions and algorithmic C code for testing in Simulink or integration into the AUTOSAR Runtime Environment (RTE).
The Embedded Coder Support Package for AUTOSAR Standard is required for working with the model in this example.
To see the steps for generating AUTOSAR-compliant C code and exporting ARXML descriptions from an AUTOSAR model, use the example model rtwdemo_autosar_swc
.
Open the model rtwdemo_autosar_swc
.
Open the Configuration Parameters dialog box. Click the Code menu and select C/C++ Code > Code Generation Options.
Select AUTOSAR as the code generation target. In the Code Generation pane, change the System target file to autosar.tlc
.
Specify an AUTOSAR schema version to use for ARXML file export. Go to the Code Generation > AUTOSAR Code Generation Options pane, and select a value for Generate XML for schema version. This example uses the default value, 4.3
.
Configure hardware settings for software-in-the-loop (SIL) testing and use them for both model builds in this example. Go to the Code Generation > Verification pane and select Enable portable word sizes. Go to the Hardware Implementation pane and select Support long long.
Click Apply.
An alternative method to prepare the model for code generation is to execute these commands.
% Model defines modelName = 'rtwdemo_autosar_swc'; % Open the model open_system(modelName); % Programmatically set the system target file and AUTOSAR schema version set_param(modelName,'SystemTargetFile','autosar.tlc'); set_param(modelName,'AutosarSchemaVersion','4.2'); % Hardware settings for software-in-the-loop simulation set_param(modelName,'PortableWordSizes','on'); % Add long long support for production device Intel x86-64 (Windows64) set_param(modelName,'ProdLongLongMode','on');
An AUTOSAR model provides a mapped configuration of an AUTOSAR software component. An AUTOSAR component is made up of elements defined in the AUTOSAR standard, such as ports, runnable entities, and events. The mapped configuration describes the AUTOSAR component and provides a mapping between Simulink model elements and AUTOSAR component elements. For more information, see AUTOSAR Component Configuration (Embedded Coder).
To configure AUTOSAR properties, use AUTOSAR Dictionary.
Click the Code menu and select C/C++ Code > Configure AUTOSAR Dictionary.
In AUTOSAR Dictionary, you can configure AUTOSAR elements and properties from an AUTOSAR component perspective.
To map Simulink model elements to AUTOSAR component elements, use the Code Mapping Editor.
Click the Code menu and select C/C++ Code > Configure Model in Code Perspective.
In the Code Mapping Editor, you can configure the mapping of model elements to AUTOSAR component elements from a SImulink model perspective.
The Code Mapping Editor provides in-canvas access to AUTOSAR mapping information, with a help panel, Property Inspector dialog box, batch editing, element filtering, easy navigation to model elements and AUTOSAR properties, and model element traceability. To confirm that the AUTOSAR component configuration meets validation requirements, you can click a Validate (check mark) button.
An alternative method to configure AUTOSAR properties and map Simulink model elements to AUTOSAR component elements is to use AUTOSAR property and map functions. For a listing of property and map functions, execute these commands.
help autosar.api.getAUTOSARProperties;
autosar.api.getAUTOSARProperties API class. DATAOBJ = autosar.api.getAUTOSARProperties(MDLNAME) creates an object DATAOBJ that can be used to query and set the AUTOSAR Properties of Simulink model MDLNAME. getAUTOSARProperties methods: add - add a property to an AUTOSAR element addPackageableElement - add an AUTOSAR element to an AUTOSAR package delete - delete an AUTOSAR element find - find AUTOSAR elements get - get the property of an AUTOSAR element set - set the property of an AUTOSAR element deleteUnmappedComponents - delete all unmapped components See also autosar.api.create autosar.api.getSimulinkMapping Reference page in Doc Center doc autosar.api.getAUTOSARProperties
help autosar.api.getSimulinkMapping;
autosar.api.getSimulinkMapping API class. MAPPINGOBJ = autosar.api.getSimulinkMapping(MDLNAME) creates an object MAPPINGOBJ that can be used to query and set the Simulink mapping of Simulink model MDLNAME getSimulinkMapping methods: getDataTransfer - get the mapping information for a Simulink data transfer line getFunction - get the mapping information for a Simulink entry point function getInport - get the mapping information for a Simulink inport getOutport - get the mapping information for a Simulink outport getFunctionCaller - get the mapping information for a Simulink function caller block getLookupTable - get the mapping information for a Simulink lookup table getDataDefaults - get the memory type configured for Signals or Discrete States mapDataTransfer - map a Simulink data transfer line mapFunction - map a Simulink entry point function mapInport - map an inport mapOutport - map an outport mapFunctionCaller - map a function caller mapLookupTable - map a lookup table mapDataDefaults - map a memory type for Signals or Discrete States See also autosar.api.syncModel autosar.api.create autosar.api.getAUTOSARProperties Reference page in Doc Center doc autosar.api.getSimulinkMapping
Building the model generates AUTOSAR-compliant C code and exports ARXML descriptions. Click the Code menu and select C/C++ Code > Build Model.
An alternative method to generate AUTOSAR-compliant C code and export ARXML descriptions from the model is to press Ctrl+B, or execute this command.
rtwbuild(modelName);
### Starting build procedure for model: rtwdemo_autosar_swc ### Generating XML files description for model: rtwdemo_autosar_swc ### Successful completion of code generation for model: rtwdemo_autosar_swc
To see the results of the model build, examine the code generation report.
The end goal of AUTOSAR model development and code generation is to integrate the generated C code and ARXML descriptions into automotive applications in the AUTOSAR Runtime Environment (RTE). An intermediate step to RTE integration is to verify the generated C code in Simulink by using software-in-the-loop (SIL) simulation. When you configure and run a SIL simulation for an AUTOSAR model, the AUTOSAR target automatically configures the generated code to route simulation data with AUTOSAR RTE API calls.
Configure the model for SIL simulation. Click the Simulation menu and select Mode > Software-in-the-Loop (SIL).
To rebuild the model and run the SIL simulation, click the Run (right-arrow) button.
Open the Diagnostic Viewer to see log messages for the AUTOSAR model build and simulation.
An alternative method to configure and run the SIL simulation is to execute these commands.
% Configure the model for software-in-the-loop simulation set_param(modelName,'SimulationMode','Software-in-the-loop'); % Run the simulation silOut = sim(modelName,'ReturnWorkspaceOutputs','on');
### Starting build procedure for model: rtwdemo_autosar_swc ### Generating XML files description for model: rtwdemo_autosar_swc ### Successful completion of build procedure for model: rtwdemo_autosar_swc ### Preparing to start SIL simulation ... Building with 'gcc'. MEX completed successfully. ### Updating code generation report with SIL files ... ### Starting SIL simulation for component: rtwdemo_autosar_swc ### Stopping SIL simulation for component: rtwdemo_autosar_swc
Rebuilding the model for SIL simulation updates the code generation report with SIL files.
AUTOSAR Code Generation (Embedded Coder)
AUTOSAR (Embedded Coder)