Blame view

Common/gen_linklist.c 2.48 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();//	
aed5e827   李外   V100.0.8
13
14
15
16
17
18
  //    if(*malloc == 0) 
  //    {
  //        platform.enable_interrupt();
  //			return 0;
  //    }
      basic_delay_ms(1);
9d8bbd1c   李外   改升级前备份
19
20
21
      GenLinkNode *node = (GenLinkNode *)malloc(sizeof(GenLinkNode));
  		
  		while(node ==NULL){//debug only
32fa5493   李外   移植快速下发完成,快速下发与17信...
22
23
24
  //			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   李外   改升级前备份
25
26
27
28
29
30
31
32
33
34
35
36
37
  			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;
9d8bbd1c   李外   改升级前备份
38
      (list->length)++;  
aed5e827   李外   V100.0.8
39
40
      platform.enable_interrupt();//platform__system_intf.enable_INT();//
      
9d8bbd1c   李外   改升级前备份
41
42
43
44
45
46
47
48
49
      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信...
50
      platform.disable_interrupt();//platform__system_intf.disable_INT();//
9d8bbd1c   李外   改升级前备份
51
52
53
54
55
56
57
58
59
60
61
      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信...
62
      platform.enable_interrupt();//platform__system_intf.enable_INT();//		
9d8bbd1c   李外   改升级前备份
63
64
65
66
67
68
69
70
71
72
73
74
      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
75
          //if(pnode_tmp->next != NULL)
9d8bbd1c   李外   改升级前备份
76
77
          pnode_tmp =pnode_tmp->next;
      }//for
0f1254c7   李外   V100.0.5
78
  		if(pnode_tmp != NULL)
9d8bbd1c   李外   改升级前备份
79
      return pnode_tmp->pdata;
0f1254c7   李外   V100.0.5
80
81
  		else
  			return NULL;
9d8bbd1c   李外   改升级前备份
82
83
84
85
86
87
88
89
90
  }
  
  /*-------------- get len ------------------------------
  * get length of linklist 
  */
  unsigned short gen_linklist__get_len(GenLinkList* const list)
  {
      return list->length;
  }