![]() |
Morse Micro IoT SDK
2.9.7
|
This API provides functionality for managing configuration data in a key/value store with a flash backend.
Data Structures | |
| struct | mmconfig_update_node |
| Update node structure. More... | |
Macros | |
| #define | MMCONFIG_MAX_KEYLEN 32 |
| The maximum length of a key in bytes. More... | |
Enumerations | |
| enum | mmconfig_result { MMCONFIG_OK = 0 , MMCONFIG_DATA_ERASED = 1 , MMCONFIG_ERR_INVALID_KEY = -1 , MMCONFIG_ERR_FULL = -2 , MMCONFIG_ERR_NOT_FOUND = -3 , MMCONFIG_ERR_INCORRECT_TYPE = -4 , MMCONFIG_ERR_INVALID_PARTITION = -5 , MMCONFIG_ERR_INSUFFICIENT_MEMORY = -6 , MMCONFIG_ERR_OUT_OF_BOUNDS = -7 , MMCONFIG_ERR_NOT_SUPPORTED = -8 , MMCONFIG_ERR_WILDCARD_KEY = -9 } |
| Return & error codes. More... | |
Functions | |
| int | mmconfig_eraseall (void) |
| Erases all flash blocks allocated to persistent storage and write the signature at the 2 copies in flash. More... | |
| int | mmconfig_write_data (const char *key, const void *data, size_t size) |
| Writes the raw data to persistent store location identified by key. More... | |
| static int | mmconfig_delete_key (const char *key) |
| Deletes the specified key(s) from persistent store. More... | |
| int | mmconfig_write_update_node_list (const struct mmconfig_update_node *node_list) |
| Writes all updates from the update node list to persistent store. More... | |
| int | mmconfig_write_string (const char *key, const char *value) |
| Writes the null terminated string to persistent store location identified by key. More... | |
| int | mmconfig_read_string (const char *key, char *buffer, int bufsize) |
| Returns the persistent store string value identified by the key. More... | |
| int | mmconfig_alloc_and_load (const char *key, void **data) |
| Allocates memory and loads the data from persistent memory into it returning a pointer. More... | |
| int | mmconfig_write_int (const char *key, int value) |
| Converts the given integer to a string and writes to persistent store. More... | |
| int | mmconfig_read_int (const char *key, int *value) |
| Returns the integer stored in persistent store identified by the key. More... | |
| int | mmconfig_write_uint32 (const char *key, uint32_t value) |
| Converts the given unsigned integer to a string and writes to persistent store. More... | |
| int | mmconfig_read_uint32 (const char *key, uint32_t *value) |
| Returns the unsigned integer stored in persistent store identified by the key. More... | |
| int | mmconfig_write_bool (const char *key, bool value) |
| Converts the given boolean to a string and writes to persistent store. More... | |
| int | mmconfig_read_bool (const char *key, bool *value) |
| Returns the boolean value stored in persistent store identified by the key. More... | |
| int | mmconfig_read_bytes (const char *key, void *buffer, uint32_t buffsize, uint32_t offset) |
| Returns the persistent store data identified by the key. More... | |
| int | mmconfig_validate_key (const char *key) |
| Validates an entire key intended for data storage. More... | |
| int | mmconfig_validate_key_character (char character) |
| Validates a single character intended to make up a key for data storage. More... | |
| int | mmconfig_check_usage (const struct mmconfig_update_node *node_list, uint32_t *bytes_used, int32_t *bytes_remaining) |
| Calculates the number of bytes that would be needed to write the given updates (if not NULL) and the number of bytes that would remain free in the persistent store afterwards. More... | |
| void | load_mmwlan_settings (void) |
Loads and applies any other mmwlan settings specified in config store. More... | |
| #define MMCONFIG_MAX_KEYLEN 32 |
The maximum length of a key in bytes.
Definition at line 216 of file mmconfig.h.
| enum mmconfig_result |
Return & error codes.
Definition at line 219 of file mmconfig.h.
| void load_mmwlan_settings | ( | void | ) |
Loads and applies any other mmwlan settings specified in config store.
Specifically looks for wlan.subbands_enabled, wlan.sgi_enabled, wlan.ampdu_enabled, wlan.fragment_threshold and wlan.rts_threshold.
| int mmconfig_alloc_and_load | ( | const char * | key, |
| void ** | data | ||
| ) |
Allocates memory and loads the data from persistent memory into it returning a pointer.
It is the responsibility of the caller to free the memory when it is no longer required.
| key | Identifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. Must be a null terminated string. |
| data | Returns a pointer to allocated memory loaded with the key value. Returns NULL on any error. |
MMCONFIG_ERR_INVALID_KEY if key is invalid MMCONFIG_ERR_NOT_FOUND if the specified key was not found MMCONFIG_ERR_INSUFFICIENT_MEMORY if memory could not be allocated Other negative number for other errors. | int mmconfig_check_usage | ( | const struct mmconfig_update_node * | node_list, |
| uint32_t * | bytes_used, | ||
| int32_t * | bytes_remaining | ||
| ) |
Calculates the number of bytes that would be needed to write the given updates (if not NULL) and the number of bytes that would remain free in the persistent store afterwards.
| node_list | Pointer to a linked list of nodes to be sized. May be NULL if there is nothing to store |
| bytes_used | Pointer for the size of current data plus node_list |
| bytes_remaining | Pointer for the number of bytes that would remain free if node_list was stored. May be negative if insufficient storage is available. |
MMCONFIG_OK on success. On error returns: MMCONFIG_ERR_NOT_SUPPORTED if there is no persistent store
|
inlinestatic |
Deletes the specified key(s) from persistent store.
| key | Identifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. For deletion a wildcard (*) may be specified at the end to delete multiple keys in one go. Must be a null terminated string. |
MMCONFIG_OK on success. On error returns: MMCONFIG_ERR_INVALID_KEY if key is invalid MMCONFIG_ERR_FULL if insufficient space to write data Other negative number for other errors. Definition at line 299 of file mmconfig.h.
| int mmconfig_eraseall | ( | void | ) |
Erases all flash blocks allocated to persistent storage and write the signature at the 2 copies in flash.
| int mmconfig_read_bool | ( | const char * | key, |
| bool * | value | ||
| ) |
Returns the boolean value stored in persistent store identified by the key.
| key | Identifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. Must be a null terminated string. |
| value | Returns the boolean value stored, it is converted from string but may even be a single byte raw boolean value. The string representation may be "true"/"false" or a "0"/non zero integer string. On error, the value is untouched, so can be preloaded with a default. |
MMCONFIG_OK on success. On error returns: MMCONFIG_ERR_INVALID_KEY if key is invalid MMCONFIG_ERR_NOT_FOUND if the specified key was not found MMCONFIG_ERR_INCORRECT_TYPE if the data pointed to by the key is not an integer represented as a string | int mmconfig_read_bytes | ( | const char * | key, |
| void * | buffer, | ||
| uint32_t | buffsize, | ||
| uint32_t | offset | ||
| ) |
Returns the persistent store data identified by the key.
| key | Identifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. Must be a null terminated string. |
| buffer | A pointer to a pre-allocated buffer to return the data address in. |
| buffsize | The length of the buffer. |
| offset | An offset into the source from which to copy the data into the buffer. |
MMCONFIG_ERR_INVALID_KEY if key is invalid MMCONFIG_ERR_NOT_FOUND if the specified key was not found MMCONFIG_ERR_OUT_OF_BOUNDS if the offset is out of bounds Other negative number for other errors. | int mmconfig_read_int | ( | const char * | key, |
| int * | value | ||
| ) |
Returns the integer stored in persistent store identified by the key.
| key | Identifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. Must be a null terminated string. |
| value | Returns the integer in this, it is converted from string. On error, the value is untouched, so can be preloaded with a default. |
MMCONFIG_OK on success. On error returns: MMCONFIG_ERR_INVALID_KEY if key is invalid MMCONFIG_ERR_NOT_FOUND if the specified key was not found MMCONFIG_ERR_INCORRECT_TYPE if the data pointed to by the key is not an integer represented as a string | int mmconfig_read_string | ( | const char * | key, |
| char * | buffer, | ||
| int | bufsize | ||
| ) |
Returns the persistent store string value identified by the key.
mmconfig_read_string() to read data written by mmconfig_write_data() then it could fail if the data is not null terminated.| key | Identifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. Must be a null terminated string. |
| buffer | Buffer to read the string into. On error, the buffer is untouched, so can be preloaded with a default value. |
| bufsize | Length of buffer. |
MMCONFIG_ERR_INVALID_KEY if key is invalid MMCONFIG_ERR_NOT_FOUND if the specified key was not found MMCONFIG_ERR_INCORRECT_TYPE if the data pointed to by the key is not a null terminated string MMCONFIG_ERR_INSUFFICIENT_MEMORY if the buffer size is insufficient Other negative number for other errors. | int mmconfig_read_uint32 | ( | const char * | key, |
| uint32_t * | value | ||
| ) |
Returns the unsigned integer stored in persistent store identified by the key.
| key | Identifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. Must be a null terminated string. |
| value | Returns the unsigned integer in this, it is converted from string. On error, the value is untouched, so can be preloaded with a default. |
MMCONFIG_OK on success. On error returns: MMCONFIG_ERR_INVALID_KEY if key is invalid MMCONFIG_ERR_NOT_FOUND if the specified key was not found MMCONFIG_ERR_INCORRECT_TYPE if the data pointed to by the key is not an unsigned integer or hexadecimal number represented as a string | int mmconfig_validate_key | ( | const char * | key | ) |
Validates an entire key intended for data storage.
| key | The key to validate |
MMCONFIG_OK if the key is valid, or MMCONFIG_ERR_INVALID_KEY if key is invalid | int mmconfig_validate_key_character | ( | char | character | ) |
Validates a single character intended to make up a key for data storage.
| character | The character to validate |
MMCONFIG_OK if the character is valid, or MMCONFIG_ERR_INVALID_KEY if character is invalid| int mmconfig_write_bool | ( | const char * | key, |
| bool | value | ||
| ) |
Converts the given boolean to a string and writes to persistent store.
If there is already data with the same key then it will be replaced.
| key | Identifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. Must be a null terminated string. |
| value | The boolean value to be written, it is converted to string and written. |
MMCONFIG_OK on success. On error returns: MMCONFIG_ERR_INVALID_KEY if key is invalid Other negative number for other errors. | int mmconfig_write_data | ( | const char * | key, |
| const void * | data, | ||
| size_t | size | ||
| ) |
Writes the raw data to persistent store location identified by key.
If there is already data with the same key (ignoring case) then it will be replaced.
| key | Identifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. Must be a null terminated string. |
| data | The binary data to be written, can contain nulls and need not be null terminated. Can be a pointer to a structure or any arbitrary data to be written. |
| size | The size of the binary data to be written. |
MMCONFIG_OK on success. On error returns: MMCONFIG_ERR_INVALID_KEY if key is invalid MMCONFIG_ERR_FULL if insufficient space to write data Other negative number for other errors. | int mmconfig_write_int | ( | const char * | key, |
| int | value | ||
| ) |
Converts the given integer to a string and writes to persistent store.
If there is already data with the same key then it will be replaced.
| key | Identifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. Must be a null terminated string. |
| value | The integer to be written, it is converted to string and written. |
MMCONFIG_OK on success. On error returns: MMCONFIG_ERR_INVALID_KEY if key is invalid Other negative number for other errors. | int mmconfig_write_string | ( | const char * | key, |
| const char * | value | ||
| ) |
Writes the null terminated string to persistent store location identified by key.
If there is already data with the same key (ignoring case) then it will be replaced.
| key | Identifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. Must be a null terminated string. |
| value | The data to be written, must be a null terminated string. |
MMCONFIG_OK on success. On error returns: MMCONFIG_ERR_INVALID_KEY if key is invalid MMCONFIG_ERR_FULL if insufficient space to write data Other negative number for other errors. | int mmconfig_write_uint32 | ( | const char * | key, |
| uint32_t | value | ||
| ) |
Converts the given unsigned integer to a string and writes to persistent store.
If there is already data with the same key then it will be replaced.
| key | Identifies the data element in persistent storage and is a case insensitive alphanumeric (plus underscore) string starting with an alpha. Same rules as a C variable name, but case insensitive. Must be a null terminated string. |
| value | The unsigned integer to be written, it is converted to string and written. |
MMCONFIG_OK on success. On error returns: MMCONFIG_ERR_INVALID_KEY if key is invalid Other negative number for other errors. | int mmconfig_write_update_node_list | ( | const struct mmconfig_update_node * | node_list | ) |
Writes all updates from the update node list to persistent store.
If there is already data with the same key (ignoring case) then it will be replaced. If data is NULL then it will be deleted.
| node_list | Pointer to a linked list of nodes to be included in the update. |
MMCONFIG_OK on success. On error, no update takes place and the return code is: MMCONFIG_ERR_INVALID_KEY if a key in the list is invalid MMCONFIG_ERR_FULL if insufficient space to write data Other negative number for other errors.