takashi kadono / Mbed OS Nucleo_446

Dependencies:   ssd1331

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 allocate_key (uint16_t &key, uint8_t owner=NVSTORE_UNSPECIFIED_OWNER)
 Allocate a free key (to be used later in a set operation).
int free_all_keys_by_owner (uint8_t owner)
 Free all allocated keys that belong to a specific owner.
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 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.

Definition at line 722 of file nvstore.cpp.

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 941 of file nvstore.cpp.

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.

Definition at line 753 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 632 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 983 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 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.

Definition at line 637 of file nvstore.cpp.

uint16_t get_max_keys (  ) const

Returns number of keys.

Returns:
Number of keys.

Definition at line 155 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 160 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 790 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 785 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 960 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 712 of file nvstore.cpp.

void set_max_keys ( uint16_t  num_keys )

Set number of keys.

Returns:
None.

Definition at line 171 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 717 of file nvstore.cpp.

size_t size (  )

Return NVStore size (area size).

Returns:
NVStore size.

Definition at line 999 of file nvstore.cpp.