原创 zigbee协议栈路由协议学习(2):MicroChip起步

2008-9-17 10:30 3594 7 7 分类: MCU/ 嵌入式

1、下载与安装。


从MicroChip网站http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en021878下载协议栈:
* 00965c.pdf:AN965, Microchip Stack for the ZigBee. Protocol:介绍基本概念,协议栈展开的目录结构,接口函数等。需要看。


* MpZBeeV1.0-3.8.1.exe,自动安装在C:\MpZBee。


2、阅读C:\MpZBee\README - Microchip Stack for ZigBee Protocol.pdf
其中“Version 1.0-3.8.1 of the Microchip Stack for the ZigBee Protocol offers the following features”中关注的一句是:“Supports non-slotted (non-beacon) star, cluster tree, and mesh network topologies”。有关这几个概念在00965c.pdf中有介绍。


因为我的目的是学习路由算法的实现,所以重点看cluster tree和mesh下的路由代码。


3、阅读zNWK.c


待进一步查看的对象:
routeDiscoveryTablePointer[]
MCPS_DATA_request


GetNextHop()
GetRoutingEntry()


ZigBeeUnblockTx()
NLDE_DATA_confirm
TxBuffer[]
neighborTable[]
GetNeighborRecord()
TickGet()
NWK_LEAVE_INDICATION | NWK_LEAVE_REMOVE_CHILDREN
MCPS_DATA_confirm


// Extract the NWK header
NWKGet()


#ifdef I_SUPPORT_ROUTING


NWKDiscardRx()


#ifndef USE_TREE_ROUTING_ONLY
#ifdef CALCULATE_LINK_QUALITY


NWKLookupNodeByShortAddrVal()


CreateRouteReply()


CreateRoutingTableEntries()


forwardRouteRequest = TRUE;


IsDescendant()


RouteAlongTree()


// Handle all unicast frames.
if (nwkFrameControlLSB.bits.frameType == NWK_FRAME_CMD)


goto HandleRouteRequest;


HaveRoutingCapacity()


PutRoutingEntry()


RouteAlongTree()


// The current frame is a data frame.


GetRoutingAddress()


对数据分组的处理过程,第2110行开始。


case MLME_ASSOCIATE_indication:


NWKLookupNodeByLongAddr()


CanAddChildNode()
CanAddNeighborNode()
AddChildNode()


goto TryToJoinPotentialParent;


MLME_SET_macShortAddress_hw()


SetBeaconPayload()


case MLME_SCAN_confirm:
nwkStatus.discoveryInfo.channelList[]


MLME_SET_macPANId_hw()


4、再看一下,与routing有关的函数:
RouteAlongTree()
GetRoutingAddress()



MESSAGE_ROUTING_STATUS GetRoutingAddress( BOOL fromUpperLayers, SHORT_ADDR nwkAddress, BYTE discoverRoute, SHORT_ADDR *macAddress ) {
  NWKLookupNodeByShortAddrVal()
  if (currentNeighborRecord.deviceInfo.bits.Relationship == NEIGHBOR_IS_CHILD)
  ...
}


5、NWKLookupNodeByShortAddrVal()


NEIGHBOR_KEY NWKLookupNodeByShortAddrVal( WORD shortAddrVal )
* Output:          Handle to matching node or INVALID_NEIGHBOR_KEY
 *
 * Side Effects:    If found, the matching neighbor table entry is in
 *                  currentNeighborRecord and pCurrentNeighborRecord
 *                  points to its location in the table.
{
遍历neighborTable中的每一条记录,对有效记录进行短地址比较(if ( currentNeighborRecord.shortAddr.Val == shortAddrVal ))。
找到时,匹配的NeighborRecord放在currentNeighborRecord变量中。


currentNeighborRecord在zNVM.h中定义:
extern NEIGHBOR_RECORD                  currentNeighborRecord;


NEIGHBOR_RECORD在zNWK.h中定义:
typedef struct _NEIGHBOR_RECORD
{
    LONG_ADDR                   longAddr;
    SHORT_ADDR                  shortAddr;
    PAN_ADDR                    panID;
    NEIGHBOR_RECORD_DEVICE_INFO deviceInfo;
    BYTE                        LogicalChannel; // Needed to add for NLME_JOIN_request and other things.
    #ifdef I_SUPPORT_SECURITY
    BOOL      bSecured;
    #endif
} NEIGHBOR_RECORD;  // 15 bytes long
typedef union _NEIGHBOR_RECORD_DEVICE_INFO
{
    struct
    {
        BYTE LQI                : 8;
        BYTE Depth              : 4;
        BYTE StackProfile       : 4;    // Needed for network discovery
        BYTE ZigBeeVersion      : 4;    // Needed for network discovery
        BYTE deviceType         : 2;
        BYTE Relationship       : 2;
        BYTE RxOnWhenIdle       : 1;
        BYTE bInUse             : 1;
        BYTE PermitJoining      : 1;
        BYTE PotentialParent    : 1;
    } bits;
    DWORD Val;
} NEIGHBOR_RECORD_DEVICE_INFO;

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
我要评论
0
7
关闭 站长推荐上一条 /3 下一条