37 #ifndef MESH_CONFIG_ENTRY_H__ 38 #define MESH_CONFIG_ENTRY_H__ 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" 65 #define MESH_CONFIG_ENTRY_ID(FILE, RECORD) (const mesh_config_entry_id_t) {(FILE), (RECORD)} 67 #define MESH_CONFIG_ENTRY_MAX_SIZE 64 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)} 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) = \ 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} 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) \ 142 const DATA_TYPE * p_entry = p_entry_param; \ 143 bool params_are_valid = (ENTRY_SANITATION); \ 144 if (params_are_valid) \ 146 memcpy(&m_##NAME[id.record - (ID).record], p_entry, sizeof(DATA_TYPE)); \ 147 return NRF_SUCCESS; \ 151 return NRF_ERROR_INVALID_DATA; \ 154 static void NAME##_get(mesh_config_entry_id_t id, void * p_entry) \ 156 memcpy(p_entry, &m_##NAME[id.record - (ID).record], sizeof(DATA_TYPE)); \ 158 MESH_CONFIG_ENTRY(NAME, (ID), (MAX_COUNT), sizeof(DATA_TYPE), NAME##_set, NAME##_get, NULL, HAS_DEFAULT_VALUE) 167 #define MESH_CONFIG_ENTRY_API_DEFINE(NAME, ID, DATA_TYPE) \ 168 uint32_t NAME##_set(const DATA_TYPE * p_entry) \ 170 return mesh_config_entry_set((ID), p_entry); \ 172 uint32_t NAME##_get(DATA_TYPE * p_entry) \ 174 return mesh_config_entry_get((ID), p_entry); \ 176 uint32_t NAME##_delete(void) \ 178 return mesh_config_entry_delete((ID)); \ 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) \ 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); \ 199 uint32_t NAME##_get(INDEX_TYPE index, DATA_TYPE * p_entry) \ 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); \ 206 uint32_t NAME##_delete(INDEX_TYPE index) \ 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); \ 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.
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.