我的程序中有如下一段代码,程序执行一段时间后给结构体node的成员赋值失败。请大家分析一下是什么原因呢?就是进行高压测试后,给node的成员赋值,而(node->Protocmd).header等成员虽然赋值了,但任然是0。
void AddCmdNode(uint8_t direction, uint8_t msgref, uint8_t msgcmd,
uint8_t length, uint8_t *data)
{
uint8_t i;
OS_ERR err;
CMD_LIST *node = NULL;
CMD_LIST *ptr = NULL;
CMD_LIST *pptr = NULL;
ProtocolCmd protocmd;
ProtocolCmd *newcmd = &protocmd;
CPU_TS ts;
OSSemPend(&CmdSem,0,OS_OPT_PEND_BLOCKING, &ts, &err);
//*****************校验链表长度,防止内存无止境增加***********************//
if(GetCmdListLen() < 10) /*------8个内存块,再除去一个头节点-----*/
{
//******************组合命令********************************//
newcmd->header = 0xAA;
newcmd->checksum = 0xAA;
newcmd->direction = direction;
newcmd->checksum += direction;
newcmd->msgref = msgref;
newcmd->checksum += msgref;
newcmd->msgcmd = msgcmd;
newcmd->checksum += msgcmd;
newcmd->length = length;
newcmd->checksum += length;
for(i = 0; i < length; i++)
{
newcmd->data[i] = data[i];
newcmd->checksum += data[i];
}
newcmd->dataindex = 0;
/*
************************增加节点************************
*/
ptr = head->next;
while (ptr != NULL)
{
if(IS_CMD_SAME(ptr, newcmd)) //有相同命令则不增加
{
(ptr->ProtoCmd).dataindex = 0;
break;
}
ptr = ptr->next;
}
if(ptr == NULL) //没有相同
{
node = (CMD_LIST *)OSMemGet(&CmdTXList, &err); //申请内存
if(node != NULL)
{
/*------------清0--------------*/
node->next = NULL;
//memset(node, 0, CMDLISTLEN);
(node->ProtoCmd).header = 0xAA;
(node->ProtoCmd).checksum = 0xAA;
(node->ProtoCmd).direction = direction;
(node->ProtoCmd).checksum += direction;
(node->ProtoCmd).msgref = msgref;
(node->ProtoCmd).checksum += msgref;
(node->ProtoCmd).msgcmd = msgcmd;
(node->ProtoCmd).checksum += msgcmd;
(node->ProtoCmd).length = length;
(node->ProtoCmd).checksum += length;
for(i = 0; i < length; i++)
{
(node->ProtoCmd).data[i] = data[i];
(node->ProtoCmd).checksum += data[i];
}
(node->ProtoCmd).dataindex = 0;
/* ***************在尾部插入一个节点************************* */
pptr = head;
while (pptr->next != NULL)
{
pptr = pptr->next;
}
pptr->next = node;
node->next = NULL;
}
}
}
OSSemPost(&CmdSem,OS_OPT_POST_1, &err);
}
此帖出自
小平头技术问答
一周热门 更多>