Main Content

Import AUTOSAR XML Descriptions Into Simulink

In Simulink®, you can import AUTOSAR software components, compositions, or packages of shared elements from AUTOSAR XML (ARXML) files. You use the ARXML importer, which is implemented as an arxml.importer object. For more information, see AUTOSAR ARXML Importer.

To import ARXML software description files into Simulink, first call the arxml.importer function. In the function argument, specify one or more ARXML files that describe software components, compositions, or packages of shared elements. For example:

ar = arxml.importer('ThrottlePositionControlComposition.arxml')

The function:

  • Parses the ARXML files to identify AUTOSAR software descriptions.

  • If you entered the function call without a terminating semicolon (;), lists the AUTOSAR content of the specified ARXML file or files.

  • Returns a handle to an ARXML importer object. In subsequent function calls, the object represents the parsed AUTOSAR software descriptions in the ARXML files.

For more information, see Create ARXML Importer Object.

Next, based on what you want to import, call an arxml.importer create or update function. For example:

To help support the round trip of AUTOSAR elements between an AUTOSAR authoring tool (AAT) and the Simulink model-based design environment, ARXML import preserves imported AUTOSAR XML file structure, elements, and element universal unique identifiers (UUIDs) for ARXML export. For more information, see Round-Trip Preservation of AUTOSAR XML File Structure and Element Information.

After you import an AUTOSAR software component or composition into Simulink, you can develop the behavior and configuration of the component or composition model. To refine the component configuration, see AUTOSAR Component Configuration.

To configure ARXML export options, see Configure AUTOSAR XML Options.

Create ARXML Importer Object

Before you import ARXML descriptions into Simulink, call the arxml.importer function. Specify the names of one or more ARXML files that contain descriptions of AUTOSAR software components, compositions, or shared elements. The function parses the descriptions in the specified ARXML files and creates an importer object that represents the parsed information. Subsequent calls to createComponentAsModel or other ARXML importer functions must specify the importer object.

For example, open the autosar_swc model and build it.

openExample('autosar_swc');

The below call specifies a main AUTOSAR software component file, autosar_swc_component.arxml, and related dependent files containing data type, implementation, and interface information that completes the software component description.

ar = arxml.importer({'autosar_swc_component.arxml','autosar_swc_datatype.arxml',...
                     'autosar_swc_implementation.arxml','autosar_swc_interface.arxml'})

This call specifies an ARXML file, ThrottlePositionControlComposition.arxml, which describes an AUTOSAR software composition and its aggregated AUTOSAR components.

ar = arxml.importer('ThrottlePositionControlComposition.arxml')

If you enter the arxml.importer function call without a terminating semicolon (;), the importer lists the AUTOSAR content of the specified XML file or files. The information includes paths to software components in the AUTOSAR package structure, which you use in the next step.

In this example, the path to software composition ThrottlePositionControlComposition is /Company/Components/ThrottlePositionControlComposition. The path to software component Controller is /Company/Components/Controller.

ar =
The file "path/ThrottlePositionControlComposition.arxml" contains:
  1 Composition-Software-Component-Type:
    '/Company/Components/ThrottlePositionControlComposition'
  2 Application-Software-Component-Type:
    '/Company/Components/Controller'
    '/Company/Components/ThrottlePositionMonitor'
  3 Sensor-Actuator-Software-Component-Type:
    '/Company/Components/AccelerationPedalPositionSensor'
    '/Company/Components/ThrottlePositionActuator'
    '/Company/Components/ThrottlePositionSensor'

Import Software Component and Create Model

To import a parsed atomic software component into a Simulink model, call the createComponentAsModel function. Specify the ARXML importer object and the component to create as a model. The parsed ARXML files must specify all dependencies for the component.

The following example creates a Simulink representation of an AUTOSAR atomic software component.

ar = arxml.importer('ThrottlePositionControlComposition.arxml');
names = getComponentNames(ar)
names = 5x1 cell
    {'/Company/Components/Controller'                     }
    {'/Company/Components/ThrottlePositionMonitor'        }
    {'/Company/Components/AccelerationPedalPositionSensor'}
    {'/Company/Components/ThrottlePositionActuator'       }
    {'/Company/Components/ThrottlePositionSensor'         }
createComponentAsModel(ar,'/Company/Components/Controller',...
    'ModelPeriodicRunnablesAs','AtomicSubsystem');

The 'ModelPeriodicRunnablesAs' argument controls whether the importer models AUTOSAR periodic runnables as atomic subsystems with periodic rates (the default) or function-call subsystems with periodic rates. Specify AtomicSubsystem unless your design requires use of function-call subsystems. For more information, see Import AUTOSAR Software Component with Multiple Runnables.

To import Simulink data objects for AUTOSAR data into a Simulink data dictionary, you can set the 'DataDictionary' argument on the model creation. If the specified dictionary does not already exist, the importer creates it.

To explicitly designate an AUTOSAR runnable as the initialization runnable in a component, use the 'InitializationRunnable' argument on the model creation.

For more information, see the createComponentAsModel reference page and the example Import AUTOSAR Component to Simulink.

Import Software Composition and Create Models

To import a parsed atomic software composition into a Simulink model, call the createCompositionAsModel function. Specify the ARXML importer object and the composition to create as a model. The parsed ARXML files must specify all dependencies for the composition.

The following example creates a Simulink representation of an AUTOSAR software composition.

ar = arxml.importer('ThrottlePositionControlComposition.arxml');
names = getComponentNames(ar,'Composition')
names = 1x1 cell array
    {'/Company/Components/ThrottlePositionControlComposition'}
createCompositionAsModel(ar,'/Company/Components/ThrottlePositionControlComposition');
Creating model 'ThrottlePositionSensor' for component 1 of 5:
 /Company/Components/ThrottlePositionSensor
Creating model 'ThrottlePositionMonitor' for component 2 of 5:
 /Company/Components/ThrottlePositionMonitor
Creating model 'Controller' for component 3 of 5:
 /Company/Components/Controller
Creating model 'AccelerationPedalPositionSensor' for component 4 of 5:
 /Company/Components/AccelerationPedalPositionSensor
Creating model 'ThrottlePositionActuator' for component 5 of 5:
 /Company/Components/ThrottlePositionActuator
Creating model 'ThrottlePositionControlComposition' for composition 1 of 1:
 /Company/Components/ThrottlePositionControlComposition

To include existing Simulink atomic software component models in the composition model, use the 'ComponentModels' argument on the composition model creation.

For more information, see the createCompositionAsModel reference page and the example Import AUTOSAR Composition to Simulink.

For compositions containing more than 20 software components, sharing AUTOSAR properties among components can significantly improve performance and reduce duplication for composition workflows. To configure a composition import to store AUTOSAR properties for component sharing, use the 'DataDictionary' and 'ShareAUTOSARProperties' arguments. For more information, see the createCompositionAsModel reference page and the example Import AUTOSAR Composition and Share AUTOSAR Dictionary.

Import Component or Composition External Updates Into Model

After you import a parsed atomic software component or composition into a Simulink model, the ARXML description of the component or composition might continue to evolve in a different AUTOSAR authoring environment. To update your AUTOSAR component or composition model with external changes, call the updateModel function. Specify an ARXML importer object representing the ARXML changes and the existing AUTOSAR model to update.

The following example updates an existing AUTOSAR component model named Controller with changes from the file ThrottlePositionControlComposition_updated.arxml.

% Create and open AUTOSAR controller component model
ar = arxml.importer('ThrottlePositionControlComposition.arxml');
createComponentAsModel(ar,'/Company/Components/Controller',...
  'ModelPeriodicRunnablesAs','AtomicSubsystem');

% Update AUTOSAR controller component model (model must be open)
ar2 = arxml.importer('ThrottlePositionControlComposition_updated.arxml');
updateModel(ar2,'Controller');

For more information, see the updateModel reference page, Import AUTOSAR Software Component Updates, and the update section of the example Import AUTOSAR Component to Simulink.

Import Shared Element Packages into Component Model

After you create an AUTOSAR software component model, either by starting in Simulink or importing ARXML component descriptions, you can update the AUTOSAR properties of the component model with predefined elements and properties that are shared among components. To update the component AUTOSAR properties with packages of shared element definitions, call the updateAUTOSARProperties function. Specify an ARXML importer object representing the ARXML shared element definitions and the existing AUTOSAR model to update.

The following example updates an AUTOSAR component model with element definitions from the file SwAddrMethods.arxml.

modelName = 'autosar_swc';
openExample(modelName);
ar = arxml.importer('SwAddrMethods.arxml');
updateAUTOSARProperties(ar,modelName);

For more information, see the updateAUTOSARProperties reference page, Import and Reference Shared AUTOSAR Element Definitions, and the example Import AUTOSAR Package into Component Model.

See Also

Related Examples

More About