Thread 中讨论的其他器件:CC2630、 CC2650、 Z-stack
尊敬的 TI 团队:
我想将变量的值读写到 NVRAM 中。 您是否有任何我可以使用的 API、并提供一些示例代码供参考?
非常感谢
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
您好,YK,
我在按下按钮后使用以下代码初始化、写入和读取 NVRAM。 但它似乎不起作用。 我输出了读取 NVRAM 的结果,但该值不正确。 我会错过什么吗?
我还检查了 INIT (NV_IT_UNINIT 0x09)、WRITE (NV_ITE_UNINIT 0x09)和 READ (成功 0x00)的状态。
/*读/写 NVRAM*/
uint8 join_result;
uint16_t customNvID=0x0402;;
//join_result=0x01;
uint8 result_read;
zclport_initializeNVItem (customNvID、0、1、(void*)&join_result);
//printf ("result_init=%02x\n"、result_init);
//fflush (stdout);
Joine_Result = 0x00;
zclport_writeNV (customNvID、0、0、1、(void*)&join_result);
//printf ("result_write=%02x\n"、result_write);
//fflush (stdout);
uint8 temp_value;
result_read=zclport_readnv (customNvID、0、0、1、(void*)&temp_value);
printf ("result_read=%02x temp_value=%02x\n"、result_read、temp_value);
fflush (stdout);
谢谢
您好,YK,
我已经叫它。 您可以参考我的代码。 每次我想使用读/写时都需要调用 init 函数?
或者、我需要将 zclport_initializeNVItem 的函数放入 init 应用程序中吗?
静态空 zclSampleSw_processKey (uint8 keyPressed)
{
if (keysPressed = key_right)
{
/*读/写 NVRAM*/
uint8 join_result;
uint16_t customNvID=0x0402;;
//join_result=0x01;
uint8 result_init;
uint8 result_write;
uint8 result_read;
result_init=zclport_initializeNVItem (customNvID、0、1、(void*)&join_result);
printf ("result_init=%02x\n"、result_init);
fflush (stdout);
Joine_Result = 0x00;
result_write=zclport_writeNV (customNvID、0、0、1、(void*)&join_result);
printf ("result_write=%02x\n"、result_write);
fflush (stdout);
uint8 temp_value;
result_read=zclport_readnv (customNvID、0、0、1、(void*)&temp_value);
printf ("temp_value=%02x result_read=%02x\n"、temp_value、result_read);
fflush (stdout);
}
}
谢谢
您好,YK,
注意到。
尊敬的 Ryan Brown1:
您能否帮助提供为应用预留的正确 NV ID 范围?
我们是否有任何可用于取消设置 NV ID 的 API?
我是否可以通过任何方法取消将参考板(CC2652)上的所有 NV ID 设为默认值? 我很疲惫地按下 CC2652参考板上的 RESET 按钮来重置 NV ID、因为我已经写入了一些数据、但它不起作用。
谢谢
您好,黄伟,劳伦斯,
每个 NV 项目的长度为8字节(四个字)、因此0x400项目为8 KB (或两页)的闪存存储器、默认情况下、所有这些都在 hal_board_cfg.h 中分配 如果您想访问0x400以上的 NV 项目空间、请尝试增大 HAL_NV_PAGE_CNT。 至于在复位时清除 NV 项目:
Zstack_sysResetReq_t resetReq; restReq.newNWkState = true; (void) Zstackapi_sysResetReq (zclSampleLight_Entity、&resetReq);
只要 newNWKState 设置为 true、这就应该执行出厂复位。 这是指向 Z-Stack API 指南的链接、尽管我们确实认识到我们目前正在努力解决一些 API 缺失的问题: 
此致、
Ryan
您好、Ryan、
此外,还有黄大黄的问题。 我想再问一个问题。
bdb_resetLocalAction()函数与 Zstackapi_sysResetReq 的 API 之间有何差异?
我知道 bdb_resetLocalAction 的函数只能复位 ZigBee 的设置。
Zstackapi_sysResetReq 的 API 可以重置(清除) ZigBee 和 NV 项目的设置、或者它只能重置(清除) NV 项目的设置?
谢谢
您好,YK,
我查找的是示例代码,并且以错误的方式进行写入,请查看 zcl_port.c 中的 zclGeneral_AddScene(), zclSceneNVID 等于 ZCL_port_Scene_table_nv_ID,该值在 zcl_port.h 中定义为0x0001。 zclport NV API 以与以前不同的方式保存项目、因为现在有两个 ID 提供 NV 项目的位置。
从 zcl_port.h:
/**默认 ZCL 场景表 NV 项目 ID */ #define ZCL_PORT_Scene_Table_NV_ID 0x0001 /**默认 ZCL 代理表 NV 项目 ID */ #define ZCL_PORT_PROVITY_TABLE _NV_ID 0x0002/** 默认 ZCL 接收器表 NV 项目 ID */ #define ZCL_PORT_SINK_TACK_NOT_ID 0x0003
工作的代码如下:
#define custom_nv_ID 0x0004
static void zclSampleSw_processKey (uint8 keyssed)
{
if (keyssed = key_right)
{
/*读/写 NVRAM*/
uint8 join_result;
uint16_t customNvID = custom_nv_ID;
//join_result=0x01;
uint8 result_init;
uint8 result_write;
uint8 result_read;
result_init=zclport_initializeNVItem (customNvID、0、1、(void*)&join_result);
printf ("result_init=%02x\n"、result_init);
fflush (stdout);
Joine_Result = 0x00;
result_write=zclport_writeNV (customNvID、0、0、1、(void*)&join_result);
printf ("result_write=%02x\n"、result_write);
fflush (stdout);
uint8 temp_value;
result_read=zclport_readnv (customNvID、0、0、1、(void*)&temp_value);
printf ("temp_value=%02x result_read=%02x\n"、temp_value、result_read);
fflush (stdout);
}
是的、您也可以查看 gp_ProxyTblInit()中的绿色电源代理表、此函数位于 gp_proxy.c 中、其中代理表初始化为 ZCL_port_proxy_table_nv_ID、其中元素数量等于 GPP_MAX_proxy_table_entries、这意味着"subp_entries 将从 GPP_MAX_entries 开始。
uint8 gp_ProxyTblInit( uint8 resetable )
{
uint8 i;
uint8 status;
uint8 emptyEntry [proxy_TBL_LEN];
GP_ResetProxyTblEntry (emutyEntry);
对于(i = 0;i < GPP_MAX_PROXY TABLE _entries;i++)
{
status = zclport_initiataleNVItem (ZCL_port_proxy_table_nv_ID,(ZCD_nv_proxy_table_start + i),
proxy_TBL_LEN、
emptyEntry );
if ((status!= Success)&(status!= nV_item_UNINIT))
{
返回状态;
}
否则((status == Success)&&(resettable == true))
{
status = zclport_writeNV (ZCL_port_proxy_table_nv_ID、(ZCD_nv_proxy_table_start + i)、
0、
proxy_TBL_LEN、
emptyEntry );}
}
返回状态;
}
您好,YK,
我将在我们的文档中找到合适的位置来解决这一问题、但用户指南的 Z-Stack 概述部分的第9.6.3节中提到了这一点。 用户应该能够参考门锁控制器示例、以了解在其应用中实现定制 NV 项目的用例场景。 nvertp.c 中定义了此 nv id 的最大值:
//最大 ID 参数-必须与头压缩协调, //增加这些限制需要修改 readHdr()函数 #define NVOCTP_MAXSYSID 0x003F // 6位 #define NVOCTP_MAXITEMID 0x03FF // 10位 #define NVOCTP_MAXSUBID 0x03FF // 10位 #define NVOCTP_MAXLEN 0x03FF // 10位
此致、Ryan