当前位置: 代码迷 >> 综合 >> Zstack 笔记(一)
  详细解决方案

Zstack 笔记(一)

热度:52   发布时间:2023-12-13 12:02:15.0

 ZIGBEE 协议中的三种设备类型:

 ZigBee 协调者(ZC)这个设备被配置为初始化并建立一个 PAN 网络(注意PANID的分配)
 ZigBee
 路由器(ZR)该设备被配置为加入一个存在的网络,可以加入一个协调求或路由器, 然后允许其他设备加入它,在网络中路有数据信息。 
 ZigBee
 终端节点 (ZED)该设备被配置为加入一个存在的网络,可以加入一个协调求或路由器。 

PanID 和通道(Channel)选择 :
 ZigBee
协议规范规定,一个 14位的个域网标志符(PAN ID)来标识唯一的一个网络。Z-Stack可以用两种方式由用户自己选择其 PAN ID,当 ZDAPP_CONFIG_PAN_ID值设置不为 0xFFFF时,那么设备建立或加入网络的 PAN ID ZDAPP_CONFIG_PAN_ID指定;如果设置ZDAPP_CONFIG_PAN_ID 0xFFFF;那么设备就将建立或加入它发现网络中的最好的网络。关于这里提到的最好的网络,我觉得可能是有些参数评估,只不过这里没有详细的介绍,在后续文档中应该有介绍的。 

  2.4G频段上,IEEE802.15.4/ZIGBEE规范规定了 16 个频道。用户可以通过选择DEFAULT_CHANLIST不同的值可以选择不同的频道,其频道如下所示。该协议默认DDEFAULT_CHANLIST=0x00000800    // 11 - 0x0B
  
/*Default channel is Channel 11 - 0x0B */
  // Channels are defined in the following:
  //          0     : 868 MHz     0x00000001
  //         1 - 10 :915  MHz     0x000007FE
  //        11 - 16 :2.4  GHz     0x07FFF800
  //
  //-DMAX_CHANNELS_868MHZ     0x00000001
  //-DMAX_CHANNELS_915MHZ     0x000007FE
  //-DMAX_CHANNELS_24GHZ      0x07FFF800
  //-DDEFAULT_CHANLIST=0x04000000 // 26 - 0x1A
  //-DDEFAULT_CHANLIST=0x02000000 // 25 - 0x19
  //-DDEFAULT_CHANLIST=0x01000000 // 24 - 0x18
  //-DDEFAULT_CHANLIST=0x00800000 // 23 - 0x17
  //-DDEFAULT_CHANLIST=0x00400000 // 22 - 0x16
  //-DDEFAULT_CHANLIST=0x00200000 // 21 - 0x15
  //-DDEFAULT_CHANLIST=0x00100000 // 20 - 0x14
  //-DDEFAULT_CHANLIST=0x00080000 // 19 - 0x13
  //-DDEFAULT_CHANLIST=0x00040000 // 18 - 0x12
  //-DDEFAULT_CHANLIST=0x00020000 // 17 - 0x11
  //-DDEFAULT_CHANLIST=0x00010000 // 16 - 0x10
  //-DDEFAULT_CHANLIST=0x00008000 // 15 - 0x0F
  //-DDEFAULT_CHANLIST=0x00004000 // 14 - 0x0E
  //-DDEFAULT_CHANLIST=0x00002000 // 13 - 0x0D
  //-DDEFAULT_CHANLIST=0x00001000 // 12 - 0x0C
  -DDEFAULT_CHANLIST=0x00000800    // 11 - 0x0B

  

/* Definethe default PAN ID.
  * Setting this to a value other than 0xFFFF causes
  * ZDO_COORD to use this value as its PAN ID and
  * Routers and end devices to join PAN with this ID
  */
  //-DZDAPP_CONFIG_PAN_ID=0xFFFF
  -DZDAPP_CONFIG_PAN_ID=0xFFFF
  DEFAULT_CHANLIST
  ZDAPP_CONFIG_PAN_ID都作为 IAR IDE中的编译选项可以进行设置,在应用文件中的…\Projects\Tools\CC2430DB目录下的  f8wConfig.cfg文件中有相应设置。

Zstack协议的阅读:首先从主函数ZMain.c着手,其中Zmain.c:

int main( void )
{// Turn off interruptsosal_int_disable( INTS_ALL );// Initialization for board related stuff such as LEDsHAL_BOARD_INIT();// Make sure supply voltage is high enough to runzmain_vdd_check();// Initialize board I/OInitBoard( OB_COLD );// Initialze HAL driversHalDriverInit();// Initialize NV Systemosal_nv_init( NULL );// Initialize the MACZMacInit();// Determine the extended addresszmain_ext_addr();#if defined ZCL_KEY_ESTABLISH// Initialize the Certicom certificate information.zmain_cert_init();
#endif// Initialize basic NV itemszgInit();#ifndef NONWK// Since the AF isn't a task, call it's initialization routineafInit();
#endif// Initialize the operating systemosal_init_system();// Allow interruptsosal_int_enable( INTS_ALL );// Final board initializationInitBoard( OB_READY );// Display information about this devicezmain_dev_info();/* Display the device info on the LCD */
#ifdef LCD_SUPPORTEDzmain_lcd_init();
#endif#ifdef WDT_IN_PM1/* If WDT is used, this is a good place to enable it. */WatchDogEnable( WDTIMX );
#endifosal_start_system(); // No Return from herereturn 0;  // Shouldn't get here.
} // main()

从zmain.c里可以知道这个函数一共做了两件事,系统初始化(由启动代码初始化硬件和软件架构需要的各个模块)和开始执行操作系统实体。里面的具体工作有:关闭中断---板级初始化---电压检测 ---初始化板载IO--- 初始化HAL驱动 ---初始化NV系统 ---确定扩展地址(64位IEEE/物理地址)---初始化基本NV条目--- 初始化MAC ---操作系统---- 允许中断-----最终板初始化 ---显示设备信息  液晶支持显示。启动代码为操作系统做好准备工作后,就开始执行操作系统入口程序,并将控制权彻底交给操作系统。


初始化64  IEEE地址 
         
实际上在主函数中有这么个初始化函数的:zmain_ext_addr()。这里说如果地址复位为  0xFFFFFFFFFFFFFFFF的话则为无效地址

/*************************************************************************************************** @fn          zmain_ext_addr** @brief       Execute a prioritized search for a valid extended address and write the results*              into the OSAL NV system for use by the system. Temporary address not saved to NV.** input parameters** None.** output parameters** None.** @return      None.***************************************************************************************************/
static void zmain_ext_addr(void)
{uint8 nullAddr[Z_EXTADDR_LEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};uint8 writeNV = TRUE;// First check whether a non-erased extended address exists in the OSAL NV.if ((SUCCESS != osal_nv_item_init(ZCD_NV_EXTADDR, Z_EXTADDR_LEN, NULL))  ||(SUCCESS != osal_nv_read(ZCD_NV_EXTADDR, 0, Z_EXTADDR_LEN, aExtendedAddress)) ||(osal_memcmp(aExtendedAddress, nullAddr, Z_EXTADDR_LEN))){// Attempt to read the extended address from the location on the lock bits page// where the programming tools know to reserve it.HalFlashRead(HAL_FLASH_IEEE_PAGE, HAL_FLASH_IEEE_OSET, aExtendedAddress, Z_EXTADDR_LEN);if (osal_memcmp(aExtendedAddress, nullAddr, Z_EXTADDR_LEN)){// Attempt to read the extended address from the designated location in the Info Page.if (!osal_memcmp((uint8 *)(P_INFOPAGE+HAL_INFOP_IEEE_OSET), nullAddr, Z_EXTADDR_LEN)){osal_memcpy(aExtendedAddress, (uint8 *)(P_INFOPAGE+HAL_INFOP_IEEE_OSET), Z_EXTADDR_LEN);}else  // No valid extended address was found.{uint8 idx;#if !defined ( NV_RESTORE )writeNV = FALSE;  // Make this a temporary IEEE address
#endif/* Attempt to create a sufficiently random extended address for expediency.* Note: this is only valid/legal in a test environment and*       must never be used for a commercial product.*/for (idx = 0; idx < (Z_EXTADDR_LEN - 2);){uint16 randy = osal_rand();aExtendedAddress[idx++] = LO_UINT16(randy);aExtendedAddress[idx++] = HI_UINT16(randy);}// Next-to-MSB identifies ZigBee devicetype.
#if ZG_BUILD_COORDINATOR_TYPE && !ZG_BUILD_JOINING_TYPEaExtendedAddress[idx++] = 0x10;
#elif ZG_BUILD_RTRONLY_TYPEaExtendedAddress[idx++] = 0x20;
#elseaExtendedAddress[idx++] = 0x30;
#endif// MSB has historical signficance.aExtendedAddress[idx] = 0xF8;}}if (writeNV){(void)osal_nv_write(ZCD_NV_EXTADDR, 0, Z_EXTADDR_LEN, aExtendedAddress);}}// Set the MAC PIB extended address according to results from above.(void)ZMacSetReq(MAC_EXTENDED_ADDRESS, aExtendedAddress);
}

ZDO当成一个节点设备,其实ZDO是ZigBee协议栈中的一个协议,负责所有设备的管

理,安全方案。ZDO就好像是一个驻留在所有ZigBee节点中特殊应用对象,是应用层其他端点

与应用子层管理实体交互的中间件。ZDO的配置叫做ZDP(ZigBee设备配置ZigBee Device

Profile)ZDP可以被应用终端(application end points)和ZigBee节点访问。

acronyms n.首字母缩略词