打开.isc文件,勾选NVM3的依赖插件:”NVM3 Library”、”Simulated EEPROM version 2 to NVM3 Upgrade Stub”,如图 1,还有一个插件是”EEPROM” ,不勾选也是可以的,但是建议也勾上。
----------------------------------------------------------------图 1--------------------------------------------------------------
在emberAfMain()函数入口初始化NVM3,代码如下:
int emberAfMain(MAIN_FUNCTION_PARAMETERS)
{
EmberStatus status;
#ifdef USE_NVM3
// Initialize tokens in zigbee before we call emberAfMain because we need to
// upgrade any potential SimEEv2 data to NVM3 before we call gecko_stack_init
// (a bluetooth call). If we don't, the bluetooth call only initializes NVM3
// and wipes any SimEEv2 data present (it does not handle upgrading). The
// second call of halStackInitTokens in the zigbee stack will be a no-op
if (EMBER_SUCCESS != halStackInitTokens()) {
assert(false);
}
#endif //#ifdef USE_NVM3
//省略……
}
/* Custom Application Tokens*/
// Define token names here
#define CREATOR_DEVICE_INSTALL_DATA (0x000A)
#define CREATOR_HOURLY_TEMPERATURES (0x000B)
#define CREATOR_LIFETIME_HEAT_CYCLES (0x000C)
/* Custom Zigbee Application Tokens*/
// Define token names here
#define NVM3KEY_DEVICE_INSTALL_DATA (NVM3KEY_DOMAIN_ZIGBEE | 0x000A)
// This key is used for an indexed token and the subsequent 0x7F keys are also reserved
#define NVM3KEY_HOURLY_TEMPERATURES (NVM3KEY_DOMAIN_ZIGBEE | 0x1000)
#define NVM3KEY_LIFETIME_HEAT_CYCLES (NVM3KEY_DOMAIN_ZIGBEE | 0x000C)
// Types for the tokens
#ifdef DEFINETYPES
// Include or define any typedef for tokens here
typedef struct {
int8u install_date[11] /** YYYY-mm-dd + NULL */
int8u room_number; /** The room where this device is installed*/
} InstallationData_t;
#endif // DEFINETYPES
#ifdef DEFINETOKENS
// Define the actual token storage information here
DEFINE_BASIC_TOKEN(DEVICE_INSTALL_DATA,InstallationData_t,{0, {0,...}})
DEFINE_INDEXED_TOKEN(HOURLY_TEMPERATURES, int16u, HOURS_IN_DAY, {0,...})
DEFINE_COUNTER_TOKEN(LIFETIME_HEAT_CYCLES, int32u, 0}
#endif //DEFINETOKENS