nRF5 SDK for Mesh v3.1.0
mesh_config_entry.h
1 /* Copyright (c) 2010 - 2018, 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 
138 #define MESH_CONFIG_ENTRY_IMPLEMENTATION(NAME, ID, MAX_COUNT, DATA_TYPE, ENTRY_SANITATION, HAS_DEFAULT_VALUE) \
139  static DATA_TYPE m_##NAME[(MAX_COUNT)]; \
140  static uint32_t NAME##_set(mesh_config_entry_id_t id, const void * p_entry_param) \
141  { \
142  const DATA_TYPE * p_entry = p_entry_param; \
143  bool params_are_valid = (ENTRY_SANITATION); \
144  if (params_are_valid) \
145  { \
146  memcpy(&m_##NAME[id.record - (ID).record], p_entry, sizeof(DATA_TYPE)); \
147  return NRF_SUCCESS; \
148  } \
149  else \
150  { \
151  return NRF_ERROR_INVALID_DATA; \
152  } \
153  } \
154  static void NAME##_get(mesh_config_entry_id_t id, void * p_entry) \
155  { \
156  memcpy(p_entry, &m_##NAME[id.record - (ID).record], sizeof(DATA_TYPE)); \
157  } \
158  MESH_CONFIG_ENTRY(NAME, (ID), (MAX_COUNT), sizeof(DATA_TYPE), NAME##_set, NAME##_get, NULL, HAS_DEFAULT_VALUE)
159 
167 #define MESH_CONFIG_ENTRY_API_DEFINE(NAME, ID, DATA_TYPE) \
168  uint32_t NAME##_set(const DATA_TYPE * p_entry) \
169  { \
170  return mesh_config_entry_set((ID), p_entry); \
171  } \
172  uint32_t NAME##_get(DATA_TYPE * p_entry) \
173  { \
174  return mesh_config_entry_get((ID), p_entry); \
175  } \
176  uint32_t NAME##_delete(void) \
177  { \
178  return mesh_config_entry_delete((ID)); \
179  }
180 
191 #define MESH_CONFIG_ENTRY_ARRAY_WRAPPER_DECLARE(NAME, ID, DATA_TYPE, INDEX_TYPE, MAX_COUNT) \
192  uint32_t NAME##_set(INDEX_TYPE index, const DATA_TYPE * p_entry) \
193  { \
194  if (index >= (MAX_COUNT)) return NRF_ERROR_INVALID_PARAM; \
195  mesh_config_entry_id_t id = ID; \
196  id.record += (uint16_t) index; \
197  return mesh_config_entry_set(id, p_entry); \
198  } \
199  uint32_t NAME##_get(INDEX_TYPE index, DATA_TYPE * p_entry) \
200  { \
201  if (index >= (MAX_COUNT)) return NRF_ERROR_INVALID_PARAM; \
202  mesh_config_entry_id_t id = ID; \
203  id.record += (uint16_t) index; \
204  return mesh_config_entry_get(id, p_entry); \
205  } \
206  uint32_t NAME##_delete(INDEX_TYPE index) \
207  { \
208  if (index >= (MAX_COUNT)) return NRF_ERROR_INVALID_PARAM; \
209  mesh_config_entry_id_t id = ID; \
210  id.record += (uint16_t) index; \
211  return mesh_config_entry_delete(id); \
212  }
213 
217 typedef struct
218 {
219  uint16_t file;
220  uint16_t record;
222 
228 typedef enum
229 {
234 
248 typedef uint32_t (*mesh_config_entry_set_t)(mesh_config_entry_id_t id, const void * p_entry);
249 
259 typedef void (*mesh_config_entry_get_t)(mesh_config_entry_id_t id, void * p_entry);
260 
270 
276 typedef struct
277 {
278  uint16_t id;
280  mesh_config_backend_file_t * p_backend_data;
282 
284 typedef enum
285 {
290 
292 typedef struct
293 {
297  uint16_t entry_size;
298  uint16_t max_count;
299  bool has_default;
300  struct
301  {
305  } callbacks;
308 
311 /*****************************************************************************
312 * User interface
313 *****************************************************************************/
324 bool mesh_config_entry_available_id(mesh_config_entry_id_t * p_id);
325 
343 uint32_t mesh_config_entry_set(mesh_config_entry_id_t id, const void * p_entry);
344 
360 uint32_t mesh_config_entry_get(mesh_config_entry_id_t id, void * p_entry);
361 
376 uint32_t mesh_config_entry_delete(mesh_config_entry_id_t id);
377 
380 #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