Main Content

cgsl_0411: Access nonvolatile memory

ID: Titlecgsl_0411: Access nonvolatile memory
DescriptionTo access target platform nonvolatile memory, use one of these approaches:
A

Use a persistency service interface for asynchronous or synchronous memory access:

  1. Configure a measurement service interface that specifies Persistent Data.

  2. Configure states and data stores to use the measurement service interface for persistent data.

B

Use Initialize Function and Terminate Function blocks and the Direct Access data communication method for synchronous memory access:

  1. At the root-level of the component, use the Initialize Function block to read data and the Terminate Function block to write data.

  2. Configure the root-level ports to use the Direct Access data communication method.

Notes

Memory access using a persistency service interface

For accessing nonvolatile memory by using a service provided by the target environment, map internal states and data stores to a measurement service interface for persistent data. For more information, see cgsl_0414: Configure service interface for component model.

Alternatively, you can use a client-server interface approach for modeling the service interface. With this approach, you represent the target environment service that provides access to nonvolatile memory by using a Simulink Function block and access the service by using the Function Caller block. For more information, see Nonvolatile Memory Interfaces (Embedded Coder).

Memory access by using Initialize Function and Terminate Function blocks

For synchronous accesses of nonvolatile memory during function execution, see guidelines cgsl_0406: Data send for component deployment and cgsl_0405: Data receive for component deployment.

RationaleA

Memory access using a persistency service interface:

  • Supports asynchronous or synchronous reading and writing to nonvolatile memory

  • Robustly handles data accesses of functions that execute concurrently

  • Supports multiple instances of components

  • Uses target platform service

B

Memory access using Initialize Function and Terminate Function blocks:

  • Supports only synchronous reading and writing to nonvolatile memory

  • Robustly handles data accesses of functions that execute concurrently

  • Supports multiple instances of components

Model Advisor CheckA Model Advisor check is not provided for this guideline.
Examples

Memory access using a persistency service interface

Simulink model that contains a discrete integrator

Code Mappings editor. The Discrete Integrator state is mapped to PermanentRAM measurement service.

Example of generated ModelName.h:

#include "PersistencyServiceExample_types.h" 
#include "services.h" 
. 
. 
. 
/* Storage class 'PersistentMemory' */ 
extern double DiscreteIntegrator; 
. 
. 
.
Example of generated ModelName.c:
#include "PersistencyServiceExample.h" 

/* Storage class 'PersistentMemory' */ 
double DiscreteIntegrator;           /* '<Root>/Discrete Integrator' */ 
. 
. 
. 
void PersistencyServiceExample_step(void) 
{ 
   double EstimatedPosition; 
   EstimatedPosition = DiscreteIntegrator;
   DiscreteIntegrator++; 
   . 
   . 
   . 
}

Memory access using Initialize Function and Terminate Function blocks

Simulink model that uses Initialize Function and Terminate Function blocks to access nonvolatile memory

Example of generated ModelName.c:

void CD_initialize(void)
.
.
.
    &(get_CD_initialize_input())[0]
.
.
.
void CD_terminate(void)
{
  memcpy(&(getref_CD_terminate_OutBus_NVM()))[0]...
}

Version History

expand all

Introduced in R2022b