📄 buffer.c
字号:
/********************************************************************************/
/* filename: buffer.c */
/* created : hw-chen */
/********************************************************************************/
#include "com_inc.h"
st_buffer_node buffer_node[MAX_BUFF];
st_buffer_list free_buffer_list;
/********************************************************************************/
/* function : buffer_list_initialize() */
/* created : hw-chen */
/* descript : initialize the free buffer list */
/********************************************************************************/
void buffer_list_initialize(void)
{ int i=0x0;
free_buffer_list.head=null;
free_buffer_list.tail=null;
while(i<MAX_BUFF)
{ list_add_tail(&free_buffer_list,&buffer_node[i++]);
}
}
/********************************************************************************/
/* function : get_node_from_pool() */
/* created : hw-chen */
/* descript : 从POOL里面取出一个节点 */
/********************************************************************************/
st_buffer_node * get_node_from_pool(void)
{ return list_del_head(&free_buffer_list);
}
/********************************************************************************/
/* function : set_node_to_pool() */
/* created : hw-chen */
/* descript : 把一个自由节点放回到POOL里面 */
/********************************************************************************/
void set_node_to_pool(st_buffer_node * node)
{ list_add_tail(&free_buffer_list,node);
}
/********************************************************************************/
/* function : list_add_tail() */
/* created : hw-chen */
/* descript : Add a new entry after the specified list's tail but it is must */
/* less max */
/********************************************************************************/
void list_add_tail(st_buffer_list * list, st_buffer_node * node)
{ if( list->tail==null)
{ list->head=node;
list->tail=node;
node->prev=null;
node->next=null;
}
else
{ list->tail->next=node;
node->prev=list->tail;
node->next=null;
list->tail=node;
}
}
/********************************************************************************/
/* function : list_add_head() */
/* created : hw-chen */
/* descript : Add a new entry after the specified list's tail but it is must */
/* less max */
/********************************************************************************/
void list_add_head(st_buffer_list * list, st_buffer_node * node)
{ if( list->head==null)
{ list->head=node;
list->tail=node;
node->prev=null;
node->next=null;
}
else
{ list->head->prev=node;
node->next=list->head;
node->prev=null;
list->head=node;
}
}
/********************************************************************************/
/* function : list_add_between() */
/* created : hw-chen */
/* descript : Add a new entry after the specified list's tail but it is must */
/* less max */
/********************************************************************************/
void list_add_between(st_buffer_node * prev, st_buffer_node * next, st_buffer_node * node)
{ prev->next=node;
node->prev=prev;
node->next=next;
next->prev=node;
}
/********************************************************************************/
/* function : list_del_head() */
/* created : hw-chen */
/* descript : remove entry from the specified list's head . */
/********************************************************************************/
st_buffer_node * list_del_head(st_buffer_list * list)
{ st_buffer_node * head;
head=list->head;
if( list->head==null)
{ return null;
}
if( list->head==list->tail)
{ list->head=null;
list->tail=null;
return head;
}
else
{ list->head=head->next;
list->head->prev=null;
return head;
}
}
/********************************************************************************/
/* function : list_get_buffer() */
/* created : hw-chen */
/* descript : get and remove entry from the specified list's head . */
/********************************************************************************/
st_buffer_node * list_get_buffer(st_buffer_list * list)
{ return list_del_head(list);
}
/********************************************************************************/
/* function : list_search_sequence() */
/* created : hw-chen */
/* descript : remove entry from the specified list's head . */
/********************************************************************************/
int list_search_sequence(st_buffer_list * list, st_buffer_node * node,st_buffer_node ** prev, st_buffer_node ** next)
{ st_buffer_node * nxt1;
st_buffer_node * nxt2;
nxt1=list->head;
nxt2=nxt1->next;
while(nxt2!=null)
{ if((node->sequence>nxt1->sequence)&&(node->sequence<nxt2->sequence))
{ break;
}
if(node->sequence<=nxt1->sequence)
{ nxt2=null;
break;
}
nxt1=nxt2;
nxt2=nxt2->next;
}
if(nxt2==null)
{ msg_addr_value(prev,null);
msg_addr_value(next,null);
return ERR_ERROR;
}
else
{ msg_addr_value(prev,nxt1);
msg_addr_value(next,nxt2);
return 0x1;
}
}
/********************************************************************************/
/* function : list_add_sequence() */
/* created : hw-chen */
/* descript : remove entry from the specified list's head . */
/********************************************************************************/
int list_add_sequence(st_buffer_list * list, st_buffer_node * node)
{ st_buffer_node * prev;
st_buffer_node * next;
if( list_search_sequence(list,node,&prev,&next)==0x1)
{ list_add_between(prev,next,node);
return 0x1;
}
else
{ return ERR_ERROR;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -