this file formats plugin data for saving to non-volatile space. More...
#include "tr_af.h"Go to the source code of this file.
Data Structures | |
| struct | tr_nvram_section_header_t |
| struct for the section header that starts each data section More... | |
| struct | tr_nvram_data_info_t |
| struct that a plugin fills in to have its plugin data saved More... | |
Macros | |
| #define | TR_NVRAM_STORAGE_VER_1 (1) |
| #define | TR_NVRAM_STORAGE_VER_2 (2) |
| #define | TR_NVRAM_WRITE_DELAY_MS (2000) |
| #define | TR_NVRAM_ATTR_STORAGE_VER_1 (1) |
| #define | TR_NVRAM_ATTR_STORAGE_CUR_VER (TR_NVRAM_ATTR_STORAGE_VER_1) |
| #define | TR_NVRAM_SECTION_ID_ZIGBEE_ATTRS 0x8001 |
| #define | tr_nvram_printf(...) |
| #define | tr_nvram_verbose_printf(...) |
| #define | TR_NVRAM_SCENES_SLOTS 0 |
| this defines the number of slots available for plugins to register to save their data | |
| #define | TR_NVRAM_DOOR_LOCK_SLOTS 0 |
| #define | TR_NVRAM_NUM_APP_SECTIONS 1 |
| #define | TR_NVRAM_NUM_TABLE_SLOTS (TR_NVRAM_NUM_APP_SECTIONS + TR_NVRAM_DOOR_LOCK_SLOTS + TR_NVRAM_SCENES_SLOTS) |
Typedefs | |
| struct { | |
| zb_uint8_t endpoint | |
| zb_uint16_t cluster_id | |
| zb_uint16_t attr_id | |
| zb_uint8_t cluster_role | |
| zb_uint16_t manuf_code | |
| zb_uint8_t data_type | |
| } | tr_nvram_attr_storage_v1_t |
| structure for storing information about zigbee attributes in NV | |
| typedef zb_bool_t(* | tr_nvram_clear_data_t) (void) |
| function pointer type for clearing the callback data or NULL to use default behavior (set to 0) | |
| typedef zb_bool_t(* | tr_nvram_err_handler_t) (zb_uint8_t *saved_data_ptr, zb_uint8_t data_entry_size, zb_uint8_t data_num_entries) |
| function pointer type for handling size or version errors or NULL to abort data read in this casee | |
Enumerations | |
| enum | tr_nvram_section_id_t { TR_NVRAM_SECTION_ZIGBEE_ATTRIBUTES = 1 , TR_NVRAM_SECTION_SCENES_TABLE = 2 , TR_NVRAM_SECTION_DOOR_LOCK_USER_TABLE = 3 , TR_NVRAM_SECTION_TSTAT_SCHEDULE_TABLE = 4 , TR_NVRAM_SECTION_APP_DATA_1 = 101 } |
| standard section IDs used by Trident plugins and reserved for use by the application More... | |
Functions | |
| zb_uint16_t | tr_get_nvram_data_size (void) |
| there are 3 API functions needed by ZBOSS and passed by the apps | |
| zb_ret_t | tr_nvram_write_app_data_cb (zb_uint8_t page, zb_uint32_t pos) |
| write API: do not change this without reading below | |
| void | tr_nvram_read_app_data_cb (zb_uint8_t page, zb_uint32_t pos, zb_uint16_t payload_length) |
| read API: do not change this without reading below | |
| void | tr_check_for_attr_nvram_update (zb_uint8_t ep, zb_uint16_t cluster_id, zb_uint8_t cluster_role, zb_uint16_t attr_id, zb_uint16_t manuf_code) |
| check if a changed attr is supposed to be saved in NV and if so, save it | |
| void | tr_check_for_attr_nvram_update_delay (zb_uint8_t ep, zb_uint16_t cluster_id, zb_uint8_t cluster_role, zb_uint16_t attr_id, zb_uint16_t manuf_code, zb_uint16_t delay_time_ms) |
| check if a changed attr is supposed to be saved in NV and if so, save it | |
| void | tr_nvram_register (tr_nvram_data_info_t *register_data) |
| this API is called by a plugin to register to have its data saved | |
| void | tr_nvram_save (zb_uint16_t delay_time_ms) |
| this API is called by a plugin when plugin data has changed | |
this file formats plugin data for saving to non-volatile space.
The code in this file helps to save plugin data to nonvolatile storage. In order to make this work for different chips, and to provide wear leveling it works like this:
We need to provide 3 main functions to make this work: READ, WRITE, and SIZE there are helper functions for each of these APIs that handle size, read, and write for any plugin that needs to save data, so far there are 2: zigbee attr table and scenes table.
if a plugin wants to save data in NV, it registers with this module by calling: tr_nvram_register(tr_nvram_data_info_t *register_data);
and passes in a struct that has all the relevant information:
if a plugin changes its RAM data and wants to save the data in NV, it calls: void tr_nvram_save(zb_uint16_t delay_time_ms);
and passes in 0 to save immediately and a nonzero value to save at that time (this delay allows other changes to happen in the delay window which would start another delay window and minimizes the flash writes)
In order to allow for apps to change and support different plugins each plugins data is saved as a section. Each section has a 4 bytes header:
SPDX-License-Identifier: LicenseRef-TridentMSLA SPDX-FileCopyrightText: 2025 Trident IoT, LLC https://www.tridentiot.com
| #define TR_NVRAM_ATTR_STORAGE_CUR_VER (TR_NVRAM_ATTR_STORAGE_VER_1) |
| #define TR_NVRAM_ATTR_STORAGE_VER_1 (1) |
| #define tr_nvram_printf | ( | ... | ) |
enable this to print when errors occur
| #define TR_NVRAM_SECTION_ID_ZIGBEE_ATTRS 0x8001 |
| #define TR_NVRAM_STORAGE_VER_1 (1) |
| #define TR_NVRAM_STORAGE_VER_2 (2) |
| #define tr_nvram_verbose_printf | ( | ... | ) |
these are for verbose printing of the read, write, and size APIs
| #define TR_NVRAM_WRITE_DELAY_MS (2000) |
| zb_uint16_t attr_id |
| zb_uint16_t cluster_id |
| zb_uint8_t cluster_role |
| zb_uint8_t data_type |
| zb_uint8_t endpoint |
| zb_uint16_t manuf_code |