BSB Developer Docs
Loading...
Searching...
No Matches
nvm.h File Reference

Non-volatile flash memory API. More...

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <furi.h>

Go to the source code of this file.

Macros

#define RECORD_NVM   "nvm"
 The string key for Nvm instance access.
 

Typedefs

typedef struct Nvm Nvm
 

Enumerations

enum  NvmKeyRange {
  NvmKeyRangeMin = 0x0UL , NvmKeyRangeUser1Min = 0x10000UL , NvmKeyBlePairingData = 0x10001UL , NvmKeyCryptoAccessMode = 0x10002UL ,
  NvmKeyRangeUser1Max = 0x87000UL , NvmKeyRangeUser2Min = 0x88000UL , NvmKeyRangeMax = 0x1000000UL
}
 Enumeration of available Nvm key ranges. More...
 

Functions

bool nvm_exists (Nvm *instance, uint32_t key, size_t *len)
 Check if a record exists under a given key and optionally get its length.
 
FURI_CHECK_RETURN bool nvm_read (Nvm *instance, uint32_t key, void *data, size_t len)
 Read the record data under a given key.
 
FURI_CHECK_RETURN bool nvm_read_partial (Nvm *instance, uint32_t key, void *data, size_t offset, size_t len)
 Read the record data under a given key partially.
 
FURI_CHECK_RETURN bool nvm_write (Nvm *instance, uint32_t key, const void *data, size_t len)
 Write data to a record under a given key.
 
FURI_CHECK_RETURN bool nvm_read_counter (Nvm *instance, uint32_t key, uint32_t *value)
 Read the counter value under a given key.
 
FURI_CHECK_RETURN bool nvm_write_counter (Nvm *instance, uint32_t key, uint32_t value)
 Write the counter value under a given key.
 
FURI_CHECK_RETURN bool nvm_increment_counter (Nvm *instance, uint32_t key, uint32_t *value)
 Increment the counter under a given key by 1 and optionally get its value.
 
FURI_CHECK_RETURN bool nvm_delete (Nvm *instance, uint32_t key)
 Delete the record under a given key.
 
FURI_CHECK_RETURN bool nvm_repack (Nvm *instance)
 Repack the storage to optimise space.
 
FURI_CHECK_RETURN bool nvm_erase_all (Nvm *instance)
 Erase all data from the storage.
 
FURI_CHECK_RETURN bool nvm_purge_all (Nvm *instance)
 Erase all data AND metadata from the storage.
 

Detailed Description

Non-volatile flash memory API.

Macro Definition Documentation

◆ RECORD_NVM

#define RECORD_NVM   "nvm"

The string key for Nvm instance access.

Get the instance pointer by calling furi_record_open(RECORD_NVM)

Enumeration Type Documentation

◆ NvmKeyRange

Enumeration of available Nvm key ranges.

Warning
Keys 0x0-0xFFFF are reserved, do not use
Keys 0x87000-0x87FFF are reserved, do not use
Enumerator
NvmKeyRangeMin 

Minimum key value (inclusive)

NvmKeyRangeUser1Min 

Free to use key range 1 start (inclusive)

NvmKeyRangeUser1Max 

Free to use key range 1 end (non-inclusive)

NvmKeyRangeUser2Min 

Free to use key range 2 start (inclusive)

NvmKeyRangeMax 

Maximum key value (non-inclusive)

Function Documentation

◆ nvm_delete()

FURI_CHECK_RETURN bool nvm_delete ( Nvm * instance,
uint32_t key )

Delete the record under a given key.

Parameters
[in,out]instancepointer to the Nvm instance
[in]keykey associated with the record to be deleted
Returns
true if the record could be deleted, false otherwise

◆ nvm_erase_all()

FURI_CHECK_RETURN bool nvm_erase_all ( Nvm * instance)

Erase all data from the storage.

Warning
This will ERASE ALL THE DATA on the storage, use with caution
Parameters
[in,out]instancepointer to the Nvm instance
Returns
true if the storage could be erased, false otherwise.

◆ nvm_exists()

bool nvm_exists ( Nvm * instance,
uint32_t key,
size_t * len )

Check if a record exists under a given key and optionally get its length.

Parameters
[in,out]instancepointer to the Nvm instance
[in]keykey associated with the record to be checked
[out]lenoptional pointer to the variable to contain the record length (may be NULL)
Returns
true if the record exists, false otherwise

◆ nvm_increment_counter()

FURI_CHECK_RETURN bool nvm_increment_counter ( Nvm * instance,
uint32_t key,
uint32_t * value )

Increment the counter under a given key by 1 and optionally get its value.

Parameters
[in,out]instancepointer to the Nvm instance
[in]keykey associated with the counter to be incremented
[out]valueoptional pointer to the variable to hold the new counter value (may be NULL)
Returns
true if the counter could be incremented, false otherwise

◆ nvm_purge_all()

FURI_CHECK_RETURN bool nvm_purge_all ( Nvm * instance)

Erase all data AND metadata from the storage.

Warning
This will ERASE ALL THE DATA on the storage, use with caution

Unlike nvm_erase_all() which will keep the partition initialised, calling this function will completely reset it to a clean slate.

Parameters
[in,out]instancepointer to the Nvm instance
Returns
true if the storage could be purged, false otherwise.

◆ nvm_read()

FURI_CHECK_RETURN bool nvm_read ( Nvm * instance,
uint32_t key,
void * data,
size_t len )

Read the record data under a given key.

Note
Value of len MUST match the data length given during writing, otherwise an error will occur.
Parameters
[in,out]instancepointer to the Nvm instance
[in]keykey associated with the record to be read
[out]datapointer to the buffer to hold the data (must be large enough)
[in]lenlength of the data to be read (see note), in bytes
Returns
true if the record could be read, false otherwise

◆ nvm_read_counter()

FURI_CHECK_RETURN bool nvm_read_counter ( Nvm * instance,
uint32_t key,
uint32_t * value )

Read the counter value under a given key.

Parameters
[in,out]instancepointer to the Nvm instance
[in]keykey associated with the counter to be read
[out]valuepointer to the variable to hold the counter value
Returns
true if the counter could be read, false otherwise

◆ nvm_read_partial()

FURI_CHECK_RETURN bool nvm_read_partial ( Nvm * instance,
uint32_t key,
void * data,
size_t offset,
size_t len )

Read the record data under a given key partially.

Note
Value of len - offset MUST match the data length given during writing, otherwise an error will occur.
Parameters
[in,out]instancepointer to the Nvm instance
[in]keykey associated with the record to be read
[out]datapointer to the buffer to hold the data (must be large enough)
[in]offsetoffset from the beginning of the data, in bytes
[in]lenlength of the data to be read (see note), in bytes
Returns
true if the record could be read, false otherwise

◆ nvm_repack()

FURI_CHECK_RETURN bool nvm_repack ( Nvm * instance)

Repack the storage to optimise space.

Note
The operation will only be performed if the driver logic decides that it is needed.
Parameters
[in,out]instancepointer to the Nvm instance
Returns
true if the storage could be repacked, false otherwise

◆ nvm_write()

FURI_CHECK_RETURN bool nvm_write ( Nvm * instance,
uint32_t key,
const void * data,
size_t len )

Write data to a record under a given key.

Note
If a record under the given key already exists, it will be overwritten with the new data.
Parameters
[in,out]instancepointer to the Nvm instance
[in]keykey associated with the record to be written
[in]datapointer to the data to be written
[in]lenlength of the data to be written
Returns
true if the record could be written, false otherwise

◆ nvm_write_counter()

FURI_CHECK_RETURN bool nvm_write_counter ( Nvm * instance,
uint32_t key,
uint32_t value )

Write the counter value under a given key.

Parameters
[in,out]instancepointer to the Nvm instance
[in]keykey associated with the counter to be written
[in]valuecounter value to be written
Returns
true if the counter could be written, false otherwise