Safe API Framework 0.1.0 build 384e6ae
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
Non-Volatile Memory User Guide

What is NVM?

NVM provides persistent storage for configuration, state, diagnostics. Caller manages address space and layout. Read/write with checksums.

Quick Start

// Define NVM layout
#define CONFIG_ADDR 0
#define CONFIG_SIZE 256
// Read configuration
config_t cfg;
rte_nvm_read(CONFIG_ADDR, (uint8_t *)&cfg, sizeof(cfg));
// Verify checksum
uint32_t crc = compute_crc((uint8_t *)&cfg, sizeof(cfg) - 4);
if (crc != cfg.checksum) {
log_error("Config corrupted");
use_default_config(&cfg);
}
// Save configuration
cfg.checksum = compute_crc((uint8_t *)&cfg, sizeof(cfg) - 4);
rte_nvm_write(CONFIG_ADDR, (uint8_t *)&cfg, sizeof(cfg));
rte_status_t rte_nvm_read(rte_nvm_handle_t handle, size_t offset, void *out_buffer, size_t buffer_size)
Reads and integrity-checks data from an NVM region.
Definition rte_nvm.c:77
rte_status_t rte_nvm_write(rte_nvm_handle_t handle, size_t offset, const void *buffer, size_t buffer_size)
Writes data and its integrity metadata to an NVM region.
Definition rte_nvm.c:97

Best Practices

  1. Always use checksums
  2. Manage wear (limit writes)
  3. Plan address layout
  4. Version data for evolution

See Also