nRF5 SDK for Mesh v5.0.0
mesh_config_entry.h
1 /* Copyright (c) 2010 - 2020, Nordic Semiconductor ASA
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form, except as embedded into a Nordic
11  * Semiconductor ASA integrated circuit in a product or a software update for
12  * such product, must reproduce the above copyright notice, this list of
13  * conditions and the following disclaimer in the documentation and/or other
14  * materials provided with the distribution.
15  *
16  * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
17  * contributors may be used to endorse or promote products derived from this
18  * software without specific prior written permission.
19  *
20  * 4. This software, with or without modification, must only be used with a
21  * Nordic Semiconductor ASA integrated circuit.
22  *
23  * 5. Any software provided in binary form under this license must not be reverse
24  * engineered, decompiled, modified and/or disassembled.
25  *
26  * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
27  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28  * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
29  * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
30  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
32  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
35  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 #ifndef MESH_CONFIG_ENTRY_H__
38 #define MESH_CONFIG_ENTRY_H__
39 
40 #include <stdint.h>
41 #include <stdbool.h>
42 
43 #include "nrf_mesh_assert.h"
44 #include "nrf_mesh_section.h"
45 #include "nrf_error.h"
46 #include "mesh_config_backend_file.h"
47 #include "nordic_common.h"
48 
65 #define MESH_CONFIG_ENTRY_ID(FILE, RECORD) (const mesh_config_entry_id_t) {(FILE), (RECORD)}
66 
67 #define MESH_CONFIG_ENTRY_MAX_SIZE 64
68 /*****************************************************************************
69  * State owner interface
70  *****************************************************************************/
80 #define MESH_CONFIG_FILE(NAME, FILE_ID, STRATEGY) \
81  static mesh_config_backend_file_t CONCAT_2(NAME, _backend_data); \
82  NRF_MESH_SECTION_ITEM_REGISTER_FLASH(mesh_config_files, const mesh_config_file_params_t NAME) = \
83  {.id = FILE_ID, .strategy = STRATEGY, .p_backend_data = &CONCAT_2(NAME, _backend_data)}
84 
103 #define MESH_CONFIG_ENTRY(NAME, ID, MAX_COUNT, ENTRY_SIZE, SET_CB, GET_CB, DELETE_CB, HAS_DEFAULT_VALUE) \
104  NRF_MESH_STATIC_ASSERT((ENTRY_SIZE) <= MESH_CONFIG_ENTRY_MAX_SIZE); \
105  NRF_MESH_STATIC_ASSERT((MAX_COUNT) > 0); \
106  static mesh_config_entry_flags_t m_##NAME##_state[MAX_COUNT]; \
107  NRF_MESH_SECTION_ITEM_REGISTER_FLASH(mesh_config_entries, \
108  const mesh_config_entry_params_t m_##NAME##_params) = \
109  {.p_id = &(ID), \
110  .entry_size = ENTRY_SIZE, \
111  .has_default = HAS_DEFAULT_VALUE, \
112  .max_count = MAX_COUNT, \
113  .callbacks = {SET_CB, GET_CB, DELETE_CB}, \
114  .p_state = m_##NAME##_state}
115 
123 #define MESH_CONFIG_ENTRY_API_DEFINE(NAME, ID, DATA_TYPE) \
124  uint32_t NAME##_set(const DATA_TYPE * p_entry) \
125  { \
126  return mesh_config_entry_set((ID), p_entry); \
127  } \
128  uint32_t NAME##_get(DATA_TYPE * p_entry) \
129  { \
130  return mesh_config_entry_get((ID), p_entry); \
131  } \
132  uint32_t NAME##_delete(void) \
133  { \
134  return mesh_config_entry_delete((ID)); \
135  }
136 
147 #define MESH_CONFIG_ENTRY_ARRAY_WRAPPER_DECLARE(NAME, ID, DATA_TYPE, INDEX_TYPE, MAX_COUNT) \
148  uint32_t NAME##_set(INDEX_TYPE index, const DATA_TYPE * p_entry) \
149  { \
150  if (index >= (MAX_COUNT)) return NRF_ERROR_INVALID_PARAM; \
151  mesh_config_entry_id_t id = ID; \
152  id.record += (uint16_t) index; \
153  return mesh_config_entry_set(id, p_entry); \
154  } \
155  uint32_t NAME##_get(INDEX_TYPE index, DATA_TYPE * p_entry) \
156  { \
157  if (index >= (MAX_COUNT)) return NRF_ERROR_INVALID_PARAM; \
158  mesh_config_entry_id_t id = ID; \
159  id.record += (uint16_t) index; \
160  return mesh_config_entry_get(id, p_entry); \
161  } \
162  uint32_t NAME##_delete(INDEX_TYPE index) \
163  { \
164  if (index >= (MAX_COUNT)) return NRF_ERROR_INVALID_PARAM; \
165  mesh_config_entry_id_t id = ID; \
166  id.record += (uint16_t) index; \
167  return mesh_config_entry_delete(id); \
168  }
169 
173 typedef struct
174 {
175  uint16_t file;
176  uint16_t record;
178 
184 typedef enum
185 {
190 
204 typedef uint32_t (*mesh_config_entry_set_t)(mesh_config_entry_id_t id, const void * p_entry);
205 
215 typedef void (*mesh_config_entry_get_t)(mesh_config_entry_id_t id, void * p_entry);
216 
226 
232 typedef struct
233 {
234  uint16_t id;
236  mesh_config_backend_file_t * p_backend_data;
238 
240 typedef enum
241 {
246 
248 typedef struct
249 {
253  uint16_t entry_size;
254  uint16_t max_count;
255  bool has_default;
256  struct
257  {
261  } callbacks;
264 
267 /*****************************************************************************
268 * User interface
269 *****************************************************************************/
280 bool mesh_config_entry_available_id(mesh_config_entry_id_t * p_id);
281 
299 uint32_t mesh_config_entry_set(mesh_config_entry_id_t id, const void * p_entry);
300 
316 uint32_t mesh_config_entry_get(mesh_config_entry_id_t id, void * p_entry);
317 
332 uint32_t mesh_config_entry_delete(mesh_config_entry_id_t id);
333 
336 #endif /* MESH_CONFIG_ENTRY_H__ */
mesh_config_entry_flags_t * p_state
Array of states for each entry.
mesh_config_strategy_t strategy
Storage strategy.
void(* mesh_config_entry_delete_t)(mesh_config_entry_id_t id)
State owner entry delete callback.
bool has_default
Whether the entry has a default value or not.
Mesh config entry identifier.
mesh_config_backend_file_t * p_backend_data
Pointer to backend data associated with the file.
Mesh config entry parameters.
The entry is set to a valid value.
Not stored persistently.
uint32_t(* mesh_config_entry_set_t)(mesh_config_entry_id_t id, const void *p_entry)
State owner entry setter callback.
uint16_t entry_size
Size of each entry.
mesh_config_entry_flags_t
Entry state.
uint16_t max_count
Max number of entries in the set.
File parameters for a mesh config file.
Stored as soon as possible after each change.
The backend is currently processing the entry.
mesh_config_strategy_t
Mesh config entry storage strategy.
Stored when device is about to power down.
void(* mesh_config_entry_get_t)(mesh_config_entry_id_t id, void *p_entry)
State owner entry getter callback.
const mesh_config_entry_id_t * p_id
Base-ID for this entry set.
The backend and frontend representation of the entry is not in sync.

Documentation feedback | Developer Zone | Subscribe | Updated