BA / Mbed OS BaBoRo1
Embed: (wiki syntax)

« Back to documentation index

NVStore Class Reference

NVStore class. More...

#include <nvstore.h>

Inherits NonCopyable< NVStore >.

Public Member Functions

uint16_t get_max_keys () const
 Returns number of keys.
void set_max_keys (uint16_t num_keys)
 Set number of keys.
uint16_t get_max_possible_keys ()
 Return maximal possible number of keys (in this flash configuration).
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.
int get_item_size (uint16_t key, uint16_t &actual_size)
 Returns size of the data programmed on Flash, given key.
int set (uint16_t key, uint16_t buf_size, const void *buf)
 Programs one item of data on Flash, given key.
int set_alloc_key (uint16_t &key, uint16_t buf_size, const void *buf)
 Programs one item of data on Flash, allocating a key.
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.
int remove (uint16_t key)
 Remove an item from flash.
int init ()
 Initializes NVStore component.
int deinit ()
 Deinitializes NVStore component.
int reset ()
 Reset Flash NVStore areas.
size_t size ()
 Return NVStore size (area size).
int get_area_params (uint8_t area, uint32_t &address, size_t &size)
 Return address and size of an NVStore area.

Static Public Member Functions

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

Private Member Functions

 MBED_DEPRECATED ("Invalid copy construction of a NonCopyable resource.") NonCopyable(const NonCopyable &)
 NonCopyable copy constructor.
 MBED_DEPRECATED ("Invalid copy assignment of a NonCopyable resource.") NonCopyable &operator
 NonCopyable copy assignment operator.

Detailed Description

NVStore class.

Class for storing data by keys in the internal flash

Definition at line 68 of file nvstore.h.


Member Function Documentation

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.

Definition at line 879 of file nvstore.cpp.

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.

Definition at line 621 of file nvstore.cpp.

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.

Definition at line 921 of file nvstore.cpp.

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 79 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.

Definition at line 626 of file nvstore.cpp.

uint16_t get_max_keys (  ) const

Returns number of keys.

Returns:
Number of keys.

Definition at line 147 of file nvstore.cpp.

uint16_t get_max_possible_keys (  )

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

Returns:
Max possible number of keys.

Definition at line 152 of file nvstore.cpp.

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.

Definition at line 730 of file nvstore.cpp.

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.

Definition at line 725 of file nvstore.cpp.

int reset ( void   )

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.

Definition at line 898 of file nvstore.cpp.

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.

Definition at line 709 of file nvstore.cpp.

int set_alloc_key ( uint16_t &  key,
uint16_t  buf_size,
const void *  buf 
)

Programs one item of data on Flash, allocating a key.

Parameters:
[out]keyReturned key 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. NVSTORE_NO_FREE_KEY Couldn't allocate a key for this call.

Definition at line 719 of file nvstore.cpp.

void set_max_keys ( uint16_t  num_keys )

Set number of keys.

Returns:
None.

Definition at line 163 of file nvstore.cpp.

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.

Definition at line 714 of file nvstore.cpp.

size_t size (  )

Return NVStore size (area size).

Returns:
NVStore size.

Definition at line 937 of file nvstore.cpp.