大学生
最后登录1970-1-1
在线时间 小时
注册时间2013-7-16
|
我实现了一个链表,不在任务中调用一切正常,但是如果在任务中使用这个链表就会导致 HardFault_Handler 这个错误,下面是代码,请各位大佬帮忙看下,谢谢 !
[mw_shl_code=c,true]/****************************
功能: 初始化链表
说明:
****************************/
fingertech_node* Fingertech_listInit(void)
{
fingertech_node* list = NULL;
list = (fingertech_node*)pvPortMalloc(sizeof(fingertech_node));
if (list == NULL)
{
return NULL;
}
memset(list,0xff,sizeof(fingertech_node));
list->next = NULL;
return list;
}
/****************************
功能: 向链表钟添加元素
说明:
****************************/
uint32_t Fingertech_listadd(fingertech_node **head, fingertech_node *list)
{
fingertech_node *temp = NULL;
//判断链表是否为空
if (NULL == *head)
{
FingerTech_Loge("Fingertech_listadd is NULL\r\n");
*head = list;
(*head)->next = NULL;
}
else
{
FingerTech_Loge("Fingertech_listadd is ssss\r\n");
temp = *head;
while (temp)
{
if (NULL == temp->next)
{
temp->next = list;
list->next = NULL;
}
temp = temp->next;
}
}
return FINGERTECH_SUCCESS;
}
/****************************
功能: 删除元素
说明:
****************************/
uint32_t FingerTech_listdel(fingertech_node **head, uint16_t fingertempnum)
{
fingertech_node *temp, *p;
temp = *head;
if (NULL == temp)
{
return FINGERTECH_LISTERR;
}
else
{
//判断匹配的元素是否为链表的头部元素
if (fingertempnum == temp->fingertempnum)
{
*head = temp->next;
}
else
{
while (temp->next)
{
p = temp;
temp = temp->next;
if (fingertempnum == temp->fingertempnum)
{
p->next = temp->next;
return FINGERTECH_SUCCESS;
}
}
return FINGERTECH_LISTERR;
}
}
return FINGERTECH_LISTERR;
}
/****************************
功能: 修改元素值
说明:
****************************/
uint32_t FingerTech_listmodify(fingertech_node **head, uint16_t fingertempnum, uint32_t fingertempsize)
{
fingertech_node *temp;
//头部作为临时变量
temp = *head;
while (temp)
{
if (fingertempnum == temp->fingertempnum)
{
temp->fingertempsize = fingertempsize;
return FINGERTECH_SUCCESS;
}
temp = temp->next;
}
return FINGERTECH_LISTERR;
}
/****************************
功能: 查找元素
说明:
****************************/
uint32_t FingerTech_listfind(fingertech_node **head, uint16_t fingertempnum)
{
fingertech_node* temp;
temp = *head;
while (temp)
{
if (fingertempnum == temp->fingertempnum)
{
return temp->fingertempsize;
}
temp = temp->next;
}
return FINGERTECH_LISTERR;
}
/****************************
功能: 打印链表值
说明:
****************************/
void FingerTech_listPrint(fingertech_node **head)
{
fingertech_node *temp;
temp = *head;
FingerTech_Logi("list information:\n");
while (temp)
{
FingerTech_Logi("list %d : %d\r\n",temp->fingertempnum,temp->fingertempsize);
temp = temp->next;
}
}
/****************************
功能: 获取链表长度
说明:
****************************/
uint8_t FingerTech_Getlistlen(fingertech_node **head)
{
fingertech_node *temp;
uint32_t count = 0;
temp = *head;
while (temp)
{
count++;
temp = temp->next;
}
return count;
}
/****************************
功能: 获取链表中空余的最小的ID
说明:
****************************/
uint8_t FingerTech_GetlistminID(fingertech_node **head)
{
fingertech_node *temp;
uint8_t tempid = 0xa0;
uint8_t idtemp[10] = { 0,1,2,3,4,5,6,7,8,9 };
uint8_t count = 0;
temp = *head;
FingerTech_Logi("get listmin id \r\n");
while (temp)
{
idtemp[temp->fingertempnum] = 0xff;
temp = temp->next;
}
for (count = 0; count<10; count++)
{
if (tempid > idtemp[count])
{
tempid = idtemp[count];
}
}
return tempid;
}
[/mw_shl_code]
|
|