微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI Zigbee设计交流 > CC2530 Simpliciti NVOBJ 保存连接状态问题

CC2530 Simpliciti NVOBJ 保存连接状态问题

时间:10-02 整理:3721RD 点击:

目前有个小型项目需要用到简单的协议,直接用了simpliciti协议,涉及到断电保存的问题,参考了这个wiki:http://processors.wiki.ti.com/index.php/SimpliciTI_FAQ#Restoring_connection_after_power_cycle里面的Restoring connection after power cycle的例程,目前能拷贝到objptr的内容跟第一次连接的一样,但是没有建立连接,不知道为什么,下面是代码

代码段1,读取&保存objptr内容

uint8_t* nv_obj_read_nwk_cfg(void)
{
  uint8_t byte[5] ;
  uint8_t *data=NULL ;
  uint16_t str_len ;
  int i ;
  EE_Sequential_Read(1,0x00,(char*)byte,4);
   
  if((byte[0] == 'S') && (byte[1] == 'M') && 
     (byte[2] == 'P') && (byte[3] == 'L'))
  {
    //Read config ObjLen
    str_len=EE_Random_Read(1,0x05);
    //assign memory for data buf
    data = (uint8_t*)malloc(str_len*sizeof(uint8_t));
    //Read ObjPtr from EEPROM
    EE_Sequential_Read(2,0x00,(char*)data,str_len);
  }
  for(i=0;i<29;i++)
  {
    UartSendByte(data[i]);
  }
  return data;
}
bool nv_obj_write_nwk_cfg(uint8_t **nwk_cfg, uint16_t len)
{
  int i ;
  uint8_t *dat=NULL;
  
  printf("NVOBJ Store NWK Config:");
  
  dat = (uint8_t*)malloc(len*sizeof(uint8_t));
  memcpy(dat,(*nwk_cfg),len);
  
  if(!EE_Byte_Write(1,0x05,len))
  {
    printf("failed\r\n");
    return false ;
  }
  
  //**page write only support 16bit in a write cycle
  //**Do not use page write in case of the "roll over" situation
  for(i=0;i<len;i++)
  {
    if(!EE_Byte_Write(2,(0x00+i),dat[i]))
    {
      printf("failed\r\n");
      return false ;
    }
  }
  
  free(dat);
  
  EE_Byte_Write(1,0x00,'S');
  EE_Byte_Write(1,0x01,'M');
  EE_Byte_Write(1,0x02,'P');
  EE_Byte_Write(1,0x03,'L');
  printf("success\r\n");

  return true;
}

代码段2 上电设置连接相关代码
void Set_Connection(void)
{
  uint8_t *nwk_cfg_flash;
  uint8_t *data = NULL;
  int i;
  nwk_cfg_flash = nv_obj_read_nwk_cfg();

  if(nwk_cfg_flash==NULL)
  {
    while(1)
    {
      if (SMPL_SUCCESS == SMPL_LinkListen(&sLinkID2))
        break;  
      LED_Toggle('G');
      LED_Toggle('R');    
    }
    LED_OFF('G');
    LED_OFF('R');
    Buzzer(0);
    Store_Connection();
  }
  else
  {
    nwk_cfg_ram.objPtr = &data ;
    nwk_cfg_ram.objLen = 0x1d ;
    if(SMPL_Ioctl(IOCTL_OBJ_NVOBJ, IOCTL_ACT_GET, &nwk_cfg_ram) == SMPL_SUCCESS)
    {
      memcpy((*nwk_cfg_ram.objPtr), nwk_cfg_flash, nwk_cfg_ram.objLen);
      for(i=0;i<29;i++)
      {
        UartSendByte((*nwk_cfg_ram.objPtr)[i]);
      }
    }
    sLinkID2 = nv_obj_read_lnk_id(0);
  }
}
void Store_Connection(void)
{
  if(SMPL_Ioctl(IOCTL_OBJ_NVOBJ, IOCTL_ACT_GET, &nwk_cfg_ram) == SMPL_SUCCESS)
  { 
    if(nv_obj_write_nwk_cfg(nwk_cfg_ram.objPtr,(char)nwk_cfg_ram.objLen) != true)
    {
      while(1);
    }
    nv_obj_write_lnk_id(0,sLinkID2);
  }
}
void Set_Connection(void)
{
  uint8_t *nwk_cfg_flash;
  uint8_t *data = NULL;
  int i;
  nwk_cfg_flash = nv_obj_read_nwk_cfg();

  if(nwk_cfg_flash==NULL)
  {
    while(1)
    {
      if (SMPL_SUCCESS == SMPL_LinkListen(&sLinkID2))
        break;  
      LED_Toggle('G');
      LED_Toggle('R');    
    }
    LED_OFF('G');
    LED_OFF('R');
    Buzzer(0);
    Store_Connection();
  }
  else
  {
    nwk_cfg_ram.objPtr = &data ;
    nwk_cfg_ram.objLen = 0x1d ;
    if(SMPL_Ioctl(IOCTL_OBJ_NVOBJ, IOCTL_ACT_GET, &nwk_cfg_ram) == SMPL_SUCCESS)
    {
      memcpy((*nwk_cfg_ram.objPtr), nwk_cfg_flash, nwk_cfg_ram.objLen);
      for(i=0;i<29;i++)
      {
        UartSendByte((*nwk_cfg_ram.objPtr)[i]);
      }
    }
    sLinkID2 = nv_obj_read_lnk_id(0);
  }
}
void Store_Connection(void)
{
  if(SMPL_Ioctl(IOCTL_OBJ_NVOBJ, IOCTL_ACT_GET, &nwk_cfg_ram) == SMPL_SUCCESS)
  { 
    if(nv_obj_write_nwk_cfg(nwk_cfg_ram.objPtr,(char)nwk_cfg_ram.objLen) != true)
    {
      while(1);
    }
    nv_obj_write_lnk_id(0,sLinkID2);
  }
}
 
6457.Desk_Zigbee.rar

这是工程,求解答,万分感谢

如果恢复出来的内容都一样的话,之前保存的地址信息都在,直接可以发送数据吗?

你好,不好意思才关注到,是的,恢复出来发送/接收都不可用

你好,已经搞定了,谢谢

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top