Contenido principal

Model AUTOSAR Adaptive Persistent Memory

R2026b

Persistency is a measurement service that preserves data in nonvolatile memory across power cycles. When you map a data element to a persistent measurement service and generate code, the generated service code reads the stored value from nonvolatile memory at initialization. The code writes the value back at termination. Between initialization and termination, the software component operates on the data in RAM. The software component does not access nonvolatile memory during execution.

To model adaptive persistent memory in Simulink®, you create AUTOSAR elements in the AUTOSAR Dictionary and corresponding elements in the Simulink model. For example, you:

  • Create AUTOSAR persistency provided-required ports, persistency key value interfaces, and key value interface data elements in the AUTOSAR Dictionary.

  • Map local data stores, states, and signals in the model to AUTOSAR persistency ports and data elements by using the Service Mappings Editor.

If you have Embedded Coder® software, you can generate C++ algorithm and service implementation code and export AUTOSAR XML (ARXML) descriptions for AUTOSAR persistent memory artifacts.

To implement adaptive persistent memory in Simulink:

  1. Open a model configured for the AUTOSAR Adaptive Platform. This example uses model adaptive_ActuatorSWC. Open this model by entering this command in your MATLAB® Command Window:

    openExample("adaptive_ActuatorSWC");

  2. Open the AUTOSAR Dictionary and select Persistency Key Value Interfaces. To create an AUTOSAR persistency key value interface, click the Add button . In the Add Interfaces dialog box, specify the interface name and the number of associated data elements. Click Add. In this example add persistency key value interface PerKeyIf.

    Add Interfaces dialog box for creating a persistency key value interface, with fields for interface name and number of data elements.

  3. In the AUTOSAR Dictionary, expand the Persistency Key Value Interfaces node. Expand the new key value interface and select DataElements. In the data elements view name each data element.

  4. Expand the AdaptiveApplications and adaptiev_ActuatorSWC nodes. Use the PersistencyProvidedRequiredPorts view to add AUTOSAR persistency provided-required ports that you want to associate with the new persistency key value interface. In this example, add NumBrakeCmds, and set Interface to PerKeyIf with data element DE1.

    AUTOSAR Dictionary with persistency provided-required port NumBrakeCmds with interface PerKeyIf.

  5. To map AUTOSAR adaptive persistency provided-required ports to data stores, signals, and states, open the Service Mappings Editor in the model window and navigate to the Measurements tab. For each data store, signal, and state, you can select the Persistency measurement service. In this example, map data store NumberofAutomatedBrakeCmds as a persistent measurement service.

    Service Mappings editor Measurements tab showing Unit Delay blocks mapped to Persistency Measure Service.

    Then click the pencil icon at the end of the row for NumberOfAutomatedBrakeCmds. In the box that appears, set Port to NumBrakeCmds and DataElement to DE1.

    Service Mappings editor Measurements tab showing Unit Delay blocks mapped to AUTOSAR persistency provided-required ports and key value interface data elements.

  6. Validate the service mappings of an AUTOSAR Adaptive software component by clicking the Validate button in the Service Mappings Editor.

  7. Build the model. Building the model generates C++ algorithm and service implementation code and exports ARXML descriptions that contain AUTOSAR persistent memory artifacts.

    The build generates file PerServicesImpl.cpp in folder <modelName>/services/per. This file contains service implementation code that reads persistent values from nonvolatile storage at initialization and writes them back at termination, by using the ara::per key value storage API.

    ...
    void ec::scheduler::PerService::PreInitialize() {
      ara::per::RegisterApplicationDataUpdateCallback(updateInitialValuesToDB);
      {
        ara::core::Result<ara::per::SharedHandle<ara::per::KeyValueStorage>>
            kvsResult = ara::per::OpenKeyValueStorage(ara::core::InstanceSpecifier(
                "adaptive_ActuatorSWC/"
                "adaptive_ActuatorSWC_RootSwComponentPrototype/NumBrakeCmds"));
        if (kvsResult.HasValue()) {
          auto kvsPtr = kvsResult.Value();
          if (kvsPtr) {
            auto perResult_DE1 = kvsPtr->GetValue<double>("DE1");
            if (perResult_DE1.HasValue()) {
              PersistentMemory_adaptive_ActuatorSWC.NumberOfAutomatedBrakeCmds =
                  perResult_DE1.Value();
            }
          }
        }
      }
    }
    
    void ec::scheduler::PerService::PostTerminate() {
      {
        ara::core::Result<ara::per::SharedHandle<ara::per::KeyValueStorage>>
            kvsResult = ara::per::OpenKeyValueStorage(ara::core::InstanceSpecifier(
                "adaptive_ActuatorSWC/"
                "adaptive_ActuatorSWC_RootSwComponentPrototype/NumBrakeCmds"));
        if (kvsResult.HasValue()) {
          auto kvsPtr = kvsResult.Value();
          if (kvsPtr) {
            kvsPtr->SetValue<double>(
                "DE1",
                PersistentMemory_adaptive_ActuatorSWC.NumberOfAutomatedBrakeCmds);
            kvsPtr->SyncToStorage();
          }
        }
      }
    }
    

    The exported ARXML contains descriptions of the persistency key value interface, and the required services for the persistency provided-required ports and the mapping from persistency port prototypes to key value storage. For example, in adaptive_ActuatorSWC_component.arxml the PERSISTENCY-DATA-REQUIRED-COM-SPEC describes the AUTOSAR persistency key value interface and persistency provided-required port element definitions.

    <PR-PORT-PROTOTYPE UUID="...">
        <SHORT-NAME>NumBrakeCmds</SHORT-NAME>
        <PROVIDED-COM-SPECS/>
        <REQUIRED-COM-SPECS>
            <PERSISTENCY-DATA-REQUIRED-COM-SPEC>
                <DATA-ELEMENT-REF DEST="PERSISTENCY-DATA-ELEMENT">/Interfaces/PerKeyIf/DE1</DATA-ELEMENT-REF>
                <INIT-VALUE>
                    <NUMERICAL-VALUE-SPECIFICATION>
                        <SHORT-LABEL>DefaultInitValue_double</SHORT-LABEL>
                        <VALUE>0</VALUE>
                    </NUMERICAL-VALUE-SPECIFICATION>
                </INIT-VALUE>
            </PERSISTENCY-DATA-REQUIRED-COM-SPEC>
        </REQUIRED-COM-SPECS>
        <PROVIDED-REQUIRED-INTERFACE-TREF DEST="PERSISTENCY-INTERFACE">/Interfaces/PerKeyIf</PROVIDED-REQUIRED-INTERFACE-TREF>
    </PR-PORT-PROTOTYPE>

If you have the Embedded Coder Support Package for Service-Oriented Applications on Linux® support package, you can deploy AUTOSAR Adaptive software components as applications. At run time, the deployed application stores persistent data in a key value database. For more information about deploying AUTOSAR Adaptive applications, see Get Started with Embedded Coder Support Package for Service-Oriented Applications on Linux.

See Also

Topics