Trident IoT Zigbee SDK
Loading...
Searching...
No Matches
NVRAM save and restore
Collaboration diagram for NVRAM save and restore:

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_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

Detailed Description



Macro Definition Documentation

◆ TR_NVRAM_DOOR_LOCK_SLOTS

#define TR_NVRAM_DOOR_LOCK_SLOTS   0

◆ TR_NVRAM_NUM_APP_SECTIONS

#define TR_NVRAM_NUM_APP_SECTIONS   1

◆ TR_NVRAM_NUM_TABLE_SLOTS

#define TR_NVRAM_NUM_TABLE_SLOTS   (TR_NVRAM_NUM_APP_SECTIONS + TR_NVRAM_DOOR_LOCK_SLOTS + TR_NVRAM_SCENES_SLOTS)

◆ TR_NVRAM_SCENES_SLOTS

#define TR_NVRAM_SCENES_SLOTS   0

this defines the number of slots available for plugins to register to save their data


we need to have one of these per plugin section that the app supports (see defines above). The zigbee attribute section doesn't count against this since it is always there, and not kept in the table


Typedef Documentation

◆ [struct]

typedef ZB_PACKED_PRE struct { ... } tr_nvram_attr_storage_v1_t

structure for storing information about zigbee attributes in NV



◆ tr_nvram_clear_data_t

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)



◆ tr_nvram_err_handler_t

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



Enumeration Type Documentation

◆ tr_nvram_section_id_t

standard section IDs used by Trident plugins and reserved for use by the application


when a plugin registers with the NV save/restore module, it needs to have a unique number for the section ID. These only need to be unique within the particular app, but if they are standard then different apps can be loaded and read the plugin data, so we standardize the ones we know about here section IDs


Enumerator
TR_NVRAM_SECTION_ZIGBEE_ATTRIBUTES 
TR_NVRAM_SECTION_SCENES_TABLE 
TR_NVRAM_SECTION_DOOR_LOCK_USER_TABLE 
TR_NVRAM_SECTION_TSTAT_SCHEDULE_TABLE 
TR_NVRAM_SECTION_APP_DATA_1 

Function Documentation

◆ tr_check_for_attr_nvram_update()

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


Parameters
epthe endpoint of the attribute that changed
cluster_idthe cluster_id of the attribute that changed
cluster_rolethe cluster rold of the attribute that changed
attr_idthe attribute id of the attribute that changed
manuf_codethe manufacturer code of the attribute that changed

zigbee attributes are handled differently than other plugin data since these are stored by the ZBOSS stack. When the app changes an attribute it can call this to check it that attribute needs to be updated in NV. The delay time determines if the NV write is done immediately or delayed for that amount of time. It is a good idea to add delay in the case that multiple attributes are going to be written to reduce the number of NV writes. Alternatively, it may be necessary to have a delay of 0 in order to force the NV write immediately so that an ayttribute is written before an impending reset which would erase the attributes in RAM.


◆ tr_check_for_attr_nvram_update_delay()

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


Parameters
epthe endpoint of the attribute that changed
cluster_idthe cluster_id of the attribute that changed
cluster_rolethe cluster rold of the attribute that changed
attr_idthe attribute id of the attribute that changed
manuf_codethe manufacturer code of the attribute that changed
delay_time_mshow long to wait before saving, 0 means immediate

◆ tr_get_nvram_data_size()

zb_uint16_t tr_get_nvram_data_size ( void )

there are 3 API functions needed by ZBOSS and passed by the apps




size API: do not change this without reading below

Returns
the total size of the data to save in NV

this is an API, passed as a fx ptr by the app generated code to ZBOSS, and called by ZBOSS when reading or writing items to NV. This API returns the total size of what needs to be saved, or what was expected to be saved.


◆ tr_nvram_read_app_data_cb()

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


Parameters
pagethe page that was read from in NV
posthe position that was read from in NV
payload_lengththe length of the data that is handed to this module

this is an API, passed as a fx ptr by the app generated code to ZBOSS, and called by ZBOSS when writing items to NV. This API is given the page and position of where to write to in flash (write is done using a chip platform API). This function is responsible for reading data from the plugin structures and placing the data in a contiguous RAM memory buffer so it can be written into flash.


◆ tr_nvram_register()

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


Parameters
register_datathe information about what this plugin wants to save

◆ tr_nvram_save()

void tr_nvram_save ( zb_uint16_t delay_time_ms)

this API is called by a plugin when plugin data has changed


Parameters
delay_time_mshow long to wait before saving, 0 means immediate

◆ tr_nvram_write_app_data_cb()

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


Parameters
pagethe page to write to in NV
posthe position to write to in NV
Returns
ZBOSS status code

this is an API, passed as a fx ptr by the app generated code to ZBOSS, and called by ZBOSS when reading items from NV. This API passes the page and position of where to read from in NV (read is done using a chip platform API), and once the read is is done, this function is responsible for placing the data in the plugin data structures.