2 * Copyright 2018-2019 NXP
\r
3 * All rights reserved.
\r
6 * SPDX-License-Identifier: BSD-3-Clause
\r
9 #ifndef _GENERIC_LIST_H_
\r
10 #define _GENERIC_LIST_H_
\r
13 * @addtogroup GenericList
\r
17 /*!*********************************************************************************
\r
18 *************************************************************************************
\r
20 *************************************************************************************
\r
21 ********************************************************************************** */
\r
23 /*! *********************************************************************************
\r
24 *************************************************************************************
\r
25 * Public macro definitions
\r
26 *************************************************************************************
\r
27 ********************************************************************************** */
\r
29 /*! *********************************************************************************
\r
30 *************************************************************************************
\r
31 * Public type definitions
\r
32 *************************************************************************************
\r
33 ********************************************************************************** */
\r
34 /*! @brief The list status */
\r
35 typedef enum _list_status
\r
37 kLIST_Ok = kStatus_Success, /*!< Success */
\r
38 kLIST_DuplicateError = MAKE_STATUS(kStatusGroup_LIST, 1), /*!< Duplicate Error */
\r
39 kLIST_Full = MAKE_STATUS(kStatusGroup_LIST, 2), /*!< FULL */
\r
40 kLIST_Empty = MAKE_STATUS(kStatusGroup_LIST, 3), /*!< Empty */
\r
41 kLIST_OrphanElement = MAKE_STATUS(kStatusGroup_LIST, 4), /*!< Orphan Element */
\r
44 /*! @brief The list structure*/
\r
45 typedef struct list_tag
\r
47 struct list_element_tag *head; /*!< list head */
\r
48 struct list_element_tag *tail; /*!< list tail */
\r
49 uint16_t size; /*!< list size */
\r
50 uint16_t max; /*!< list max number of elements */
\r
51 } list_t, *list_handle_t;
\r
53 /*! @brief The list element*/
\r
54 typedef struct list_element_tag
\r
56 struct list_element_tag *next; /*!< next list element */
\r
57 struct list_element_tag *prev; /*!< previous list element */
\r
58 struct list_tag *list; /*!< pointer to the list */
\r
59 } list_element_t, *list_element_handle_t;
\r
61 /*! *********************************************************************************
\r
62 *************************************************************************************
\r
64 *************************************************************************************
\r
65 ********************************************************************************** */
\r
66 /*******************************************************************************
\r
68 ******************************************************************************/
\r
70 #if defined(__cplusplus)
\r
72 #endif /* _cplusplus */
\r
74 * @brief Initialize the list.
\r
76 * This function initialize the list.
\r
78 * @param list - List handle to initialize.
\r
79 * @param max - Maximum number of elements in list. 0 for unlimited.
\r
81 void LIST_Init(list_handle_t list, uint32_t max);
\r
84 * @brief Gets the list that contains the given element.
\r
87 * @param element - Handle of the element.
\r
88 * @retval NULL if element is orphan, Handle of the list the element is inserted into.
\r
90 list_handle_t LIST_GetList(list_element_handle_t element);
\r
93 * @brief Links element to the head of the list.
\r
95 * @param list - Handle of the list.
\r
96 * @param element - Handle of the element.
\r
97 * @retval kLIST_Full if list is full, kLIST_Ok if insertion was successful.
\r
99 list_status_t LIST_AddHead(list_handle_t list, list_element_handle_t element);
\r
102 * @brief Links element to the tail of the list.
\r
104 * @param list - Handle of the list.
\r
105 * @param element - Handle of the element.
\r
106 * @retval kLIST_Full if list is full, kLIST_Ok if insertion was successful.
\r
108 list_status_t LIST_AddTail(list_handle_t list, list_element_handle_t element);
\r
111 * @brief Unlinks element from the head of the list.
\r
113 * @param list - Handle of the list.
\r
115 * @retval NULL if list is empty, handle of removed element(pointer) if removal was successful.
\r
117 list_element_handle_t LIST_RemoveHead(list_handle_t list);
\r
120 * @brief Gets head element handle.
\r
122 * @param list - Handle of the list.
\r
124 * @retval NULL if list is empty, handle of removed element(pointer) if removal was successful.
\r
126 list_element_handle_t LIST_GetHead(list_handle_t list);
\r
129 * @brief Gets next element handle for given element handle.
\r
131 * @param element - Handle of the element.
\r
133 * @retval NULL if list is empty, handle of removed element(pointer) if removal was successful.
\r
135 list_element_handle_t LIST_GetNext(list_element_handle_t element);
\r
138 * @brief Gets previous element handle for given element handle.
\r
140 * @param element - Handle of the element.
\r
142 * @retval NULL if list is empty, handle of removed element(pointer) if removal was successful.
\r
144 list_element_handle_t LIST_GetPrev(list_element_handle_t element);
\r
147 * @brief Unlinks an element from its list.
\r
149 * @param element - Handle of the element.
\r
151 * @retval kLIST_OrphanElement if element is not part of any list.
\r
152 * @retval kLIST_Ok if removal was successful.
\r
154 list_status_t LIST_RemoveElement(list_element_handle_t element);
\r
157 * @brief Links an element in the previous position relative to a given member of a list.
\r
159 * @param element - Handle of the element.
\r
160 * @param newElement - New element to insert before the given member.
\r
162 * @retval kLIST_OrphanElement if element is not part of any list.
\r
163 * @retval kLIST_Ok if removal was successful.
\r
165 list_status_t LIST_AddPrevElement(list_element_handle_t element, list_element_handle_t newElement);
\r
168 * @brief Gets the current size of a list.
\r
170 * @param list - Handle of the list.
\r
172 * @retval Current size of the list.
\r
174 uint32_t LIST_GetSize(list_handle_t list);
\r
177 * @brief Gets the number of free places in the list.
\r
179 * @param list - Handle of the list.
\r
181 * @retval Available size of the list.
\r
183 uint32_t LIST_GetAvailableSize(list_handle_t list);
\r
187 #if defined(__cplusplus)
\r
191 #endif /*_GENERIC_LIST_H_*/
\r