|
MeshX 0.4
This repository provides an implementation for Bluetooth Low Energy (BLE) Mesh network nodes. The project allows you to create BLE mesh nodes that can communicate with each other, enabling the development of smart home solutions or other IoT-based applications.
|
Implementation for MeshX Non-Volatile Storage (NVS) operations. More...
#include "meshx_nvs.h"#include "unit_test.h"#include "interface/utils/meshx_nvs_interface.h"#include "meshx_control_task.h"#include "interface/utils/meshx_tiny_printf.h"Data Structures | |
| struct | meshx_nvs_write_list |
| Linked list structure used to store key-value pairs that need to be written to NVS. More... | |
Macros | |
| #define | MESHX_NVS_INIT_MAGIC 0x5489 |
| #define | MESHX_NVS_NAMESPACE_PID "MESHX_PID" |
| #define | MESHX_NVS_NAMESPACE_CID "MESHX_CID" |
| #define | MESHX_NVS_TIMER_NAME "MESHX_COMMIT_TIMER" |
| #define | MESHX_NVS_ELEMENT_CTX "MXE_%02x_%04x" |
| #define | MESHX_NVS_RELOAD_ONE_SHOT 0 |
| #define | MESHX_KEY_NAME_MAX_SIZE 16 |
| #define | MESHX_KEY_VALUE_MAX_SIZE 256 |
| #define | MESHX_NVS_UNIT_TEST_KEY "MESHX_UT" |
Typedefs | |
| typedef struct meshx_nvs_write_list | meshx_nvs_write_list_t |
| typedef enum meshx_nvs_cli_cmd | meshx_nvs_cli_cmd_t |
| MeshX NVS unit test command IDs. | |
Enumerations | |
| enum | meshx_nvs_cli_cmd { MESHX_NVS_CLI_CMD_OPEN , MESHX_NVS_CLI_CMD_SET , MESHX_NVS_CLI_CMD_GET , MESHX_NVS_CLI_CMD_COMMIT , MESHX_NVS_CLI_CMD_REMOVE , MESHX_NVS_CLI_CMD_ERASE , MESHX_NVS_CLI_CMD_CLOSE , MESHX_NVS_CLI_MAX } |
| MeshX NVS unit test command IDs. More... | |
Functions | |
| static meshx_err_t | meshx_nvs_unit_test_cb_handler (int cmd_id, int argc, char **argv) |
| Callback handler for MeshX NVS unit test command. | |
| static meshx_err_t | meshx_nvs_control_msg_handler (dev_struct_t *pdev, control_task_msg_evt_t evt, void *params) |
| static void | meshx_nvs_os_timer_cb (const meshx_os_timer_t *p_timer) |
| MeshX NVS Timer callback. | |
| static meshx_err_t | meshx_nvs_erase_prod_init (uint16_t cid, uint16_t pid) |
| Erase the NVS and set the product ID. | |
| meshx_err_t | meshx_nvs_init (void) |
| MeshX NVS Initialisation. | |
| meshx_err_t | meshx_nvs_open (uint16_t cid, uint16_t pid, uint32_t commit_timeout_ms) |
| Open the NVS with a timeout. | |
| meshx_err_t | meshx_nvs_erase (void) |
| Erase all key-value pairs stored in the NVS. | |
| meshx_err_t | meshx_nvs_commit (void) |
| Commit changes to the NVS. | |
| meshx_err_t | meshx_nvs_close (void) |
| Close the NVS handle. | |
| meshx_err_t | meshx_nvs_remove (char const *key) |
| Remove a key-value pair from the NVS. | |
| meshx_err_t | meshx_nvs_get (char const *key, void *blob, uint16_t blob_size) |
| Get a value from the NVS. | |
| meshx_err_t | meshx_nvs_set (char const *key, void const *blob, uint16_t blob_size, bool arm_timer) |
| Set a value in the NVS. | |
| meshx_err_t | meshx_nvs_element_ctx_get (uint16_t element_id, meshx_element_type_t element_type, void *blob, size_t blob_size) |
| Retrieve the context of a specific element from NVS. | |
| meshx_err_t | meshx_nvs_element_ctx_set (uint16_t element_id, meshx_element_type_t element_type, const void *blob, size_t blob_size) |
| Store the context of a specific element to NVS. | |
| meshx_err_t | meshx_nvs_element_ctx_remove (uint16_t element_id, meshx_element_type_t element_type) |
| Remove the context of a specific element from NVS. | |
Variables | |
| meshx_nvs_write_list_t * | meshx_nvs_write_list_head = NULL |
| Head of the linked list used to store key-value pairs that need to be written to NVS. | |
| static meshx_nvs_t | meshx_nvs_inst |
Implementation for MeshX Non-Volatile Storage (NVS) operations.
Copyright © 2024 - 2025 MeshX
This file provides APIs to manage the Non-Volatile Storage (NVS) used in the MeshX system. It includes functions to read, write, erase, and manage key-value pairs stored persistently.
| #define MESHX_KEY_NAME_MAX_SIZE 16 |
| #define MESHX_KEY_VALUE_MAX_SIZE 256 |
| #define MESHX_NVS_ELEMENT_CTX "MXE_%02x_%04x" |
| #define MESHX_NVS_INIT_MAGIC 0x5489 |
| #define MESHX_NVS_NAMESPACE_CID "MESHX_CID" |
| #define MESHX_NVS_NAMESPACE_PID "MESHX_PID" |
| #define MESHX_NVS_RELOAD_ONE_SHOT 0 |
| #define MESHX_NVS_TIMER_NAME "MESHX_COMMIT_TIMER" |
| #define MESHX_NVS_UNIT_TEST_KEY "MESHX_UT" |
| typedef enum meshx_nvs_cli_cmd meshx_nvs_cli_cmd_t |
MeshX NVS unit test command IDs.
| typedef struct meshx_nvs_write_list meshx_nvs_write_list_t |
| enum meshx_nvs_cli_cmd |
MeshX NVS unit test command IDs.
| Enumerator | |
|---|---|
| MESHX_NVS_CLI_CMD_OPEN | |
| MESHX_NVS_CLI_CMD_SET | |
| MESHX_NVS_CLI_CMD_GET | |
| MESHX_NVS_CLI_CMD_COMMIT | |
| MESHX_NVS_CLI_CMD_REMOVE | |
| MESHX_NVS_CLI_CMD_ERASE | |
| MESHX_NVS_CLI_CMD_CLOSE | |
| MESHX_NVS_CLI_MAX | |
| meshx_err_t meshx_nvs_close | ( | void | ) |
Close the NVS handle.
This function releases any resources associated with the NVS handle.
| meshx_err_t meshx_nvs_commit | ( | void | ) |
Commit changes to the NVS.
This function ensures that any pending changes to the NVS are flushed to persistent storage.
|
static |
| meshx_err_t meshx_nvs_element_ctx_get | ( | uint16_t | element_id, |
| meshx_element_type_t | element_type, | ||
| void * | blob, | ||
| size_t | blob_size ) |
Retrieve the context of a specific element from NVS.
| [in] | element_id | The ID of the element whose context is to be retrieved. |
| [in] | element_type | The type of the element. |
| [out] | blob | Pointer to the buffer where the retrieved context will be stored. |
| [in] | blob_size | Size of the buffer provided to store the context. |
| meshx_err_t meshx_nvs_element_ctx_remove | ( | uint16_t | element_id, |
| meshx_element_type_t | element_type ) |
Remove the context of a specific element from NVS.
| [in] | element_id | The ID of the element whose context is to be removed. |
| [in] | element_type | The type of the element. |
| meshx_err_t meshx_nvs_element_ctx_set | ( | uint16_t | element_id, |
| meshx_element_type_t | element_type, | ||
| const void * | blob, | ||
| size_t | blob_size ) |
Store the context of a specific element to NVS.
| [in] | element_id | The ID of the element whose context is to be stored. |
| [in] | element_type | The type of the element. |
| [in] | blob | Pointer to the buffer containing the context to be stored. |
| [in] | blob_size | Size of the buffer containing the context. |
| meshx_err_t meshx_nvs_erase | ( | void | ) |
Erase all key-value pairs stored in the NVS.
This function clears all data stored in the Non-Volatile Storage.
|
static |
Erase the NVS and set the product ID.
This function erases the NVS and sets the product ID.
| [in] | cid | Company ID |
| [in] | pid | Product ID |
| meshx_err_t meshx_nvs_get | ( | char const * | key, |
| void * | blob, | ||
| uint16_t | blob_size ) |
Get a value from the NVS.
This function retrieves a value associated with the given key from the NVS.
| [in] | key | The key identifying the value to be retrieved. |
| [out] | blob | Pointer to the buffer where the value will be stored. |
| [in] | blob_size | Size of the buffer in bytes. |
| meshx_err_t meshx_nvs_init | ( | void | ) |
MeshX NVS Initialisation.
| meshx_err_t meshx_nvs_open | ( | uint16_t | cid, |
| uint16_t | pid, | ||
| uint32_t | commit_timeout_ms ) |
Open the NVS with a timeout.
This function initializes the NVS and sets a timeout for stability operations.
| [in] | cid | Company ID |
| [in] | pid | Product ID |
| [in] | commit_timeout_ms | Timeout for stability operations in milliseconds. |
|
static |
MeshX NVS Timer callback.
| [in] | p_timer | meshx_os_timer param pointer * |
| meshx_err_t meshx_nvs_remove | ( | char const * | key | ) |
Remove a key-value pair from the NVS.
This function deletes a specific key-value pair from the NVS based on the provided key.
| [in] | key | The key identifying the value to be removed. |
| meshx_err_t meshx_nvs_set | ( | char const * | key, |
| void const * | blob, | ||
| uint16_t | blob_size, | ||
| bool | arm_timer ) |
Set a value in the NVS.
This function stores a value associated with the given key in the NVS.
| [in] | key | The key identifying the value to be stored. |
| [in] | blob | Pointer to the buffer containing the value. |
| [in] | blob_size | Size of the buffer in bytes. |
| [in] | arm_timer | Re-arm stability timer and auto commit |
|
static |
Callback handler for MeshX NVS unit test command.
This function handles MeshX NVS unit test command by processing the provided command ID and arguments.
| [in] | cmd_id | The command ID to be processed. |
| [in] | argc | The number of arguments provided. |
| [in] | argv | The array of arguments. |
|
static |
| meshx_nvs_write_list_t* meshx_nvs_write_list_head = NULL |
Head of the linked list used to store key-value pairs that need to be written to NVS.