1 /**
2 ******************************************************************************
3 * @file stm_list.c
4 * @author MCD Application Team
5 * @brief TCircular Linked List Implementation.
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2018-2021 STMicroelectronics.
10 * All rights reserved.
11 *
12 * This software is licensed under terms that can be found in the LICENSE file
13 * in the root directory of this software component.
14 * If no LICENSE file comes with this software, it is provided AS-IS.
15 *
16 ******************************************************************************
17 */
18
19
20 /******************************************************************************
21 * Include Files
22 ******************************************************************************/
23 #include "utilities_common.h"
24
25 #include "stm_list.h"
26
27 /******************************************************************************
28 * Function Definitions
29 ******************************************************************************/
LST_init_head(tListNode * listHead)30 void LST_init_head (tListNode * listHead)
31 {
32 listHead->next = listHead;
33 listHead->prev = listHead;
34 }
35
LST_is_empty(tListNode * listHead)36 uint8_t LST_is_empty (tListNode * listHead)
37 {
38 uint32_t primask_bit;
39 uint8_t return_value;
40
41 primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */
42 __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
43 if(listHead->next == listHead)
44 {
45 return_value = TRUE;
46 }
47 else
48 {
49 return_value = FALSE;
50 }
51 __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/
52
53 return return_value;
54 }
55
LST_insert_head(tListNode * listHead,tListNode * node)56 void LST_insert_head (tListNode * listHead, tListNode * node)
57 {
58 uint32_t primask_bit;
59
60 primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */
61 __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
62
63 node->next = listHead->next;
64 node->prev = listHead;
65 listHead->next = node;
66 (node->next)->prev = node;
67
68 __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/
69 }
70
71
LST_insert_tail(tListNode * listHead,tListNode * node)72 void LST_insert_tail (tListNode * listHead, tListNode * node)
73 {
74 uint32_t primask_bit;
75
76 primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */
77 __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
78
79 node->next = listHead;
80 node->prev = listHead->prev;
81 listHead->prev = node;
82 (node->prev)->next = node;
83
84 __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/
85 }
86
87
LST_remove_node(tListNode * node)88 void LST_remove_node (tListNode * node)
89 {
90 uint32_t primask_bit;
91
92 primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */
93 __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
94
95 (node->prev)->next = node->next;
96 (node->next)->prev = node->prev;
97
98 __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/
99 }
100
101
LST_remove_head(tListNode * listHead,tListNode ** node)102 void LST_remove_head (tListNode * listHead, tListNode ** node )
103 {
104 uint32_t primask_bit;
105
106 primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */
107 __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
108
109 *node = listHead->next;
110 LST_remove_node (listHead->next);
111
112 __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/
113 }
114
115
LST_remove_tail(tListNode * listHead,tListNode ** node)116 void LST_remove_tail (tListNode * listHead, tListNode ** node )
117 {
118 uint32_t primask_bit;
119
120 primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */
121 __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
122
123 *node = listHead->prev;
124 LST_remove_node (listHead->prev);
125
126 __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/
127 }
128
129
LST_insert_node_after(tListNode * node,tListNode * ref_node)130 void LST_insert_node_after (tListNode * node, tListNode * ref_node)
131 {
132 uint32_t primask_bit;
133
134 primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */
135 __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
136
137 node->next = ref_node->next;
138 node->prev = ref_node;
139 ref_node->next = node;
140 (node->next)->prev = node;
141
142 __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/
143 }
144
145
LST_insert_node_before(tListNode * node,tListNode * ref_node)146 void LST_insert_node_before (tListNode * node, tListNode * ref_node)
147 {
148 uint32_t primask_bit;
149
150 primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */
151 __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
152
153 node->next = ref_node;
154 node->prev = ref_node->prev;
155 ref_node->prev = node;
156 (node->prev)->next = node;
157
158 __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/
159 }
160
161
LST_get_size(tListNode * listHead)162 int LST_get_size (tListNode * listHead)
163 {
164 int size = 0;
165 tListNode * temp;
166 uint32_t primask_bit;
167
168 primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */
169 __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
170
171 temp = listHead->next;
172 while (temp != listHead)
173 {
174 size++;
175 temp = temp->next;
176 }
177
178 __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/
179
180 return (size);
181 }
182
LST_get_next_node(tListNode * ref_node,tListNode ** node)183 void LST_get_next_node (tListNode * ref_node, tListNode ** node)
184 {
185 uint32_t primask_bit;
186
187 primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */
188 __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
189
190 *node = ref_node->next;
191
192 __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/
193 }
194
195
LST_get_prev_node(tListNode * ref_node,tListNode ** node)196 void LST_get_prev_node (tListNode * ref_node, tListNode ** node)
197 {
198 uint32_t primask_bit;
199
200 primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */
201 __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/
202
203 *node = ref_node->prev;
204
205 __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/
206 }
207
208