/*
V0.1 Initial Release 10/July/2006
*
*/
/*
V0.21 fixed problem in OrphanResponse, was not copying the parent's
long address 27/July/2006
V0.2 added PC-based binding 21/July/2006
V0.1 Initial Release 10/July/2006
*/
#include "compiler.h"
#include "lrwpan_config.h" //user configurations
#include "lrwpan_common_types.h" //types common acrosss most files
#include "ieee_lrwpan_defs.h"
#include "console.h"
#include "debug.h"
#include "memalloc.h"
#include "hal.h"
#include "halStack.h"
#include "phy.h"
#include "mac.h"
#include "nwk.h"
#include "neighbor.h"
typedef enum _MAC_RXSTATE_ENUM {
MAC_RXSTATE_IDLE,
MAC_RXSTATE_NWK_HANDOFF,
MAC_RXSTATE_CMD_PENDING
} MAC_RXSTATE_ENUM;
static MAC_RXSTATE_ENUM macRxState;
MAC_PIB mac_pib;
MAC_SERVICE a_mac_service;
MAC_STATE_ENUM macState;
//there can only be one TX in progress at a time, so
//a_mac_tx_data contains the arguments for that TX.
MAC_TX_DATA a_mac_tx_data;
//this is used for parsing of current packet.
MAC_RX_DATA a_mac_rx_data;
LRWPAN_STATUS_ENUM macTxFSM_status;
//locals
static UINT32 mac_utility_timer; //utility timer
//local functions
static void macTxData(void);
static void macTxFSM(void);
static void macParseHdr(void);
static void macRxFSM(void);
static void macParseBeacon(void);
static void macFormatAssocRequest(void);
static BOOL macCheckDataRejection(void);
static void macFormatOrphanNotify(void);
#ifndef LRWPAN_COORDINATOR
static void macParseOrphanResponse(void);
#endif
#ifdef LRWPAN_FFD
static void macFormatBeacon(void);
static void macFormatAssociationResponse(void);
static void macFormatCoordRealign(SADDR orphan_saddr);
#endif
#ifndef LRWPAN_COORDINATOR
static void macParseAssocResponse(void);
#endif
//does not turn on radio.
void macInit(void){
macState = MAC_STATE_IDLE;
macRxState = MAC_RXSTATE_IDLE;
mac_pib.macCoordShortAddress = 0;
mac_pib.flags.val = 0;
mac_pib.rxTail = 0;
mac_pib.rxHead = 0;
mac_pib.macPANID = LRWPAN_DEFAULT_PANID;
mac_pib.macMaxAckRetries = aMaxFrameRetries;
ntInitAddressMap(); //init the address map
#ifdef LRWPAN_COORDINATOR
mac_pib.depth = 0;
#else
mac_pib.depth = 1; //depth will be at least one
#endif
mac_pib.bcnDepth = 0xFF; //remembers depth of node that responded to beacon
//other capability information
mac_pib.macCapInfo = 0;
#ifdef LRWPAN_ALT_COORDINATOR //not supported, included for completeness
LRWPAN_SET_CAPINFO_ALTPAN(mac_pib.macCapInfo);
#endif
#ifdef LRWPAN_FFD
LRWPAN_SET_CAPINFO_DEVTYPE(mac_pib.macCapInfo);
#endif
#ifdef LRWPAN_ACMAIN_POWERED
LRWPAN_SET_CAPINFO_PWRSRC(mac_pib.macCapInfo);
#endif
#ifdef LRWPAN_RCVR_ON_WHEN_IDLE
LRWPAN_SET_CAPINFO_RONIDLE(mac_pib.macCapInfo);
#endif
#ifdef LRWPAN_SECURITY_CAPABLE
LRWPAN_SET_CAPINFO_SECURITY(mac_pib.macCapInfo);
#endif
//always allocate a short address
LRWPAN_SET_CAPINFO_ALLOCADDR(mac_pib.macCapInfo);
}
LRWPAN_STATUS_ENUM macWarmStartRadio(void){
halWarmstart();
a_phy_service.cmd = LRWPAN_SVC_PHY_INIT_RADIO; //no args
a_phy_service.args.phy_init_radio_args.radio_flags.bits.listen_mode = 0;
#ifdef LRWPAN_COORDINATOR
a_phy_service.args.phy_init_radio_args.radio_flags.bits.pan_coordinator = 1;
#else
a_phy_service.args.phy_init_radio_args.radio_flags.bits.pan_coordinator = 0;
#endif
phyDoService();
halSetChannel(phy_pib.phyCurrentChannel);
halSetRadioPANID(mac_pib.macPANID); //listen on this PANID
halSetRadioShortAddr(macGetShortAddr()); //non-broadcast, reserved
return(a_phy_service.status);
}
//this assumes that phyInit, macInit has previously been called.
//turns on the radio
LRWPAN_STATUS_ENUM macInitRadio(void) {
phy_pib.phyCurrentFrequency = LRWPAN_DEFAULT_FREQUENCY;
phy_pib.phyCurrentChannel = LRWPAN_DEFAULT_START_CHANNEL;
if (phy_pib.phyCurrentChannel < 11){
mac_pib.macAckWaitDuration = SYMBOLS_TO_MACTICKS(120);
}
else {
mac_pib.macAckWaitDuration = SYMBOLS_TO_MACTICKS(54);
}
a_phy_service.cmd = LRWPAN_SVC_PHY_INIT_RADIO; //no args
a_phy_service.args.phy_init_radio_args.radio_flags.bits.listen_mode = 0;
#ifdef LRWPAN_COORDINATOR
a_phy_service.args.phy_init_radio_args.radio_flags.bits.pan_coordinator = 1;
#else
a_phy_service.args.phy_init_radio_args.radio_flags.bits.pan_coordinator = 0;
#endif
phyDoService();
#ifdef LRWPAN_USE_STATIC_PANID
halSetRadioPANID(LRWPAN_DEFAULT_PANID); //listen on this PANID
#else
halSetRadioPANID(0xFFFF); //broadcast
#endif
halSetRadioShortAddr(0xFFFE); //non-broadcast, reserved
return(a_phy_service.status);
}
void macSetPANID(UINT16 panid){
mac_pib.macPANID = panid;
halSetRadioPANID(mac_pib.macPANID);
}
void macSetChannel(BYTE channel){
phy_pib.phyCurrentChannel = channel;
halSetChannel(channel);
}
void macSetShortAddr(UINT16 saddr) {
#ifdef LRWPAN_RFD
//when changing the short address for an RFD, always clear the map first
//since the short address may have changed.
//for RFDs, there is only one entry
ntInitAddressMap();
#endif
ntAddOurselvesToAddressTable(saddr);
halSetRadioShortAddr(saddr);
}
void macFSM(void) {
BYTE cmd;
#ifdef LRWPAN_FFD
NAYBORENTRY *nt_ptr;
#endif
#ifdef LRWPAN_DEBUG
//assume 2.4 GHZ
if (debug_level == 0) {
mac_pib.macAckWaitDuration = SYMBOLS_TO_MACTICKS(54);
} else {
mac_pib.macAckWaitDuration = SYMBOLS_TO_MACTICKS(270); //give longer due to debug output
}
#endif
phyFSM();
//if TxFSM is busy we need to call it
if (macTXBusy()) macTxFSM();
macRxFSM();
#ifdef LRWPAN_FFD
macFSM_start:
#endif
//check background tasks here
switch (macState) {
case MAC_STATE_IDLE:
if (mac_pib.flags.bits.macPending ) {
//there is a MAC CMD packet pending in the RX buffer. Handle it.
cmd = *(a_mac_rx_data.orgpkt->data + a_mac_rx_data.pload_offset);
switch (cmd) {
case LRWPAN_MACCMD_BCN_REQ:
//Beacon Request
#ifdef LRWPAN_RFD
//as an RFD, I do not handle this. Release this.
mac_pib.flags.bits.macPending = 0;
#else
//as a Coordinator or Router, I will only respond
//only respond if association permitted
//as this is the stack's only use of beacons
if (mac_pib.flags.bits.macAssociationPermit) {
//will keep spinning through here until TX buffer unlocked
if (phyTxUnLocked()) {
phyGrabTxLock(); //grab the lock
macState = MAC_STATE_SEND_BEACON_RESPONSE;
mac_pib.flags.bits.macPending = 0; //release packet
goto macFSM_start;
}
}else {
//release packet.
mac_pib.flags.bits.macPending = 0;
}
#endif
break;
case LRWPAN_MACCMD_ORPHAN:
//Orphan Notify
#ifdef LRWPAN_RFD
//as an RFD, I do not handle this. Release this.
mac_pib.flags.bits.macPending = 0;
#else
//will keep spinning through here until TX buffer unlocked
if (phyTxUnLocked()) {
phyGrabTxLock(); //grab the lock
macState = MAC_STATE_HANDLE_ORPHAN_NOTIFY;
mac_pib.flags.bits.macPending = 0; //release packet
goto macFSM_start;
}
#endif
case LRWPAN_MACCMD_ASSOC_REQ:
//Association Request
#ifdef LRWPAN_RFD
//as an RFD, I do not handle this. Release this.
mac_pib.flags.bits.macPending = 0;
#else
//as a Coordinator or Router, I can respond
//only respond if association
没有合适的资源?快使用搜索试试~ 我知道了~
receive.rar_源码
共115个文件
r51:54个
h:22个
c:17个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 14 浏览量
2022-07-14
00:46:31
上传
评论
收藏 906KB RAR 举报
温馨提示
ZIGBEE短距离无线开发程序,COORD接收到RFD的数据的处理程序!适合学习ZIGBEE的同学分析·!
资源推荐
资源详情
资源评论
收起资源包目录
receive.rar_源码 (115个子文件)
mac.c 53KB
aps.c 35KB
nwk.c 24KB
halStack.c 23KB
debug.c 14KB
pcbind.c 14KB
pcbind_node.c 11KB
memalloc.c 9KB
neighbor.c 8KB
zep.c 7KB
rxtest.c 5KB
evboard.c 5KB
phy.c 3KB
console.c 2KB
staticbind.c 2KB
putchar.c 695B
halNeighbor.c 343B
compiletest.dbgdt 6KB
接收方案测试.dbgdt 5KB
接收方案测试.dep 94KB
compiletest.dni 550B
接收方案测试.dni 447B
接收方案测试.ewd 52KB
接收方案测试.ewp 136KB
接收方案测试.eww 95B
hal_org.h 72KB
hal.h 31KB
aps.h 10KB
lrwpan_config.h 8KB
mac.h 6KB
ieee_lrwpan_defs.h 5KB
staticbind.h 4KB
lrwpan_common_types.h 3KB
nwk.h 3KB
halStack.h 2KB
pcbind.h 2KB
phy.h 2KB
debug.h 2KB
neighbor.h 2KB
evboard.h 2KB
compiler.h 1KB
zep.h 1KB
evbConfig.h 857B
console.h 751B
wx_lrwpan.h 620B
memalloc.h 551B
halHeapSpace.h 187B
compiletest.hex 265KB
compiletest.hex 253KB
compiletest.hex 77KB
compiletest.map 305KB
compiletest.map 290KB
compiletest.map 261KB
untitled.mcw 4KB
compiletest.pbd 1KB
compiletest.pbd 1KB
compiletest.pbd 1KB
接收方案测试.pbd 1KB
mac.r51 291KB
debug.r51 220KB
aps.r51 169KB
mac.r51 164KB
nwk.r51 162KB
mac.r51 160KB
halStack.r51 160KB
debug.r51 150KB
debug.r51 146KB
aps.r51 132KB
aps.r51 128KB
halStack.r51 125KB
halStack.r51 107KB
wxldemo.r51 103KB
nwk.r51 93KB
nwk.r51 91KB
constant.r51 81KB
neighbor.r51 78KB
ping_pong.r51 78KB
wxldemo.r51 74KB
wxldemo.r51 70KB
ping_pong.r51 69KB
ping_pong.r51 65KB
constant.r51 63KB
zep.r51 62KB
memalloc.r51 55KB
med-main.r51 51KB
neighbor.r51 49KB
med-main.r51 48KB
zep.r51 46KB
zep.r51 42KB
memalloc.r51 41KB
console.r51 37KB
memalloc.r51 37KB
rxtest.r51 36KB
neighbor.r51 30KB
console.r51 29KB
console.r51 27KB
phy.r51 26KB
evboard.r51 23KB
phy.r51 21KB
phy.r51 20KB
共 115 条
- 1
- 2
资源评论
刘良运
- 粉丝: 66
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功