Morse Micro IoT SDK  2.12.3
mmconfig.h
1/*
2 * Copyright 2023 Morse Micro
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
207#pragma once
208
209#include <stddef.h>
210#include <stdbool.h>
211#include <stdint.h>
212
213#ifdef __cplusplus
214extern "C"
215{
216#endif
217
219#define MMCONFIG_MAX_KEYLEN 32
220
223{
236
243{
248 const char *key;
249
252 void *data;
253
255 size_t size;
256
259
262};
263
274
287
306int mmconfig_write_data(const char *key, const void *data, size_t size);
307
325static inline int mmconfig_delete_key(const char *key)
326{
327 return mmconfig_write_data(key, NULL, 0);
328}
329
351
367int mmconfig_write_string(const char *key, const char *value);
368
390int mmconfig_read_string(const char *key, char *buffer, int bufsize);
391
409int mmconfig_alloc_and_load(const char *key, void **data);
410
425int mmconfig_write_int(const char *key, int value);
426
442int mmconfig_read_int(const char *key, int *value);
443
458int mmconfig_write_uint32(const char *key, uint32_t value);
459
475int mmconfig_read_uint32(const char *key, uint32_t *value);
476
491int mmconfig_write_bool(const char *key, bool value);
492
510int mmconfig_read_bool(const char *key, bool *value);
511
527int mmconfig_read_bytes(const char *key, void *buffer, uint32_t buffsize, uint32_t offset);
528
539int mmconfig_validate_key(const char *key);
540
554
568int mmconfig_check_usage(const struct mmconfig_update_node *node_list,
569 uint32_t *bytes_used,
570 int32_t *bytes_remaining);
571
572#ifdef __cplusplus
573}
574#endif
575
int mmconfig_write_int(const char *key, int value)
Converts the given integer to a string and writes to persistent store.
static int mmconfig_delete_key(const char *key)
Deletes the specified key(s) from persistent store.
Definition: mmconfig.h:325
enum mmconfig_result mmconfig_check_factory_partition_status(void)
Check the status of the optional factory MMCONFIG partition.
mmconfig_result
Return & error codes.
Definition: mmconfig.h:223
int mmconfig_read_string(const char *key, char *buffer, int bufsize)
Returns the persistent store string value identified by the key.
int mmconfig_read_int(const char *key, int *value)
Returns the integer stored in persistent store identified by the key.
int mmconfig_read_bool(const char *key, bool *value)
Returns the boolean value stored in persistent store identified by the key.
int mmconfig_write_bool(const char *key, bool value)
Converts the given boolean to a string and writes to persistent store.
int mmconfig_write_update_node_list(const struct mmconfig_update_node *node_list)
Writes all updates from the update node list to persistent store.
int mmconfig_eraseall(void)
Erases all flash blocks allocated to persistent storage and write the signature at the 2 copies in fl...
int mmconfig_write_uint32(const char *key, uint32_t value)
Converts the given unsigned integer to a string and writes to persistent store.
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 ...
int mmconfig_write_data(const char *key, const void *data, size_t size)
Writes the raw data to persistent store location identified by key.
int mmconfig_validate_key(const char *key)
Validates an entire key intended for data storage.
int mmconfig_read_bytes(const char *key, void *buffer, uint32_t buffsize, uint32_t offset)
Returns the persistent store data identified by the key.
int mmconfig_write_string(const char *key, const char *value)
Writes the null terminated string to persistent store location identified by key.
int mmconfig_read_uint32(const char *key, uint32_t *value)
Returns the unsigned integer stored in persistent store identified by the key.
int mmconfig_alloc_and_load(const char *key, void **data)
Allocates memory and loads the data from persistent memory into it returning a pointer.
int mmconfig_validate_key_character(char character)
Validates a single character intended to make up a key for data storage.
@ MMCONFIG_ERR_NOT_SUPPORTED
Operation not supported.
Definition: mmconfig.h:233
@ MMCONFIG_ERR_NOT_FOUND
Requested key was not found.
Definition: mmconfig.h:228
@ MMCONFIG_ERR_FULL
Config store is full.
Definition: mmconfig.h:227
@ MMCONFIG_DATA_ERASED
Partition was erased.
Definition: mmconfig.h:225
@ MMCONFIG_ERR_INVALID_KEY
Key provided was invalid.
Definition: mmconfig.h:226
@ MMCONFIG_ERR_OUT_OF_BOUNDS
Offset was out of bounds.
Definition: mmconfig.h:232
@ MMCONFIG_ERR_INSUFFICIENT_MEMORY
Insufficient memory.
Definition: mmconfig.h:231
@ MMCONFIG_ERR_INVALID_PARTITION
Valid partition was not found.
Definition: mmconfig.h:230
@ MMCONFIG_ERR_WILDCARD_KEY
Key contains wildcard valid only for deletion.
Definition: mmconfig.h:234
@ MMCONFIG_OK
Operation completed successfully.
Definition: mmconfig.h:224
@ MMCONFIG_ERR_INCORRECT_TYPE
Requested data type did not match found data.
Definition: mmconfig.h:229
Update node structure.
Definition: mmconfig.h:243
bool data_malloced
Boolean flag to indicate if data is dynamically allocated.
Definition: mmconfig.h:258
size_t size
Size of the data.
Definition: mmconfig.h:255
void * data
Pointer to the data.
Definition: mmconfig.h:252
const char * key
The key, which should be pre-validated using mmconfig_validate_key(), unless it is to be used for mul...
Definition: mmconfig.h:248
struct mmconfig_update_node * next
Pointer to the next node in the list.
Definition: mmconfig.h:261