nRF5 SDK for Mesh v2.2.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, 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  .p_default = DEFAULT_VALUE, \
112  .max_count = MAX_COUNT, \
113  .callbacks = {SET_CB, GET_CB, DELETE_CB}, \
114  .p_state = m_##NAME##_state}
115 
137 #define MESH_CONFIG_ENTRY_IMPLEMENTATION(NAME, ID, MAX_COUNT, DATA_TYPE, ENTRY_SANITATION, DEFAULT_VALUE) \
138  static DATA_TYPE m_##NAME[(MAX_COUNT)]; \
139  static uint32_t NAME##_set(mesh_config_entry_id_t id, const void * p_entry_param) \
140  { \
141  const DATA_TYPE * p_entry = p_entry_param; \
142  bool params_are_valid = (ENTRY_SANITATION); \
143  if (params_are_valid) \
144  { \
145  memcpy(&m_##NAME[id.record - (ID).record], p_entry, sizeof(DATA_TYPE)); \
146  return NRF_SUCCESS; \
147  } \
148  else \
149  { \
150  return NRF_ERROR_INVALID_DATA; \
151  } \
152  } \
153  static void NAME##_get(mesh_config_entry_id_t id, void * p_entry) \
154  { \
155  memcpy(p_entry, &m_##NAME[id.record - (ID).record], sizeof(DATA_TYPE)); \
156  } \
157  MESH_CONFIG_ENTRY(NAME, (ID), (MAX_COUNT), sizeof(DATA_TYPE), NAME##_set, NAME##_get, NULL, DEFAULT_VALUE)
158 
166 #define MESH_CONFIG_ENTRY_API_DEFINE(NAME, ID, DATA_TYPE) \
167  uint32_t NAME##_set(const DATA_TYPE * p_entry) \
168  { \
169  return mesh_config_entry_set((ID), p_entry); \
170  } \
171  uint32_t NAME##_get(DATA_TYPE * p_entry) \
172  { \
173  return mesh_config_entry_get((ID), p_entry); \
174  } \
175  uint32_t NAME##_delete(void) \
176  { \
177  return mesh_config_entry_delete((ID)); \
178  }
179 
190 #define MESH_CONFIG_ENTRY_ARRAY_WRAPPER_DECLARE(NAME, ID, DATA_TYPE, INDEX_TYPE, MAX_COUNT) \
191  uint32_t NAME##_set(INDEX_TYPE index, const DATA_TYPE * p_entry) \
192  { \
193  if (index >= (MAX_COUNT)) return NRF_ERROR_INVALID_PARAM; \
194  mesh_config_entry_id_t id = ID; \
195  id.record += (uint16_t) index; \
196  return mesh_config_entry_set(id, p_entry); \
197  } \
198  uint32_t NAME##_get(INDEX_TYPE index, DATA_TYPE * p_entry) \
199  { \
200  if (index >= (MAX_COUNT)) return NRF_ERROR_INVALID_PARAM; \
201  mesh_config_entry_id_t id = ID; \
202  id.record += (uint16_t) index; \
203  return mesh_config_entry_get(id, p_entry); \
204  } \
205  uint32_t NAME##_delete(INDEX_TYPE index) \
206  { \
207  if (index >= (MAX_COUNT)) return NRF_ERROR_INVALID_PARAM; \
208  mesh_config_entry_id_t id = ID; \
209  id.record += (uint16_t) index; \
210  return mesh_config_entry_delete(id); \
211  }
212 
216 typedef struct
217 {
218  uint16_t file;
219  uint16_t record;
221 
227 typedef enum
228 {
233 
247 typedef uint32_t (*mesh_config_entry_set_t)(mesh_config_entry_id_t id, const void * p_entry);
248 
258 typedef void (*mesh_config_entry_get_t)(mesh_config_entry_id_t id, void * p_entry);
259 
269 
275 typedef struct
276 {
277  uint16_t id;
279  mesh_config_backend_file_t * p_backend_data;
281 
283 typedef enum
284 {
289 
291 typedef struct
292 {
296  uint16_t entry_size;
297  uint16_t max_count;
298  const void * p_default;
299  struct
300  {
304  } callbacks;
307 
310 /*****************************************************************************
311 * User interface
312 *****************************************************************************/
323 bool mesh_config_entry_available_id(mesh_config_entry_id_t * p_id);
324 
342 uint32_t mesh_config_entry_set(mesh_config_entry_id_t id, const void * p_entry);
343 
359 uint32_t mesh_config_entry_get(mesh_config_entry_id_t id, void * p_entry);
360 
375 uint32_t mesh_config_entry_delete(mesh_config_entry_id_t id);
376 
379 #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.
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.
const void * p_default
Pointer to a default value for the entry.
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