Generate AUTOSAR-Compliant Code for Multiple Runnable Entities

Cnfigure 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 Package

Support Package Installation

Overview of Multiple 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 an AUTOSAR 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, and Runnable3. An additional runnable entity aggregating the initialization functions for each of the function-call subsystems is also created at code generation.

Define Inter-Runnable Variables

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, and 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 Model as AUTOSAR Component Using the Configure AUTOSAR Interface Dialog Box

Overview of the Configure AUTOSAR Interface dialog box

  1. Click the Code menu and select C/C++ Code > Configure Model as AUTOSAR Component.

  2. In the Simulink-AUTOSAR Mapping Explorer, configure the mapping of Simulink inports, outports, entry point functions, and data transfers.

  3. In the AUTOSAR Properties Explorer, configure the AUTOSAR ports, runnables, events, inter-runnable variables, interfaces, computational methods, and XML options.

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

An alternative method to change the AUTOSAR configuration is to modify programmatically using methods in the 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

    Reference page in Doc Center
       doc autosar.api.getAUTOSARProperties

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

    Reference page in Doc Center
       doc autosar.api.getSimulinkMapping

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 to press Ctrl-B, or use 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

Embedded Coder AUTOSAR documentation

Was this topic helpful?