2 FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
33 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
\r
34 distribute a combined work that includes FreeRTOS without being obliged to
\r
35 provide the source code for proprietary components outside of the FreeRTOS
\r
38 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
39 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
40 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
41 details. You should have received a copy of the GNU General Public License
\r
42 and the FreeRTOS license exception along with FreeRTOS; if not itcan be
\r
43 viewed here: http://www.freertos.org/a00114.html and also obtained by
\r
44 writing to Real Time Engineers Ltd., contact details for whom are available
\r
45 on the FreeRTOS WEB site.
\r
49 ***************************************************************************
\r
51 * Having a problem? Start by reading the FAQ "My application does *
\r
52 * not run, what could be wrong?" *
\r
54 * http://www.FreeRTOS.org/FAQHelp.html *
\r
56 ***************************************************************************
\r
59 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
60 license and Real Time Engineers Ltd. contact details.
\r
62 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
63 including FreeRTOS+Trace - an indispensable productivity tool, and our new
\r
64 fully thread aware and reentrant UDP/IP stack.
\r
66 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
67 Integrity Systems, who sell the code with commercial support,
\r
68 indemnification and middleware, under the OpenRTOS brand.
\r
70 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
71 engineered and independently SIL3 certified version for use in safety and
\r
72 mission critical applications that require provable dependability.
\r
77 #include "FreeRTOS.h"
\r
80 /*-----------------------------------------------------------
\r
81 * PUBLIC LIST API documented in list.h
\r
82 *----------------------------------------------------------*/
\r
84 void vListInitialise( xList *pxList )
\r
86 /* The list structure contains a list item which is used to mark the
\r
87 end of the list. To initialise the list the list end is inserted
\r
88 as the only list entry. */
\r
89 pxList->pxIndex = ( xListItem * ) &( pxList->xListEnd );
\r
91 /* The list end value is the highest possible value in the list to
\r
92 ensure it remains at the end of the list. */
\r
93 pxList->xListEnd.xItemValue = portMAX_DELAY;
\r
95 /* The list end next and previous pointers point to itself so we know
\r
96 when the list is empty. */
\r
97 pxList->xListEnd.pxNext = ( xListItem * ) &( pxList->xListEnd );
\r
98 pxList->xListEnd.pxPrevious = ( xListItem * ) &( pxList->xListEnd );
\r
100 pxList->uxNumberOfItems = ( unsigned portBASE_TYPE ) 0U;
\r
102 /*-----------------------------------------------------------*/
\r
104 void vListInitialiseItem( xListItem *pxItem )
\r
106 /* Make sure the list item is not recorded as being on a list. */
\r
107 pxItem->pvContainer = NULL;
\r
109 /*-----------------------------------------------------------*/
\r
111 void vListInsertEnd( xList *pxList, xListItem *pxNewListItem )
\r
113 volatile xListItem * pxIndex;
\r
115 /* Insert a new list item into pxList, but rather than sort the list,
\r
116 makes the new list item the last item to be removed by a call to
\r
117 pvListGetOwnerOfNextEntry. This means it has to be the item pointed to by
\r
118 the pxIndex member. */
\r
119 pxIndex = pxList->pxIndex;
\r
121 pxNewListItem->pxNext = pxIndex->pxNext;
\r
122 pxNewListItem->pxPrevious = pxList->pxIndex;
\r
123 pxIndex->pxNext->pxPrevious = ( volatile xListItem * ) pxNewListItem;
\r
124 pxIndex->pxNext = ( volatile xListItem * ) pxNewListItem;
\r
125 pxList->pxIndex = ( volatile xListItem * ) pxNewListItem;
\r
127 /* Remember which list the item is in. */
\r
128 pxNewListItem->pvContainer = ( void * ) pxList;
\r
130 ( pxList->uxNumberOfItems )++;
\r
132 /*-----------------------------------------------------------*/
\r
134 void vListInsert( xList *pxList, xListItem *pxNewListItem )
\r
136 volatile xListItem *pxIterator;
\r
137 portTickType xValueOfInsertion;
\r
139 /* Insert the new list item into the list, sorted in ulListItem order. */
\r
140 xValueOfInsertion = pxNewListItem->xItemValue;
\r
142 /* If the list already contains a list item with the same item value then
\r
143 the new list item should be placed after it. This ensures that TCB's which
\r
144 are stored in ready lists (all of which have the same ulListItem value)
\r
145 get an equal share of the CPU. However, if the xItemValue is the same as
\r
146 the back marker the iteration loop below will not end. This means we need
\r
147 to guard against this by checking the value first and modifying the
\r
148 algorithm slightly if necessary. */
\r
149 if( xValueOfInsertion == portMAX_DELAY )
\r
151 pxIterator = pxList->xListEnd.pxPrevious;
\r
155 /* *** NOTE ***********************************************************
\r
156 If you find your application is crashing here then likely causes are:
\r
157 1) Stack overflow -
\r
158 see http://www.freertos.org/Stacks-and-stack-overflow-checking.html
\r
159 2) Incorrect interrupt priority assignment, especially on Cortex-M3
\r
160 parts where numerically high priority values denote low actual
\r
161 interrupt priories, which can seem counter intuitive. See
\r
162 configMAX_SYSCALL_INTERRUPT_PRIORITY on http://www.freertos.org/a00110.html
\r
163 3) Calling an API function from within a critical section or when
\r
164 the scheduler is suspended.
\r
165 4) Using a queue or semaphore before it has been initialised or
\r
166 before the scheduler has been started (are interrupts firing
\r
167 before vTaskStartScheduler() has been called?).
\r
168 See http://www.freertos.org/FAQHelp.html for more tips.
\r
169 **********************************************************************/
\r
171 for( pxIterator = ( xListItem * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext )
\r
173 /* There is nothing to do here, we are just iterating to the
\r
174 wanted insertion position. */
\r
178 pxNewListItem->pxNext = pxIterator->pxNext;
\r
179 pxNewListItem->pxNext->pxPrevious = ( volatile xListItem * ) pxNewListItem;
\r
180 pxNewListItem->pxPrevious = pxIterator;
\r
181 pxIterator->pxNext = ( volatile xListItem * ) pxNewListItem;
\r
183 /* Remember which list the item is in. This allows fast removal of the
\r
185 pxNewListItem->pvContainer = ( void * ) pxList;
\r
187 ( pxList->uxNumberOfItems )++;
\r
189 /*-----------------------------------------------------------*/
\r
191 unsigned portBASE_TYPE uxListRemove( xListItem *pxItemToRemove )
\r
195 pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
\r
196 pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
\r
198 /* The list item knows which list it is in. Obtain the list from the list
\r
200 pxList = ( xList * ) pxItemToRemove->pvContainer;
\r
202 /* Make sure the index is left pointing to a valid item. */
\r
203 if( pxList->pxIndex == pxItemToRemove )
\r
205 pxList->pxIndex = pxItemToRemove->pxPrevious;
\r
208 pxItemToRemove->pvContainer = NULL;
\r
209 ( pxList->uxNumberOfItems )--;
\r
211 return pxList->uxNumberOfItems;
\r
213 /*-----------------------------------------------------------*/
\r