首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

请教:有关freescale zigbee内存分配和释放

请教:有关freescale zigbee内存分配和释放

我现在在MAC/PHY软件基础上做一些东西,用MAC层的内存分配函数MSG_Alloc()申请了一块内存空间,用来存放要发送的数据包,数据包发送之后,我调用内存释放函数MSG_Free()释放,但是调用MSG_Free()的话会自动发送一些乱码出去,为什么呢?


麻烦高手指点!

我是申请一块空间pPacket用来存放dataRequest的,下面是源程序:

if( (numPendingPackets < MAX_PENDING_DATA_PACKETS) && (pPacket == NULL) )
{
/* If the maximum number of pending data buffes is below maximum limit
and we do not have a data buffer already then allocate one. */
pPacket = MSG_Alloc(sizeof(nwkToMcpsMessage_t) - 1 + DEFAULT_DATA_LENGTH);
}

if(pPacket != NULL)
{
/* If we have a buffer, then get data from the UART. */
uint8_t msduLength = Uart_Poll(pPacket->msgData.dataReq.msdu);
//dataLength = Uart_Poll(tempBuf);

//memcpy(pPacket->msgData.dataReq.msdu,tempBuf + 8, dataLength - 8);

//msduLength = dataLength - 8;
if(msduLength)
{
/* Data was available in the UART receive buffer. Now create an
MCPS-Data Request message containing the UART data. */
pPacket->msgType = gMcpsDataReq_c;
/* Create the header using coordinator information gained during
the scan procedure. Also use the short address we were assigned
by the coordinator during association. */
memcpy(pPacket->msgData.dataReq.dstAddr, coordInfo.coordAddress, 8);
//Uart_Print("Send data to the defined address!");
//memcpy(pPacket->msgData.dataReq.dstAddr, tempBuf, 8);
memcpy(pPacket->msgData.dataReq.srcAddr, myAddress, 8);
memcpy(pPacket->msgData.dataReq.dstPanId, coordInfo.coordPanId, 2);
memcpy(pPacket->msgData.dataReq.srcPanId, coordInfo.coordPanId, 2);
pPacket->msgData.dataReq.dstAddrMode = coordInfo.coordAddrMode;
pPacket->msgData.dataReq.srcAddrMode = myAddrMode;
pPacket->msgData.dataReq.msduLength = msduLength;
/* Request MAC level acknowledgement of the data packet */
pPacket->msgData.dataReq.txOptions = gTxOptsAck_c;
/* Give the data packet a handle. The handle is
returned in the MCPS-Data Confirm message. */
pPacket->msgData.dataReq.msduHandle = msduHandle++;

/* Send the Data Request to the MCPS */
NR MSG_Send(NWK_MCPS, pPacket);
/* Prepare for another data buffer */
MSG_Free(pPacket);
pPacket = NULL;
numPendingPackets++;
}
}
}
哦,这样啊,谢谢!
但是如果不free的话,中心点重启之后,end device重新发起关联但是不重启,关联上之后,中心点就能发送三次数据包,以后就申请不到内存空间了,并且发送的三次数据,end device都没有收到,现在不知道问题在哪?

[此贴子已经被作者于2006-9-11 8:44:47编辑过]

哦,知道了
但是现在要求是中心点重启的话,end device不能重启,我试试看看重连之前先发MLME_Reset行不行
“中心点相device是非直接方式,device没有取到数据的话,数据就一直在coordinator的缓存里面,缓存空间有限,所以三次以后就没有空间了。”
那为什么end device 会取不到数据呢?根本原因在哪呢?
device执行poll的操作了
我把coordinator的PanId,channel号和短地址都定死了,每次重启之后都是这些参数
目前好用了,谢谢seuafu2005,你真是帮了俺的大忙了[em12][em12]
to seuafu2005:
"一般来说中心点得不到device收到数据的ack的话,隔一定时间,好像要10秒以上,会自动丢弃数据的",如果发送几次之后没有内存空间了,返回null,那么以后隔一段时间(足够长的时间)再申请空间,还能申请到吗?还是就一直也申请不到了?我试了一下,好像是以后一直都申请不到了,这样岂不是死到这了?再次麻烦了,谢谢
呵呵,目前还没有找到如何修改设置,我只是在检测到关联断开之后就让device跳转到初始状态,相当于重启了
记得原来看过资料说:如果coordinator找不到device,它会保留数据,直到device poll它,它就可以发送数据了,是不是这样啊?
有道理
我这还是这样:如果申请不到空间的话,以后就一直申请不到。
还没有找到问题在哪
返回列表