主要内容

Programmatically Manage AUTOSAR Architectural Data

R2026b

This example shows how to programmatically manage shared data types, interfaces, constants, software address methods, and AUTOSAR C code generation properties by using the Architectural Data section of a Simulink® data dictionary.

In Simulink, you manage data intended for use in AUTOSAR Classic software components and compositions by using the Architectural Data section of a Simulink data dictionary. Data dictionaries provides a central location for authoring and managing shared interface and data type definitions.The Architectural Data section can have an AUTOSAR Classic Platform mapping where you can configure AUTOSAR C code generation specific properties necessary for code generation and ARXML export.

You programmatically author and manage architectural data used by software components and compositions configured for the AUTOSAR Classic Platform by using this basic workflow:

  1. Create or open a data dictionary.

  2. Design interfaces, data types, and constants with the Simulink.dictionary.ArchitecturalData programmatic interface.

  3. Add an AUTOSAR Classic Platform mapping to the dictionary and configure platform-specific properties.

  4. Link data dictionary to software components, compositions, and software architectures configured for the AUTOSAR Classic Platform.

  5. Define port interface by assigning interfaces stored in the linked data dictionary to ports in an AUTOSAR Classic software architecture (requires System Composer ™).

  6. Generate code and export ARXML directly from a data dictionary that is not linked to a Simulink model or software architecture.

Create Data Dictionary

To open an existing data dictionary, use the Simulink.dictionary.archdata.open function. To create a new data dictionary, use the Simulink.dictionary.archdata.create function. Both functions return an Simulink.dictionary.ArchitecturalData object that you use to programmatically author and manage architectural data.

Open a data dictionary for a vehicle speed monitoring system configured for the AUTOSAR Classic Platform.

dictName = "SpeedMonitorData.sldd";
archData = Simulink.dictionary.archdata.create(dictName);

Create and Configure Data Types and Constants

With the data dictionary open, use the programmatic interfaces of the Simulink.dictionary.ArchitecturalData object to create, configure, and manage the shared elements that your AUTOSAR components and compositions consume. Authoring these elements in the Architectural Data section of the data dictionary allows multiple components to share the same type and interface definitions from a central location.

You can add alias types, enumeration data types, numeric data types, value data types, struct data types, and constants to the Architectural Data section of a data dictionary. You can create alias types that are based on built-in types, fixed-point specifications, or other alias types to form a type derivation chain. Add an alias type Speed_T based on built-in type single, then change the base type to a fixed-point data type. Then create a nested alias type Acceleration_T by setting the base type as alias type speedType.

speedType = addAliasType(archData,"Speed_T",BaseType="single");
set(speedType,BaseType="fixdt(1,32,16)");
accelType = addAliasType(archData,"Acceleration_T",BaseType=speedType);

Create enumeration data types, and then create an alias type based on that enumeration data type.

gearStateEnum = addEnumType(archData,"GearState");
set(gearStateEnum,Description="Transmission gear state for AUTOSAR Classic ECU");
set(gearStateEnum,StorageType="int16");
gearPositionType = addAliasType(archData,"GearPosition_T",BaseType=gearStateEnum);

Add numeric data types by using the addNumericType function to add numeric types to the data dictionary.

tempType = addNumericType(archData,"Temperature_T");
set(tempType,DataTypeMode="Single");

Add value data types by using the addValueType function to add value types that define the data type and dimensions of interface elements.

wheelSpeedsVT = addValueType(archData,"WheelSpeeds_VT");
set(wheelSpeedsVT,DataType="int32");
set(wheelSpeedsVT,Dimensions="[2 2]");
set(wheelSpeedsVT,Description="Wheel speed readings (FL, FR, RL, RR) in km/h");

Add structure data types by using the addStructType function, and add structure elements associated with that created type.

sensorDataStruct = addStructType(archData,"SensorData_ST");
rawSpeedElm = addElement(sensorDataStruct,"RawSpeed");
filteredSpeedElm = addElement(sensorDataStruct,"FilteredSpeed");
tempReadingElm = addElement(sensorDataStruct,"TemperatureReading");

Configure structure elements by using the set function and programmatically setting dimensions and Type.

set(rawSpeedElm,Type="single");
set(rawSpeedElm,Dimensions="3");
set(filteredSpeedElm,Type=wheelSpeedsVT);
set(tempReadingElm,Type="ValueType: WheelSpeeds_VT");

Define constant values with Simulink.dictionary.archdata.Constant objects. Use the addConstant function to add constants to a data dictionary programmatically. Constants defined in the Architectural Data section are shared across all components linked to the dictionary.

maxSpeedConst = addConstant(archData,"MAX_SPEED_KPH",Value=250);

Create and Configure Interfaces

You can create and configure interfaces in the Architectural Data section. In AUTOSAR workflows, these interfaces are used to define ports in software component and and software architecture models. You use Simulink.dictionary.archdata.DataInterface objects to configure sender-receiver communication, and Simulink.dictionary.archdata.ServiceInterface objects to configure client-server communication. For more information about communication workflows for the AUTOSAR see these topics:

Use the functions of the Simulink.dictionary.archdata.DataInterface object to add model sender-receiver interfaces and their elements in Simulink. You can configure AUTOSAR properties such as InterfaceKind and communication properties when you add an AUTOSAR Classic Platform mapping to the Architectural Data section of a data dictionary that is not configured for use in data dictionary hierarchies. For more information about AUTOSAR Classic Platform mappings and data dictionary hierarchies, see Choose When to Use AUTOSAR Mapped Dictionary Hierarchies.

Add these interfaces and elements by using the addDataInterface and addElement functions.

speedDataNV = addDataInterface(archData,"SpeedDataNV");
currentSpeedElm = addElement(speedDataNV,"CurrentSpeed");
set(currentSpeedElm,Type=wheelSpeedsVT);
speedThresholdElm = addElement(speedDataNV,"SpeedThreshold");
set(speedThresholdElm,Dimensions="10");
speedDataSR = addDataInterface(archData,"SpeedDataSR");

Use the the addServiceInterface function to add interfaces for modeling client-server communication. A Simulink.dictionary.archdata.ServiceInterface object contains function elements and function arguments that define the operations and operation arguments a server provides to its clients.

speedService = addServiceInterface(archData,"SpeedService");
set(speedService,Description="Speed monitoring service interface");

Add function elements to the interface by using the addElement function. Each function element represents a function prototype with input and output arguments.

getSpeedFunc = addElement(speedService,"GetCurrentSpeed");
set(getSpeedFunc,FunctionPrototype="speed = GetCurrentSpeed(sensorId)");

For one-way client-server communication where no response from the server is needed, set the ServerResponseNotRequired property to true on the function element. If you set the ServerResponseNotRequired property to true then the function prototype cannot include output arguments.

notifyFunc = addElement(speedService,"NotifySpeedExceeded");
set(notifyFunc,FunctionPrototype="NotifySpeedExceeded(threshold)");
set(notifyFunc,ServerResponseNotRequired=true);

Create and Configure Data Dictionary AUTOSAR Classic Platform Mapping

Add an AUTOSAR Classic Platform mapping to the data dictionary using the addPlatformMapping function. The platform mapping enables you to configure and customize data with platform-specific properties such as interface kind and calibration properties of data elements. This property information is not used by Simulink, but is necessary for AUTOSAR code generation and ARXML export.

platformMapping = addPlatformMapping(archData,"AUTOSARClassic",EnableDictionaryHierarchy=false);

To use the data dictionary in a reference hierarchy with other AUTOSAR Classic platform-mapped dictionaries, set EnableDictionaryHierarchy to true. For more information, see Choose When to Use AUTOSAR Mapped Dictionary Hierarchies.

Configure platform-specific properties of interfaces and elements by using setPlatformProperty. Set the AUTOSAR package path and interface kind for ARXML export.

setPlatformProperty(platformMapping,speedDataNV,...
    "Package","/SpeedMonitor/Interfaces","InterfaceKind","NvDataInterface");
[pNames,pValues] = getPlatformProperties(platformMapping,speedDataNV);

When you have an AUTOSAR Classic Platform mapping you can use it to create and configure software address methods. To add a software address method to the AUTOSAR Classic Platform mapping in the data dictionary, use the autosar.api.getAUTOSARProperties object.

arProps = autosar.api.getAUTOSARProperties(dictName);
arProps.addPackageableElement("SwAddrMethod","/SpeedMonitor/SwAddrMethods","MeasuredData","SectionType","Var");

Apply the software address method to an interface element and configure its calibration access and display format for AUTOSAR measurement and calibration tools.

setPlatformProperty(platformMapping,currentSpeedElm,...
    "SwAddrMethod","MeasuredData","SwCalibrationAccess","ReadWrite","DisplayFormat","%.3f");

Apply ASIL Profiles and Stereotypes to Architectural Data in Data Dictionary

You can capture non-functional properties on architectural data elements by applying profiles and stereotypes directly to the Architectural Data section of a data dictionary. Profiles contain stereotype definitions that you apply to interfaces, data types, and other architectural data elements. In AUTOSAR workflows, profiles and stereotypes enable you to define safety levels, such as Automotive Safety Integrity Level (ASIL) and create custom views that focus on certain aspects of the architecture. ASIL specifications are exported to ARXML.

Apply a profile to the data dictionary using the applyProfile (System Composer) function on the Simulink.dictionary.ArchitecturalData object.

applyProfile(archData,"ASILProfile");

Apply a stereotype to an interface or other architectural data element by using the applyStereotype (System Composer) function.

applyStereotype(speedDataSR,"ASILProfile.SafetyIntegrityLevel");

Set stereotype property values on the element by using the setProperty (System Composer) function.

setProperty(speedDataSR,"ASILProfile.SafetyIntegrityLevel.ASIL","'C'");

You can also manage profiles and stereotypes from the Architectural Data Editor. Access the Profile Editor from the Profiles tab to import or create profiles, then apply stereotypes to architectural data elements by using the Stereotypes pane.

Link Data Dictionary to AUTOSAR Software Architecture Model

Link the data dictionary containing architectural data to an architecture model so that components and compositions in the model can consume the shared interfaces, types, and constants. Use the linkDictionary function to link a dictionary.

Create a data dictionary for speed monitoring interfaces.

dictName = "SpeedInterfaces.sldd";
archData = Simulink.dictionary.archdata.create(dictName);

Create an AUTOSAR architecture model and link it to the data dictionary. Component and architecture models linked to the data dictionary use the interfaces, types, and AUTOSAR properties defined in the Architectural Data section.

archModel = autosar.arch.createModel("SpeedMonitorArch");
linkDictionary(archModel,dictName);

Assign Interfaces to AUTOSAR Software Component, Composition, and Architecture Ports

Once your data dictionary is linked to an architecture model, you can consume the architectural data by assigning interfaces to ports in the model. Interfaces and types authored in the Architectural Data section, with platform-specific properties configured through the AUTOSAR Classic platform mapping, are applied to the modeled AUTOSAR components. When you export ARXML from the model, the ports use the platform-specific properties configured in the platform mapping.

Add a sender-receiver data interface to the data dictionary.

speedDataSR = addDataInterface(archData,"SpeedDataSR");

Add a sender port to the architecture model and assign the data interface from the dictionary.

speedOutPort = addPort(archModel,"Sender","SpeedOut");
setInterface(speedOutPort,speedDataSR);

Export ARXML from Data Dictionary

Export ARXML and RTE stub header files directly from a data dictionary without creating a model. Use the exportDictionary function on the AUTOSAR Classic Platform mapping object. The export creates a folder in the current working directory containing ARXML files and RTE stub headers.

evalc('exportDictionary(platformMapping);');

The export generates the following files in the SpeedMonitorData/ folder:

  • SpeedMonitorData_interface.arxml — Interface definitions

  • SpeedMonitorData_datatype.arxml — Data type definitions, software address methods, and constants

  • Rte_Type.h, Std_Types.h, Platform_Types.h, Compiler.h — RTE stub header files in the stub sub-folder

In SpeedMonitorData_interface.arxml, the SpeedDataNV interface appears as an NV-DATA-INTERFACE under the package path configured with setPlatformProperty. The CurrentSpeed element includes the software address method and calibration access properties:

<AR-PACKAGE>
    <SHORT-NAME>SpeedMonitor</SHORT-NAME>
    <AR-PACKAGES>
        <AR-PACKAGE>
            <SHORT-NAME>Interfaces</SHORT-NAME>
            <ELEMENTS>
                <NV-DATA-INTERFACE>
                    <SHORT-NAME>SpeedDataNV</SHORT-NAME>
                    <IS-SERVICE>false</IS-SERVICE>
                    <NV-DATAS>
                        <VARIABLE-DATA-PROTOTYPE>
                            <SHORT-NAME>CurrentSpeed</SHORT-NAME>
                            <SW-DATA-DEF-PROPS>
                              <SW-DATA-DEF-PROPS-VARIANTS>
                                <SW-DATA-DEF-PROPS-CONDITIONAL>
                                  <SW-ADDR-METHOD-REF DEST="SW-ADDR-METHOD">/SpeedMonitor/SwAddrMethods/MeasuredData</SW-ADDR-METHOD-REF>
                                  <SW-CALIBRATION-ACCESS>READ-WRITE</SW-CALIBRATION-ACCESS>
                                  <DISPLAY-FORMAT>%.3f</DISPLAY-FORMAT>
                                </SW-DATA-DEF-PROPS-CONDITIONAL>
                              </SW-DATA-DEF-PROPS-VARIANTS>
                            </SW-DATA-DEF-PROPS>
                            <TYPE-TREF DEST="APPLICATION-ARRAY-DATA-TYPE">/DataTypes/ApplDataTypes/WheelSpeeds_VT</TYPE-TREF>
                        </VARIABLE-DATA-PROTOTYPE>
                    </NV-DATAS>
                </NV-DATA-INTERFACE>

The SpeedService service interface exports as a CLIENT-SERVER-INTERFACE with operations. The NotifySpeedExceeded operation has only an input argument and no output, reflecting the ServerResponseNotRequired configuration:

<CLIENT-SERVER-INTERFACE>
    <SHORT-NAME>SpeedService</SHORT-NAME>
    <IS-SERVICE>false</IS-SERVICE>
    <OPERATIONS>
        <CLIENT-SERVER-OPERATION>
            <SHORT-NAME>GetCurrentSpeed</SHORT-NAME>
            <ARGUMENTS>
                <ARGUMENT-DATA-PROTOTYPE>
                    <SHORT-NAME>sensorId</SHORT-NAME>
                    <DIRECTION>IN</DIRECTION>
                </ARGUMENT-DATA-PROTOTYPE>
                <ARGUMENT-DATA-PROTOTYPE>
                    <SHORT-NAME>speed</SHORT-NAME>
                    <DIRECTION>OUT</DIRECTION>
                </ARGUMENT-DATA-PROTOTYPE>
            </ARGUMENTS>
        </CLIENT-SERVER-OPERATION>
        <CLIENT-SERVER-OPERATION>
            <SHORT-NAME>NotifySpeedExceeded</SHORT-NAME>
            <ARGUMENTS>
                <ARGUMENT-DATA-PROTOTYPE>
                    <SHORT-NAME>threshold</SHORT-NAME>
                    <DIRECTION>IN</DIRECTION>
                </ARGUMENT-DATA-PROTOTYPE>
            </ARGUMENTS>
        </CLIENT-SERVER-OPERATION>
    </OPERATIONS>
</CLIENT-SERVER-INTERFACE>

In SpeedMonitorData_datatype.arxml, the software address method defined earlier appears under the configured package path:

<AR-PACKAGE>
    <SHORT-NAME>SpeedMonitor</SHORT-NAME>
    <AR-PACKAGES>
        <AR-PACKAGE>
            <SHORT-NAME>SwAddrMethods</SHORT-NAME>
            <ELEMENTS>
                <SW-ADDR-METHOD>
                    <SHORT-NAME>MeasuredData</SHORT-NAME>
                    <SECTION-INITIALIZATION-POLICY>INIT</SECTION-INITIALIZATION-POLICY>
                    <SECTION-TYPE>VAR</SECTION-TYPE>
                </SW-ADDR-METHOD>
            </ELEMENTS>
        </AR-PACKAGE>
    </AR-PACKAGES>
</AR-PACKAGE>

The exported ARXML preserves all UUIDs and AUTOSAR metadata. Platform-specific properties configured in the platform mapping, such as InterfaceKind, SwAddrMethod, SwCalibrationAccess, and DisplayFormat appear in the corresponding ARXML elements.

See Also

Functions

Objects

Topics