2 * Copyright (c) 2015, Texas Instruments Incorporated
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * ======== List.c ========
35 #include <ti/drivers/dpl/HwiP.h>
36 #include <ti/drivers/utils/List.h>
43 * ======== List_clearList ========
45 void List_clearList(List_List *list)
47 list->head = list->tail = NULL;
51 * ======== List_empty ========
53 bool List_empty(List_List *list)
55 return (list->head == NULL);
59 * ======== List_get ========
61 List_Elem *List_get(List_List *list)
70 /* See if the List was empty */
72 list->head = elem->next;
73 if (elem->next != NULL) {
74 elem->next->prev = NULL;
87 * ======== List_head ========
89 List_Elem *List_head(List_List *list)
95 * ======== List_insert ========
97 void List_insert(List_List *list, List_Elem *newElem, List_Elem *curElem)
99 newElem->next = curElem;
100 newElem->prev = curElem->prev;
101 if (curElem->prev != NULL) {
102 curElem->prev->next = newElem;
105 list->head = newElem;
107 curElem->prev = newElem;
111 * ======== List_next ========
113 List_Elem *List_next(List_Elem *elem)
119 * ======== List_prev ========
121 List_Elem *List_prev(List_Elem *elem)
127 * ======== List_put ========
129 void List_put(List_List *list, List_Elem *elem)
133 key = HwiP_disable();
136 elem->prev = list->tail;
137 if (list->tail != NULL) {
138 list->tail->next = elem;
150 * ======== List_putHead ========
152 void List_putHead(List_List *list, List_Elem *elem)
156 key = HwiP_disable();
158 elem->next = list->head;
160 if (list->head != NULL) {
161 list->head->prev = elem;
173 * ======== List_remove ========
175 void List_remove(List_List *list, List_Elem *elem)
177 /* Handle the case where the elem to remove is the last one */
178 if (elem->next == NULL) {
179 list->tail = elem->prev;
182 elem->next->prev = elem->prev;
185 /* Handle the case where the elem to remove is the first one */
186 if (elem->prev == NULL) {
187 list->head = elem->next;
190 elem->prev->next = elem->next;
195 * ======== List_tail ========
197 List_Elem *List_tail(List_List *list)