6.2. nvm — Non-volatile memory

A non-volatile memory is typically used for long-term persistent storage.

This module implements a singleton non-volatile memory, often on top of an EEPROM or software emulated EEPROM.


Source code: src/oam/nvm.h, src/oam/nvm.c

Test coverage: src/oam/nvm.c


Functions

int nvm_module_init(void)
int nvm_mount(void)

Mount the non-volatile memory.

Return
zero(0) if the memory was successfully mounted, otherwise negative error code.

int nvm_format(void)

Format the non-volatile memory, writing 0xff/erasing to the whole memory. A formatted NVM can always be mounted with nvm_mount().

Return
zero(0) or negative error code.

ssize_t nvm_read(void *dst_p, uint32_t src, size_t size)

Read into given buffer from given NVM address.

Return
Number of bytes read or negative error code.
Parameters
  • dst_p: Buffer to read into.
  • src: Address in NVM to read from. Addressing starts at zero(0).
  • size: Number of bytes to read.

ssize_t nvm_write(uint32_t dst, const void *src_p, size_t size)

Write given buffer to given NVM address.

Return
Number of bytes written or negative error code.
Parameters
  • dst: Address in NVM to write to. Addressing starts at zero(0).
  • src_p: Buffer to write.
  • size: Number of bytes to write.