17 #ifndef MBED_NVSTORE_H 18 #define MBED_NVSTORE_H 22 #undef NVSTORE_ENABLED 23 #define NVSTORE_ENABLED 0 26 #if (NVSTORE_ENABLED) || defined(DOXYGEN_ONLY) 29 #include "platform/NonCopyable.h" 30 #include "PlatformMutex.h" 35 NVSTORE_READ_ERROR = -1,
36 NVSTORE_WRITE_ERROR = -2,
37 NVSTORE_NOT_FOUND = -3,
38 NVSTORE_DATA_CORRUPT = -4,
39 NVSTORE_BAD_VALUE = -5,
40 NVSTORE_BUFF_TOO_SMALL = -6,
41 NVSTORE_FLASH_AREA_TOO_SMALL = -7,
42 NVSTORE_OS_ERROR = -8,
43 NVSTORE_ALREADY_EXISTS = -9,
44 NVSTORE_NO_FREE_KEY = -10,
48 NVSTORE_FIRST_PREDEFINED_KEY = 0,
52 NVSTORE_DEVICEKEY_KEY = 4,
54 NVSTORE_LAST_PREDEFINED_KEY = 15,
55 NVSTORE_NUM_PREDEFINED_KEYS
56 } nvstore_predefined_keys_e;
59 NVSTORE_UNSPECIFIED_OWNER = 0,
61 NVSTORE_MAX_OWNERS = 16
64 #ifndef NVSTORE_MAX_KEYS 65 #define NVSTORE_MAX_KEYS ((uint16_t)NVSTORE_NUM_PREDEFINED_KEYS) 69 #define NVSTORE_NUM_AREAS 2 135 int get(uint16_t key, uint16_t buf_size,
void *buf, uint16_t &actual_size);
167 int set(uint16_t key, uint16_t buf_size,
const void *buf);
179 int allocate_key(uint16_t &key, uint8_t owner = NVSTORE_UNSPECIFIED_OWNER);
208 int set_once(uint16_t key, uint16_t buf_size,
const void *buf);
223 int remove(uint16_t key);
279 } nvstore_area_data_t;
282 uint32_t _init_attempts;
283 uint8_t _active_area;
285 uint16_t _active_area_version;
286 uint32_t _free_space_offset;
289 uint32_t *_offset_by_key;
290 nvstore_area_data_t _flash_area_params[NVSTORE_NUM_AREAS];
291 static nvstore_area_data_t initial_area_params[NVSTORE_NUM_AREAS];
293 uint32_t _min_prog_size;
310 int flash_read_area(uint8_t area, uint32_t offset, uint32_t size,
void *buf);
322 int flash_write_area(uint8_t area, uint32_t offset, uint32_t size,
const void *buf);
331 int flash_erase_area(uint8_t area);
337 void calc_validate_area_params();
347 int calc_empty_space(uint8_t area, uint32_t &offset);
366 int read_record(uint8_t area, uint32_t offset, uint16_t buf_size,
void *buf,
367 uint16_t &actual_size,
int validate_only,
int &valid,
368 uint16_t &key, uint16_t &flags, uint8_t &owner, uint32_t &next_offset);
384 int write_record(uint8_t area, uint32_t offset, uint16_t key, uint16_t flags, uint8_t owner,
385 uint32_t data_size,
const void *data_buf, uint32_t &next_offset);
396 int write_master_record(uint8_t area, uint16_t version, uint32_t &next_offset);
408 int copy_record(uint8_t from_area, uint32_t from_offset, uint32_t to_offset,
409 uint32_t &next_offset);
424 int garbage_collection(uint16_t key, uint16_t flags, uint8_t owner, uint16_t buf_size,
const void *buf, uint16_t num_keys);
437 int do_get(uint16_t key, uint16_t buf_size,
void *buf, uint16_t &actual_size,
450 int do_set(uint16_t key, uint16_t buf_size,
const void *buf, uint16_t flags);
455 #endif // NVSTORE_ENABLED 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...
uint16_t get_max_keys() const
Returns number of keys.
void set_max_keys(uint16_t num_keys)
Set number of keys.
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.
uint16_t get_max_possible_keys()
Return maximal possible number of keys (in this flash configuration).
int get_area_params(uint8_t area, uint32_t &address, size_t &size)
Return address and size of an NVStore area.
Prevents generation of copy constructor and copy assignment operator in derived classes.
size_t size()
Return NVStore size (area size).
int deinit()
Deinitializes NVStore component.
int reset()
Reset Flash NVStore areas.
int get_item_size(uint16_t key, uint16_t &actual_size)
Returns size of the data programmed on Flash, given key.
static NVStore & get_instance()
As a singleton, return the single instance of the class.
int init()
Initializes NVStore component.