2 FreeRTOS V6.0.5 - Copyright (C) 2010 Real Time Engineers Ltd.
\r
4 ***************************************************************************
\r
8 * + New to FreeRTOS, *
\r
9 * + Wanting to learn FreeRTOS or multitasking in general quickly *
\r
10 * + Looking for basic training, *
\r
11 * + Wanting to improve your FreeRTOS skills and productivity *
\r
13 * then take a look at the FreeRTOS eBook *
\r
15 * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
\r
16 * http://www.FreeRTOS.org/Documentation *
\r
18 * A pdf reference manual is also available. Both are usually delivered *
\r
19 * to your inbox within 20 minutes to two hours when purchased between 8am *
\r
20 * and 8pm GMT (although please allow up to 24 hours in case of *
\r
21 * exceptional circumstances). Thank you for your support! *
\r
23 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 ***NOTE*** The exception to the GPL is included to allow you to distribute
\r
31 a combined work that includes FreeRTOS without being obliged to provide the
\r
32 source code for proprietary components outside of the FreeRTOS kernel.
\r
33 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
34 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
35 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
55 * This is the list implementation used by the scheduler. While it is tailored
\r
56 * heavily for the schedulers needs, it is also available for use by
\r
59 * xLists can only store pointers to xListItems. Each xListItem contains a
\r
60 * numeric value (xItemValue). Most of the time the lists are sorted in
\r
61 * descending item value order.
\r
63 * Lists are created already containing one list item. The value of this
\r
64 * item is the maximum possible that can be stored, it is therefore always at
\r
65 * the end of the list and acts as a marker. The list member pxHead always
\r
66 * points to this marker - even though it is at the tail of the list. This
\r
67 * is because the tail contains a wrap back pointer to the true head of
\r
70 * In addition to it's value, each list item contains a pointer to the next
\r
71 * item in the list (pxNext), a pointer to the list it is in (pxContainer)
\r
72 * and a pointer to back to the object that contains it. These later two
\r
73 * pointers are included for efficiency of list manipulation. There is
\r
74 * effectively a two way link between the object containing the list item and
\r
75 * the list item itself.
\r
78 * \page ListIntroduction List Implementation
\r
79 * \ingroup FreeRTOSIntro
\r
85 + Included local const within listGET_OWNER_OF_NEXT_ENTRY() to assist
\r
86 compiler with optimisation. Thanks B.R.
\r
96 * Definition of the only type of object that a list can contain.
\r
100 portTickType xItemValue; /*< The value being listed. In most cases this is used to sort the list in descending order. */
\r
101 volatile struct xLIST_ITEM * pxNext; /*< Pointer to the next xListItem in the list. */
\r
102 volatile struct xLIST_ITEM * pxPrevious;/*< Pointer to the previous xListItem in the list. */
\r
103 void * pvOwner; /*< Pointer to the object (normally a TCB) that contains the list item. There is therefore a two way link between the object containing the list item and the list item itself. */
\r
104 void * pvContainer; /*< Pointer to the list in which this list item is placed (if any). */
\r
106 typedef struct xLIST_ITEM xListItem; /* For some reason lint wants this as two separate definitions. */
\r
108 struct xMINI_LIST_ITEM
\r
110 portTickType xItemValue;
\r
111 volatile struct xLIST_ITEM *pxNext;
\r
112 volatile struct xLIST_ITEM *pxPrevious;
\r
114 typedef struct xMINI_LIST_ITEM xMiniListItem;
\r
117 * Definition of the type of queue used by the scheduler.
\r
119 typedef struct xLIST
\r
121 volatile unsigned portBASE_TYPE uxNumberOfItems;
\r
122 volatile xListItem * pxIndex; /*< Used to walk through the list. Points to the last item returned by a call to pvListGetOwnerOfNextEntry (). */
\r
123 volatile xMiniListItem xListEnd; /*< List item that contains the maximum possible item value meaning it is always at the end of the list and is therefore used as a marker. */
\r
127 * Access macro to set the owner of a list item. The owner of a list item
\r
128 * is the object (usually a TCB) that contains the list item.
\r
130 * \page listSET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER
\r
131 * \ingroup LinkedList
\r
133 #define listSET_LIST_ITEM_OWNER( pxListItem, pxOwner ) ( pxListItem )->pvOwner = ( void * ) pxOwner
\r
136 * Access macro to set the value of the list item. In most cases the value is
\r
137 * used to sort the list in descending order.
\r
139 * \page listSET_LIST_ITEM_VALUE listSET_LIST_ITEM_VALUE
\r
140 * \ingroup LinkedList
\r
142 #define listSET_LIST_ITEM_VALUE( pxListItem, xValue ) ( pxListItem )->xItemValue = xValue
\r
145 * Access macro the retrieve the value of the list item. The value can
\r
146 * represent anything - for example a the priority of a task, or the time at
\r
147 * which a task should be unblocked.
\r
149 * \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE
\r
150 * \ingroup LinkedList
\r
152 #define listGET_LIST_ITEM_VALUE( pxListItem ) ( ( pxListItem )->xItemValue )
\r
155 * Access macro to determine if a list contains any items. The macro will
\r
156 * only have the value true if the list is empty.
\r
158 * \page listLIST_IS_EMPTY listLIST_IS_EMPTY
\r
159 * \ingroup LinkedList
\r
161 #define listLIST_IS_EMPTY( pxList ) ( ( pxList )->uxNumberOfItems == ( unsigned portBASE_TYPE ) 0 )
\r
164 * Access macro to return the number of items in the list.
\r
166 #define listCURRENT_LIST_LENGTH( pxList ) ( ( pxList )->uxNumberOfItems )
\r
169 * Access function to obtain the owner of the next entry in a list.
\r
171 * The list member pxIndex is used to walk through a list. Calling
\r
172 * listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list
\r
173 * and returns that entries pxOwner parameter. Using multiple calls to this
\r
174 * function it is therefore possible to move through every item contained in
\r
177 * The pxOwner parameter of a list item is a pointer to the object that owns
\r
178 * the list item. In the scheduler this is normally a task control block.
\r
179 * The pxOwner parameter effectively creates a two way link between the list
\r
180 * item and its owner.
\r
182 * @param pxList The list from which the next item owner is to be returned.
\r
184 * \page listGET_OWNER_OF_NEXT_ENTRY listGET_OWNER_OF_NEXT_ENTRY
\r
185 * \ingroup LinkedList
\r
187 #define listGET_OWNER_OF_NEXT_ENTRY( pxTCB, pxList ) \
\r
189 xList * const pxConstList = pxList; \
\r
190 /* Increment the index to the next item and return the item, ensuring */ \
\r
191 /* we don't return the marker used at the end of the list. */ \
\r
192 ( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext; \
\r
193 if( ( pxConstList )->pxIndex == ( xListItem * ) &( ( pxConstList )->xListEnd ) ) \
\r
195 ( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext; \
\r
197 pxTCB = ( pxConstList )->pxIndex->pvOwner; \
\r
202 * Access function to obtain the owner of the first entry in a list. Lists
\r
203 * are normally sorted in ascending item value order.
\r
205 * This function returns the pxOwner member of the first item in the list.
\r
206 * The pxOwner parameter of a list item is a pointer to the object that owns
\r
207 * the list item. In the scheduler this is normally a task control block.
\r
208 * The pxOwner parameter effectively creates a two way link between the list
\r
209 * item and its owner.
\r
211 * @param pxList The list from which the owner of the head item is to be
\r
214 * \page listGET_OWNER_OF_HEAD_ENTRY listGET_OWNER_OF_HEAD_ENTRY
\r
215 * \ingroup LinkedList
\r
217 #define listGET_OWNER_OF_HEAD_ENTRY( pxList ) ( ( pxList->uxNumberOfItems != ( unsigned portBASE_TYPE ) 0 ) ? ( (&( pxList->xListEnd ))->pxNext->pvOwner ) : ( NULL ) )
\r
220 * Check to see if a list item is within a list. The list item maintains a
\r
221 * "container" pointer that points to the list it is in. All this macro does
\r
222 * is check to see if the container and the list match.
\r
224 * @param pxList The list we want to know if the list item is within.
\r
225 * @param pxListItem The list item we want to know if is in the list.
\r
226 * @return pdTRUE is the list item is in the list, otherwise pdFALSE.
\r
229 #define listIS_CONTAINED_WITHIN( pxList, pxListItem ) ( ( pxListItem )->pvContainer == ( void * ) pxList )
\r
232 * Must be called before a list is used! This initialises all the members
\r
233 * of the list structure and inserts the xListEnd item into the list as a
\r
234 * marker to the back of the list.
\r
236 * @param pxList Pointer to the list being initialised.
\r
238 * \page vListInitialise vListInitialise
\r
239 * \ingroup LinkedList
\r
241 void vListInitialise( xList *pxList );
\r
244 * Must be called before a list item is used. This sets the list container to
\r
245 * null so the item does not think that it is already contained in a list.
\r
247 * @param pxItem Pointer to the list item being initialised.
\r
249 * \page vListInitialiseItem vListInitialiseItem
\r
250 * \ingroup LinkedList
\r
252 void vListInitialiseItem( xListItem *pxItem );
\r
255 * Insert a list item into a list. The item will be inserted into the list in
\r
256 * a position determined by its item value (descending item value order).
\r
258 * @param pxList The list into which the item is to be inserted.
\r
260 * @param pxNewListItem The item to that is to be placed in the list.
\r
262 * \page vListInsert vListInsert
\r
263 * \ingroup LinkedList
\r
265 void vListInsert( xList *pxList, xListItem *pxNewListItem );
\r
268 * Insert a list item into a list. The item will be inserted in a position
\r
269 * such that it will be the last item within the list returned by multiple
\r
270 * calls to listGET_OWNER_OF_NEXT_ENTRY.
\r
272 * The list member pvIndex is used to walk through a list. Calling
\r
273 * listGET_OWNER_OF_NEXT_ENTRY increments pvIndex to the next item in the list.
\r
274 * Placing an item in a list using vListInsertEnd effectively places the item
\r
275 * in the list position pointed to by pvIndex. This means that every other
\r
276 * item within the list will be returned by listGET_OWNER_OF_NEXT_ENTRY before
\r
277 * the pvIndex parameter again points to the item being inserted.
\r
279 * @param pxList The list into which the item is to be inserted.
\r
281 * @param pxNewListItem The list item to be inserted into the list.
\r
283 * \page vListInsertEnd vListInsertEnd
\r
284 * \ingroup LinkedList
\r
286 void vListInsertEnd( xList *pxList, xListItem *pxNewListItem );
\r
289 * Remove an item from a list. The list item has a pointer to the list that
\r
290 * it is in, so only the list item need be passed into the function.
\r
292 * @param vListRemove The item to be removed. The item will remove itself from
\r
293 * the list pointed to by it's pxContainer parameter.
\r
295 * \page vListRemove vListRemove
\r
296 * \ingroup LinkedList
\r
298 void vListRemove( xListItem *pxItemToRemove );
\r