Main Content

Programmatically Manage Shared Interfaces, Data Types, and Constants of Architecture Models

The Architectural Data section of a Simulink® data dictionary enables interfaces, data types, constants and AUTOSAR-specific data to be authored, managed, and shared between AUTOSAR components and compositions modeled in Simulink. The Architectural Data section provides scalability for system-level and multicomponent designs by containing these shared elements in a central location.

You can programmatically configure architectural data and apply your changes to your model using this basic workflow:

  1. Create or open a data dictionary.

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

  3. Link the data dictionary containing architectural data to a Simulink or architecture model.

  4. Apply architectural data to a model programmatically.

Create or Open Simulink Data Dictionary Programmatically

These functions return Architectural Data objects that you can edit using the Simulink.dictionary.ArchitecturalData programmatic interfaces.

Design Data Types, Interfaces, and Constants Programmatically

  1. To programmatically create, configure, and manage architectural data in your data dictionary, use the programmatic interfaces for the Simulink.dictionary.ArchitecturalData object.

    dictName = "myDataDictionary.sldd";
    archDataObj = Simulink.dictionary.archdata.create(dictName);
  2. Use type-specific functions to add alias types and enumerations to the data dictionary.

    myAliasType1Obj = addAliasType(archDataObj,"aliasType",BaseType="single");
    myAliasType1Obj.Name = "myAliasType1";
    myAliasType1Obj.BaseType = "fixdt(1,32,16)";
    myAliasType2Obj = addAliasType(archDataObj,"myAliasType2");
    myAliasType2Obj.BaseType = myAliasType1Obj;
    
    myEnumType1Obj = addEnumType(archDataObj,"myColor");
    myEnumType1Obj.DefaultValue = "BLUE";
    myEnumType1Obj.Description = "I am a Simulink Enumeration";
    myEnumType1Obj.StorageType = "int16"; 
  3. You can set the base type of the created alias type to be the created enumeration data type myColor.

    myAliasType3Obj = addAliasType(archDataObj,"myAliasType3");
    myAliasType3Obj.BaseType = myEnumType1Obj;
  4. Use the addNumericType function to add numeric types to the data dictionary.

    myNumericType1Obj = addNumericType(archDataObj,"myNumericType1");
    myNumericType1Obj.DataTypeMode = "Single";
  5. Use the addValueType to add value types to the data dictionary. You can also set the data type of the value types to be pre-existing data types or created enumeration data types.

    myValueType1Obj = addValueType(archDataObj,"myValueType1");
    myValueType1Obj.DataType = 'int32';
    myValueType1Obj.Dimensions = '[2 3]';
    myValueType1Obj.Description = "I am a Simulink ValueType";
  6. Use the addStructType function to add struct types to the data dictionary.

    myStructType1Obj = addStructType(archDataObj,"myStructType1");
    structElement1 = myStructType1Obj.addElement("Element1");
    structElement1.Type.DataType = 'single';
    structElement1.Type.Dimensions = '3';
    structElement2 = addElement(myStructType1Obj,"Element2");
    structElement3 = addElement(myStructType1Obj,"Element3");
  7. You can set the data type of a struct element by using the data type object or by using the name of the data type, specified as a string scalar or character vector.

    structElement2.Type = myValueType1Obj;
    % or
    structElement3.Type = "ValueType: myValueType1";
  8. You can add constants using the addConstant function.

    myConstantObj = addConstant(archDataObj, "myConst", Value=4);
  9. You can add communication interfaces and their data elements using the functions of the Simulink.dictionary.archdata.DataInterface object.

    nvInterface1 = addDataInterface(archDataObj,"NV1");
    
    dataElm1 = addElement(nvInterface1,"DE1");
    dataElm1.Type = myValueType1Obj;
    dataElm2 = addElement(nvInterface1,"DE3");
    dataElm2.Type.DataType = 'single';
    dataElm2.Type.Dimensions = '10';
    dataElm2.Type.Minimum = '-5';
     
    srInterface2 = addDataInterface(archDataObj,"SR1");
  10. Add AUTOSAR Classic platform mapping using the addPlatformMapping function. You can get and set properties using the setPlatformProperty and getPlatformProperties functions.

    platformMapping = addPlatformMapping(archDataObj,"AUTOSARClassic");
    setPlatformProperty(platformMapping,nvInterface1,...
        "Package", "/Interface2", "InterfaceKind", "NvDataInterface");
    [pNames, pValues] = getPlatformProperties(platformMapping,nvInterface1);
  11. Programmatically manage AUTOSAR Classic platform related elements that do not have mappings to Simulink. See autosar.api.getAUTOSARProperties for information regarding related workflows.

    arPropsObj = autosar.api.getAUTOSARProperties(dictName);
    arPropsObj.addPackageableElement("SwAddrMethod","/SwAddressMethods","VAR1","SectionType","Var");
    setPlatformProperty(platformMapping,dataElm1,...
        "SwAddrMethod","VAR1","SwCalibrationAccess","ReadWrite","DisplayFormat","%.3f");

Link Data Dictionary Programmatically

To link a dictionary to a model programmatically use the linkDictionary function.

  1. Create or open a Simulink data dictionary. In this example you create a new data dictionary MyInterfaces.sldd.

    dictName = "MyInterfaces.sldd";
    archDataObj = Simulink.dictionary.archdata.create(dictName);
  2. Create an AUTOSAR architecture model and link it to a simulink data dictionary.

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

Apply Data Changes Programmatically

Once your data dictionary is linked to an architecture model, you can apply the changes to your modeled application programmatically by using the Simulink.dictionary.ArchitecturalData object.

Here, you link a dictionary with an AUTOSAR Classic platform mapping to an architecture model then map a SenderPort to an interface in that dictionary.

  1. Create or open a Simulink data dictionary. In this example you create a new data dictionary MyInterfaces.sldd.

    dictName = 'MyInterfaces.sldd';
    archDataObj = Simulink.dictionary.archdata.create(dictName);
  2. Create an AUTOSAR architecture model.

    archModel = autosar.arch.createModel('myTopComposition'); 
  3. Add a data interface to the Architectural Data of the AUTOSAR architecture model.

    srInterface2 = addDataInterface(archDataObj,'SR1');
  4. Link a data dictionary to the AUTOSAR architecture model.

    linkDictionary(archModel,dictName);
  5. Add a port and set the interface of the port.

    pport = archModel.addPort("Sender", 'PPort');
    setInterface(pport,srInterface2);

Limitations

Some limitations for AUTOSAR mapped data dictionaries include:

  • Data dictionary reference hierarchies are not supported for data dictionaries mapped to the AUTOSAR Classic Platform.

  • The Interface Editor can only view and edit data interfaces. To author and view other kinds of interfaces for AUTOSAR workflows, such as client/server, parameter, and trigger interfaces, use the AUTOSAR component dictionary.

    An AUTOSAR component dictionary showing Client Server interfaces.

  • The data dictionary does not support the import of AUTOSAR information from an ARXML file.

See Also

| | | | | | |

Related Topics