Blame view

Common/gen_linklist.c 2.36 KB
9d8bbd1c   李外   改升级前备份
1
  #include    "gen_linklist.h"
32fa5493   李外   移植快速下发完成,快速下发与17信...
2
  #include "platform.h"
9d8bbd1c   李外   改升级前备份
3
4
5
  
  // https://blog.csdn.net/swwlqw/article/details/22498833
  
9d8bbd1c   李外   改升级前备份
6
7
8
9
10
11
  /*-------------- insert ------------------------------
  * insert data to any postion
  */
  unsigned char gen_linklist__insert(GenLinkList* const list,void *pele,unsigned short index)
  {
      if(list->length < index) return 0;
32fa5493   李外   移植快速下发完成,快速下发与17信...
12
      platform.disable_interrupt();//platform__system_intf.disable_INT();//	
9d8bbd1c   李外   改升级前备份
13
14
15
      GenLinkNode *node = (GenLinkNode *)malloc(sizeof(GenLinkNode));
  		
  		while(node ==NULL){//debug only
32fa5493   李外   移植快速下发完成,快速下发与17信...
16
17
18
  //			my_debug.printf_error("gen_linklist__insert() malloc fail \n");
  			//platform__system_intfp->delay_ms(500);
  			platform.enable_interrupt();//platform__system_intf.enable_INT();//
9d8bbd1c   李外   改升级前备份
19
20
21
22
23
24
25
26
27
28
29
30
31
  			return 0;
  		}
  	
      node->next = NULL;
      node->pdata = pele;
  
      GenLinkNode *pnode_tmp= list->front;
      for(unsigned short i=0;i<index;i++){
          pnode_tmp =pnode_tmp->next;
      }//for
  
      node->next =pnode_tmp->next;
      pnode_tmp->next =node;
32fa5493   李外   移植快速下发完成,快速下发与17信...
32
      platform.enable_interrupt();//platform__system_intf.enable_INT();//
9d8bbd1c   李外   改升级前备份
33
34
35
36
37
38
39
40
41
42
43
      (list->length)++;  
  
      return 1;  
  }
  
  /* -------------- detele  ------------------------------
  * detele node at any postion
  */
  void* gen_linklist__detele(GenLinkList* const list,unsigned short index)
  {
      if(list->length < index) return NULL;
32fa5493   李外   移植快速下发完成,快速下发与17信...
44
      platform.disable_interrupt();//platform__system_intf.disable_INT();//
9d8bbd1c   李外   改升级前备份
45
46
47
48
49
50
51
52
53
54
55
      GenLinkNode *pnode_tmp= list->front;
      for(unsigned short i=0;i<index;i++){
          pnode_tmp =pnode_tmp->next;
      }//for
  
      GenLinkNode *pnode_record= pnode_tmp->next;
      pnode_tmp->next = pnode_tmp->next->next;
      void * re =pnode_record->pdata;
      free(pnode_record);
  		if(list->length)
  			(list->length)--;
32fa5493   李外   移植快速下发完成,快速下发与17信...
56
      platform.enable_interrupt();//platform__system_intf.enable_INT();//		
9d8bbd1c   李外   改升级前备份
57
58
59
60
61
62
63
64
65
66
67
68
      return re;
  }
  
  /*-------------- get ele ------------------------------
  * get element of index;
  */
  void* gen_linklist__get_ele(GenLinkList* const list,unsigned short index)
  {
      if( list->length < index) return NULL;
  
      GenLinkNode *pnode_tmp= list->front->next;//diff with no head
      for(unsigned short i=0;i<index;i++){
0f1254c7   李外   V100.0.5
69
          //if(pnode_tmp->next != NULL)
9d8bbd1c   李外   改升级前备份
70
71
          pnode_tmp =pnode_tmp->next;
      }//for
0f1254c7   李外   V100.0.5
72
  		if(pnode_tmp != NULL)
9d8bbd1c   李外   改升级前备份
73
      return pnode_tmp->pdata;
0f1254c7   李外   V100.0.5
74
75
  		else
  			return NULL;
9d8bbd1c   李外   改升级前备份
76
77
78
79
80
81
82
83
84
  }
  
  /*-------------- get len ------------------------------
  * get length of linklist 
  */
  unsigned short gen_linklist__get_len(GenLinkList* const list)
  {
      return list->length;
  }