2 FreeRTOS V7.4.2 - 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 it can 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 * const 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 ); /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */
\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 ); /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */
\r
98 pxList->xListEnd.pxPrevious = ( xListItem * ) &( pxList->xListEnd );/*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */
\r
100 pxList->uxNumberOfItems = ( unsigned portBASE_TYPE ) 0U;
\r
102 /*-----------------------------------------------------------*/
\r
104 void vListInitialiseItem( xListItem * const 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 * const pxList, xListItem * const pxNewListItem )
\r
113 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. */
\r
118 pxIndex = pxList->pxIndex;
\r
120 pxNewListItem->pxNext = pxIndex;
\r
121 pxNewListItem->pxPrevious = pxIndex->pxPrevious;
\r
122 pxIndex->pxPrevious->pxNext = pxNewListItem;
\r
123 pxIndex->pxPrevious = pxNewListItem;
\r
125 /* Remember which list the item is in. */
\r
126 pxNewListItem->pvContainer = ( void * ) pxList;
\r
128 ( pxList->uxNumberOfItems )++;
\r
130 /*-----------------------------------------------------------*/
\r
132 void vListInsert( xList * const pxList, xListItem * const pxNewListItem )
\r
134 xListItem *pxIterator;
\r
135 portTickType xValueOfInsertion;
\r
137 /* Insert the new list item into the list, sorted in ulListItem order. */
\r
138 xValueOfInsertion = pxNewListItem->xItemValue;
\r
140 /* If the list already contains a list item with the same item value then
\r
141 the new list item should be placed after it. This ensures that TCB's which
\r
142 are stored in ready lists (all of which have the same ulListItem value)
\r
143 get an equal share of the CPU. However, if the xItemValue is the same as
\r
144 the back marker the iteration loop below will not end. This means we need
\r
145 to guard against this by checking the value first and modifying the
\r
146 algorithm slightly if necessary. */
\r
147 if( xValueOfInsertion == portMAX_DELAY )
\r
149 pxIterator = pxList->xListEnd.pxPrevious;
\r
153 /* *** NOTE ***********************************************************
\r
154 If you find your application is crashing here then likely causes are:
\r
155 1) Stack overflow -
\r
156 see http://www.freertos.org/Stacks-and-stack-overflow-checking.html
\r
157 2) Incorrect interrupt priority assignment, especially on Cortex-M3
\r
158 parts where numerically high priority values denote low actual
\r
159 interrupt priories, which can seem counter intuitive. See
\r
160 configMAX_SYSCALL_INTERRUPT_PRIORITY on http://www.freertos.org/a00110.html
\r
161 3) Calling an API function from within a critical section or when
\r
162 the scheduler is suspended, or calling an API function that does
\r
163 not end in "FromISR" from an interrupt.
\r
164 4) Using a queue or semaphore before it has been initialised or
\r
165 before the scheduler has been started (are interrupts firing
\r
166 before vTaskStartScheduler() has been called?).
\r
167 See http://www.freertos.org/FAQHelp.html for more tips.
\r
168 **********************************************************************/
\r
170 for( pxIterator = ( xListItem * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */
\r
172 /* There is nothing to do here, we are just iterating to the
\r
173 wanted insertion position. */
\r
177 pxNewListItem->pxNext = pxIterator->pxNext;
\r
178 pxNewListItem->pxNext->pxPrevious = pxNewListItem;
\r
179 pxNewListItem->pxPrevious = pxIterator;
\r
180 pxIterator->pxNext = pxNewListItem;
\r
182 /* Remember which list the item is in. This allows fast removal of the
\r
184 pxNewListItem->pvContainer = ( void * ) pxList;
\r
186 ( pxList->uxNumberOfItems )++;
\r
188 /*-----------------------------------------------------------*/
\r
190 unsigned portBASE_TYPE uxListRemove( xListItem * const pxItemToRemove )
\r
194 pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
\r
195 pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
\r
197 /* The list item knows which list it is in. Obtain the list from the list
\r
199 pxList = ( xList * ) pxItemToRemove->pvContainer;
\r
201 /* Make sure the index is left pointing to a valid item. */
\r
202 if( pxList->pxIndex == pxItemToRemove )
\r
204 pxList->pxIndex = pxItemToRemove->pxPrevious;
\r
207 pxItemToRemove->pvContainer = NULL;
\r
208 ( pxList->uxNumberOfItems )--;
\r
210 return pxList->uxNumberOfItems;
\r
212 /*-----------------------------------------------------------*/
\r