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

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

有道理
我这还是这样:如果申请不到空间的话,以后就一直申请不到。
还没有找到问题在哪
我也来说说我的问题,呵呵 :
void App_TransmitData(void)
{
uint8_t msduLength = 0;
uint8_t morePackets = 1;
uint8_t deviceAddress = 0x01;
uint8_t ret;
static uint8_t dataBuffer[DEFAULT_DATA_LENGTH]; /* Prevent slow allocation on stack */

/* We transmit only if at least one device is associated. */
if(addressesMap == 0)
return;

/* Send packets only if we can send info to all End Devices */
if(numPendingPackets > 0)
{
if(packetDropped > 0)
{
Uart_Print("Packet dropped.\n");
packetDropped = 0;
}
return;
}

/* Get data to be transmitted from one source */
/* Try first the LED counter */
if(counterLEDsModified)
{
counterLEDsModified = FALSE;
packetDropped = FALSE;
dataBuffer[0] = counterLEDs & 0x0F;
msduLength = 1;
}
else
{
/* Else try to get data from the UART. */
msduLength = Uart_PollMessage(dataBuffer);
}

/* For every device associated, if there is still room in the queue
allocate and send a packet */
if(msduLength != 0)
{
/* Find the first associated end device. We have at least one.*/
while((deviceAddress & addressesMap) == 0)
{
deviceAddress = deviceAddress << 1;
}
/* Transmit packets to the devices */
do
{
morePackets = 0;
if (numPendingPackets < MAX_PENDING_DATA_PACKETS && NULL == pPacket)
{
pPacket = MSG_Alloc(sizeof(nwkToMcpsMessage_t) - 1 + DEFAULT_DATA_LENGTH);
if (pPacket != NULL)
{
/* Create an MCPS-Data Request message containing the data. */
pPacket->msgType = gMcpsDataReq_c;
/* Copy data to be sent to packet */
memcpy(pPacket->msgData.dataReq.msdu, (void *)dataBuffer, msduLength);
/* Create the header using device information stored when creating
the association response. In this simple example the use of short
addresses is hardcoded. In a real world application we must be
flexible, and use the address mode required by the given situation. */
pPacket->msgData.dataReq.dstAddr[0] = deviceAddress;
pPacket->msgData.dataReq.dstAddr[1] = 0;
memcpy(pPacket->msgData.dataReq.srcAddr, (void *)shortAddress, 2);
memcpy(pPacket->msgData.dataReq.dstPanId, (void *)panId, 2);
memcpy(pPacket->msgData.dataReq.srcPanId, (void *)panId, 2);
pPacket->msgData.dataReq.dstAddrMode = gAddrModeShort_c;
pPacket->msgData.dataReq.srcAddrMode = gAddrModeShort_c;
pPacket->msgData.dataReq.msduLength = msduLength;
/* Request MAC level acknowledgement, and
indirect transmission of the data packet */
pPacket->msgData.dataReq.txOptions = gTxOptsAck_c | gTxOptsIndirect_c;
/* Give the data packet a handle. The handle is
returned in the MCPS-Data Confirm message. */
pPacket->msgData.dataReq.msduHandle = msduHandle++;
/* Add the packet to tracking list in the purger module. */
ret = Purger_Track(pPacket->msgData.dataReq.msduHandle, 0, deviceAddress, counterLEDs);
/* Send the Data Request to the MCPS */
NR MSG_Send(NWK_MCPS, pPacket);
/* Prepare for another data buffer */
pPacket = NULL;
numPendingPackets++;
/* Move to next associated device */
do
{
deviceAddress = deviceAddress << 1;
}
while(((deviceAddress & addressesMap) == 0) && (deviceAddress < 0x10));
/* Continue if we haven't passed the last possible device address. */
morePackets = deviceAddress < 0x10;
}
else
{
Uart_Print("Packet NULL.\n");
}
}
}
while (morePackets);
}
}
就是星型网络中协调器发送数据的函数,从代码看是支持四个END Device,其地址为01,02,04,08。协调器往end device中发送数据,但是当连接上第4个时候,向第4个end device发送数据时候会出现 Packet NULL。前面3个都能正常发送数据的
返回列表