NXP

ZigBee 3.0 EmberZNet EFR32MG学习笔记-7-EEPROM-NVM3的Cus

2019-07-12 12:50发布

转载请注明出处,谢谢! Newbit-Msming 2018-10-10 ZigBee 3.0 EmberZNet EFR32MG 学习笔记-目录
ZigBee 3.0 EmberZNet EFR32MG 学习笔记-7-EEPROM-NVM3的Custom Tokens使用 环境:Windows 10、Simplicity Studio 4 SDK: EmberZNet SDK 6.4.0.0 工程:新建
  1. 打开.isc文件,勾选NVM3的依赖插件:”NVM3 Library”、”Simulated EEPROM version 2 to NVM3 Upgrade Stub”,如图 1,还有一个插件是”EEPROM” ,不勾选也是可以的,但是建议也勾上。
    isc-file
    ----------------------------------------------------------------图 1--------------------------------------------------------------
  2. 在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 //省略…… }
  1. 测试,以下是3个token范围,用户使用的范围是0x00000-0x0ffff,
// NVM3KEY domain base keys #define NVM3KEY_DOMAIN_USER 0x00000U #define NVM3KEY_DOMAIN_ZIGBEE 0x10000U #define NVM3KEY_DOMAIN_COMMON 0x80000U 测试代码: uint32_t arg3 = 0x12345678; uint32_t read = 0x0; halInternalSetTokenData(0x0001, 0, (uint8_t *)&arg3, 4); emberAtPrintln("NW %lu", arg3); halInternalGetTokenData((uint8_t *)&read, 0x0001, 0, 4); emberAtPrintln("NR %lu", read);
  1. 如果你的Token需要让底层知道,那么需要添加Custom Tokens,需要新建一个xxx_tokens.h文件,注意头文件内不能有条件编译(#ifndef),然后在.isc文件的”Include”选项卡下的”Token Configuration”添加新建文件的路径。
  2. xxx_tokens.h文件的参考内容如下,必须是“CREATOR”开头。
/* 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
  1. 更详细的用法可以查看ember的文档《an1154-tokens-for-non-volatile-storage》。
  2. 常驻:NewBit Studio
2019-1-15 更新:
  1. 预编译注意事项,不要在新建的xxx_tokens.h文件添加类似以下的预编译,因为很有可能编译器在编译这个文件的时候找不到在其他文件定义的宏(APP_ADC),从而编译了:#define ADC_BUFF_SIZE 1。
#ifdef APP_ADC #define ADC_BUFF_SIZE 20 #else #define ADC_BUFF_SIZE 1 #endif
  1. 不能include “xxx.h”文件。