Mistake on this page?
Report an issue in GitHub or email us
Data Structures | Public Member Functions | Static Public Member Functions
NVStore Class Reference

NVStore class. More...

#include <nvstore.h>

Inheritance diagram for NVStore:
NonCopyable< NVStore >

Public Member Functions

uint16_t get_max_keys () const
 Returns number of keys. More...
 
void set_max_keys (uint16_t num_keys)
 Set number of keys. More...
 
uint16_t get_max_possible_keys ()
 Return maximal possible number of keys (in this flash configuration). More...
 
int get (uint16_t key, uint16_t buf_size, void *buf, uint16_t &actual_size)
 Returns one item of data programmed on Flash, given key. More...
 
int get_item_size (uint16_t key, uint16_t &actual_size)
 Returns size of the data programmed on Flash, given key. More...
 
int set (uint16_t key, uint16_t buf_size, const void *buf)
 Programs one item of data on Flash, given key. More...
 
int allocate_key (uint16_t &key, uint8_t owner=NVSTORE_UNSPECIFIED_OWNER)
 Allocate a free key (to be used later in a set operation). More...
 
int free_all_keys_by_owner (uint8_t owner)
 Free all allocated keys that belong to a specific owner. More...
 
int set_once (uint16_t key, uint16_t buf_size, const void *buf)
 Programs one item of data on Flash, given key, allowing no consequent sets to this key. More...
 
int remove (uint16_t key)
 Remove an item from flash. More...
 
int init ()
 Initializes NVStore component. More...
 
int deinit ()
 Deinitializes NVStore component. More...
 
int reset ()
 Reset Flash NVStore areas. More...
 
size_t size ()
 Return NVStore size (area size). More...
 
int get_area_params (uint8_t area, uint32_t &address, size_t &size)
 Return address and size of an NVStore area. More...
 

Static Public Member Functions

static NVStoreget_instance ()
 As a singleton, return the single instance of the class. More...
 

Detailed Description

NVStore class.

Class for storing data by keys in the internal flash

Definition at line 76 of file nvstore.h.

Member Function Documentation

int allocate_key ( uint16_t &  key,
uint8_t  owner = NVSTORE_UNSPECIFIED_OWNER 
)

Allocate a free key (to be used later in a set operation).

Parameters
[out]keyReturned key of stored item.
[in]ownerOwner of allocated key.
Returns
NVSTORE_SUCCESS Key was successfully allocated. NVSTORE_NO_FREE_KEY Couldn't allocate a key for this call.
int deinit ( )

Deinitializes NVStore component.

Warning: This function is not thread safe and should not be called concurrently with other NVStore functions.

Returns
NVSTORE_SUCCESS Deinitialization completed successfully.
int free_all_keys_by_owner ( uint8_t  owner)

Free all allocated keys that belong to a specific owner.

Parameters
[in]ownerOwner.
Returns
NVSTORE_SUCCESS Value was successfully written on Flash. NVSTORE_WRITE_ERROR Physical error writing data. NVSTORE_BAD_VALUE Bad value in any of the parameters.
int get ( uint16_t  key,
uint16_t  buf_size,
void *  buf,
uint16_t &  actual_size 
)

Returns one item of data programmed on Flash, given key.

Parameters
[in]keyKey of stored item.
[in]buf_sizeLength of input buffer in bytes.
[in]bufBuffer to store data on.
[out]actual_sizeActual size of returned data.
Returns
NVSTORE_SUCCESS Value was found on Flash. NVSTORE_NOT_FOUND Value was not found on Flash. NVSTORE_READ_ERROR Physical error reading data. NVSTORE_DATA_CORRUPT Data on Flash is corrupt. NVSTORE_BAD_VALUE Bad value in any of the parameters. NVSTORE_BUFF_TOO_SMALL Not enough memory in user buffer.
int get_area_params ( uint8_t  area,
uint32_t &  address,
size_t &  size 
)

Return address and size of an NVStore area.

Parameters
[in]areaArea.
[out]addressArea address.
[out]sizeArea size (bytes).
Returns
NVSTORE_SUCCESS Success. NVSTORE_BAD_VALUE Bad area parameter.
static NVStore& get_instance ( )
static

As a singleton, return the single instance of the class.

Reason for this class being a singleton is the following:

  • Ease the use for users of this class not having to coordinate instantiations.
  • Lazy instantiation of internal data (which we can't achieve with simple static classes).
Returns
Singleton instance reference.

Definition at line 87 of file nvstore.h.

int get_item_size ( uint16_t  key,
uint16_t &  actual_size 
)

Returns size of the data programmed on Flash, given key.

Parameters
[in]keyKey of stored item.
[out]actual_sizeActual size of item
Returns
NVSTORE_SUCCESS Value was found on Flash. NVSTORE_NOT_FOUND Value was not found on Flash. NVSTORE_READ_ERROR Physical error reading data. NVSTORE_DATA_CORRUPT Data on Flash is corrupt. NVSTORE_BAD_VALUE Bad value in any of the parameters.
uint16_t get_max_keys ( ) const

Returns number of keys.

Returns
Number of keys.
uint16_t get_max_possible_keys ( )

Return maximal possible number of keys (in this flash configuration).

Returns
Max possible number of keys.
int init ( )

Initializes NVStore component.

Returns
NVSTORE_SUCCESS Initialization completed successfully. NVSTORE_READ_ERROR Physical error reading data. NVSTORE_WRITE_ERROR Physical error writing data (on recovery). NVSTORE_FLASH_AREA_TOO_SMALL Not enough space in Flash area.
int remove ( uint16_t  key)

Remove an item from flash.

Parameters
[in]keyKey of stored item.
Returns
NVSTORE_SUCCESS Value was successfully written on Flash. NVSTORE_WRITE_ERROR Physical error writing data. NVSTORE_BAD_VALUE Bad value in any of the parameters. NVSTORE_FLASH_AREA_TOO_SMALL Not enough space in Flash area.
int reset ( )

Reset Flash NVStore areas.

Warning: This function is not thread safe and should not be called concurrently with other NVStore functions.

Returns
NVSTORE_SUCCESS Reset completed successfully. NVSTORE_READ_ERROR Physical error reading data. NVSTORE_WRITE_ERROR Physical error writing data.
int set ( uint16_t  key,
uint16_t  buf_size,
const void *  buf 
)

Programs one item of data on Flash, given key.

Parameters
[in]keyKey of stored item.
[in]buf_sizeItem size in bytes.
[in]bufBuffer containing data.
Returns
NVSTORE_SUCCESS Value was successfully written on Flash. NVSTORE_WRITE_ERROR Physical error writing data. NVSTORE_BAD_VALUE Bad value in any of the parameters. NVSTORE_FLASH_AREA_TOO_SMALL Not enough space in Flash area. NVSTORE_ALREADY_EXISTS Item set with write once API already exists.
void set_max_keys ( uint16_t  num_keys)

Set number of keys.

Returns
None.
int set_once ( uint16_t  key,
uint16_t  buf_size,
const void *  buf 
)

Programs one item of data on Flash, given key, allowing no consequent sets to this key.

Parameters
[in]keyKey of stored item.
[in]buf_sizeItem size in bytes.
[in]bufBuffer containing data.
Returns
NVSTORE_SUCCESS Value was successfully written on Flash. NVSTORE_WRITE_ERROR Physical error writing data. NVSTORE_BAD_VALUE Bad value in any of the parameters. NVSTORE_FLASH_AREA_TOO_SMALL Not enough space in Flash area. NVSTORE_ALREADY_EXISTS Item set with write once API already exists.
size_t size ( )

Return NVStore size (area size).

Returns
NVStore size.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.