AUTOSAR Code Generation for Multiple Runnable Entities

This example shows you how to configure and generate AUTOSAR-compliant code and export AUTOSAR software component description XML files for a Simulink® model with multiple runnable entities.


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

Install the AUTOSAR Standard Support PackageInstall the AUTOSAR Standard Support Package

Support Packages and Support Package InstallerSupport Packages and Support Package Installer

Overview of Multi-Runnable Support

You can use the rtwdemo_autosar_multirunnables model to see how to construct a Simulink model to designate multiple runnable entities.

  • Open the model rtwdemo_autosar_multirunnables.

% Model defines
modelName = 'rtwdemo_autosar_multirunnables';

% open the model
open_system( modelName );

Designate Multiple Runnable Entities

The model rtwdemo_autosar_multirunnables represents the atomic software component. You can see the multiple runnable entities that compose the atomic software component. Each function-call subsystem defines a runnable entity. This model contains three function-call subsystems: Runnable1, Runnable2, Runnable3. An additional runnable entity aggregating the initialization functions for each of the function-call subsystems is also created at code generation.

Define the Inter-RunnableVariables

Inter-runnable variables provide data consistency between runnable entities. You define these variables through the signals that connect the entities. Label the signals with their inter-runnable variable names. This model has four inter-runnable variables: irv1, irv2, irv3, irv4. You may route inter-runnable variables through Goto and From blocks, as well as through virtual subsystem boundaries. However, check that labels on the respective line segments are consistent.

Configure the model as AUTOSAR Component: Using the AUTOSAR Interface Dialog

Overview of the AUTOSAR Interface dialogOverview of the AUTOSAR Interface dialog

  1. Click the Code menu and select: Code Generation > Configure Model as AUTOSAR Component

  2. In the Simulink-AUTOSAR Mapping Explorer, configure the mapping of Simulink Inports, Outports, and Entry point functions.

  3. In the AUTOSAR Properties Explorer, configure the AUTOSAR Interfaces, Component, Ports, Runnables, and Events

  4. After making changes, click Validate to confirm that the changes conform to AUTOSAR identifier naming conventions.

An alternative method to change AUTOSAR configuration is to modify programmatically using methods in autosar.api package

help autosar.api.getAUTOSARProperties;
help autosar.api.getSimulinkMapping;
  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

  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
     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
  See also autosar.api.create autosar.api.getAUTOSARProperties 

Generate AUTOSAR-Compliant Code

Click the Code menu and select: C/C++ Code > Build Model

An alternative method to generate AUTOSAR-compliant code from the model is by pressing Ctrl-B, or by using the following command.

rtwbuild( modelName );
### Starting build procedure for model: rtwdemo_autosar_multirunnables
### Generating XML files description for model: rtwdemo_autosar_multirunnables
### Successful completion of code generation for model: rtwdemo_autosar_multirunnables

Further Information

AUTOSAR Target documentationAUTOSAR Target documentation

Was this topic helpful?