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.
Loading...
Searching...
No Matches
meshx_nvs_interface.h
Go to the documentation of this file.
1/**
2 * Copyright © 2024 - 2025 MeshX
3 *
4 * @file meshx_nvs_interface.h
5 * @brief Implementation for Non-Volatile Storage (NVS) drivers Insterface APIs
6 *
7 * @author Pranjal Chanda
8 *
9 */
10
11#ifndef __MESHX_NVS_INTERFACE_H__
12#define __MESHX_NVS_INTERFACE_H__
13
14#include "meshx_err.h"
15#include <stdint.h>
16#include <stddef.h>
17
18/**
19 * @brief Open non-volatile storage with a given namespace from the default partition.
20 *
21 * If CONFIG_BLE_MESH_SPECIFIC_PARTITION is not defined, this function will open the namespace
22 * from the default partition. Otherwise, it will open the namespace from the
23 * MESHX_NVS_PARTITION.
24 *
25 * @param[out] p_nvs_handle Pointer to the output variable populated with the opened handle.
26 *
27 * @return
28 * - MESHX_SUCCESS if the storage handle was opened successfully
29 * - MESHX_ERR_PLAT if p_nvs_handle is NULL
30 */
31meshx_err_t meshx_nvs_plat_open(uintptr_t *p_nvs_handle);
32
33/**
34 * @brief Close the non-volatile storage handle.
35 *
36 * @param[in] p_nvs_handle Handle obtained with meshx_nvs_plat_open.
37 *
38 * @return
39 * - MESHX_SUCCESS if the handle was closed successfully
40 * - MESHX_ERR_PLAT for any platform error
41 */
42meshx_err_t meshx_nvs_plat_close(uintptr_t p_nvs_handle);
43
44/**
45 * @brief Read blob value for given key from non-volatile storage.
46 *
47 * @param[in] p_nvs_handle Handle obtained with meshx_nvs_plat_open.
48 * @param[in] key Key name. Maximum length is (NVS_KEY_NAME_MAX_SIZE-1) characters. Shouldn't be empty.
49 * @param[out] p_data Pointer to the output variable populated with the read blob value.
50 * @param[in] len Length of the read blob value.
51 *
52 * @return
53 * - MESHX_SUCCESS if the blob value was read successfully
54 * - MESHX_ERR_PLAT if there is an internal error;
55 */
56meshx_err_t meshx_nvs_plat_read(uintptr_t p_nvs_handle, char const *key , uint8_t *p_data, uint16_t len);
57
58/**
59 * @brief Write a blob value to the non-volatile storage with a given key and namespace.
60 *
61 * @param[in] p_nvs_handle Pointer to the opened handle.
62 * @param[in] key Key name. Maximum length is (NVS_KEY_NAME_MAX_SIZE-1) characters. Shouldn't be empty.
63 * @param[in] p_data Pointer to the data to write.
64 * @param[in] len Number of bytes to write.
65 *
66 * @return
67 * - MESHX_SUCCESS if the value was written successfully
68 * - MESHX_ERR_PLAT for any platform error
69 */
70meshx_err_t meshx_nvs_plat_write(uintptr_t p_nvs_handle, char const * key, uint8_t const *p_data, uint16_t len);
71
72/**
73 * @brief Erase all key-value pairs in the given namespace.
74 *
75 * @param[in] p_nvs_handle Pointer to the opened handle.
76 *
77 * @return
78 * - MESHX_SUCCESS if all key-value pairs were erased successfully
79 * - MESHX_ERR_PLAT for any platform error
80 */
81meshx_err_t meshx_nvs_plat_erase(uintptr_t p_nvs_handle);
82
83/**
84 * @brief Remove a key-value pair from the non-volatile storage with a given key and namespace.
85 *
86 * @param[in] p_nvs_handle Pointer to the opened handle.
87 * @param[in] key Key name. Maximum length is (NVS_KEY_NAME_MAX_SIZE-1) characters. Shouldn't be empty.
88 *
89 * @return
90 * - MESHX_SUCCESS if the key-value pair was removed successfully
91 * - MESHX_ERR_PLAT for any platform error
92 */
93meshx_err_t meshx_nvs_plat_remove(uintptr_t p_nvs_handle, char const* key);
94
95/**
96 * @brief Commit changes to the non-volatile storage.
97 *
98 * @note This function is a prototype and can be returned with MESHX_SUCCESS if
99 * no such platform function exists
100 *
101 * @param[in] p_nvs_handle Pointer to the opened handle.
102 *
103 * @return
104 * - MESHX_SUCCESS if the changes were committed successfully
105 * - MESHX_ERR_PLAT for any platform error
106 */
107meshx_err_t meshx_nvs_plat_commit(uintptr_t p_nvs_handle);
108
109#endif /* __MESHX_NVS_INTERFACE_H__ */
MeshX Error Codes.
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
meshx_err_t meshx_nvs_plat_read(uintptr_t p_nvs_handle, char const *key, uint8_t *p_data, uint16_t len)
Read blob value for given key from non-volatile storage.
meshx_err_t meshx_nvs_plat_open(uintptr_t *p_nvs_handle)
Open non-volatile storage with a given namespace from the default partition.
meshx_err_t meshx_nvs_plat_write(uintptr_t p_nvs_handle, char const *key, uint8_t const *p_data, uint16_t len)
Write a blob value to the non-volatile storage with a given key and namespace.
meshx_err_t meshx_nvs_plat_commit(uintptr_t p_nvs_handle)
Commit changes to the non-volatile storage.
meshx_err_t meshx_nvs_plat_erase(uintptr_t p_nvs_handle)
Erase all key-value pairs in the given namespace.
meshx_err_t meshx_nvs_plat_remove(uintptr_t p_nvs_handle, char const *key)
Remove a key-value pair from the non-volatile storage with a given key and namespace.
meshx_err_t meshx_nvs_plat_close(uintptr_t p_nvs_handle)
Close the non-volatile storage handle.