2 FreeRTOS V5.4.0 - Copyright (C) 2003-2009 Richard Barry.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
7 the terms of the GNU General Public License (version 2) as published by the
\r
8 Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS without being obliged to provide the
\r
11 source code for proprietary components outside of the FreeRTOS kernel.
\r
12 Alternative commercial license and support terms are also available upon
\r
13 request. See the licensing section of http://www.FreeRTOS.org for full
\r
16 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
21 You should have received a copy of the GNU General Public License along
\r
22 with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
\r
23 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
26 ***************************************************************************
\r
28 * Looking for a quick start? Then check out the FreeRTOS eBook! *
\r
29 * See http://www.FreeRTOS.org/Documentation for details *
\r
31 ***************************************************************************
\r
35 Please ensure to read the configuration and relevant port sections of the
\r
36 online documentation.
\r
38 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
41 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
44 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
45 licensing and training services.
\r
50 #include "FreeRTOS.h"
\r
53 /*-----------------------------------------------------------
\r
54 * PUBLIC LIST API documented in list.h
\r
55 *----------------------------------------------------------*/
\r
57 void vListInitialise( xList *pxList )
\r
59 /* The list structure contains a list item which is used to mark the
\r
60 end of the list. To initialise the list the list end is inserted
\r
61 as the only list entry. */
\r
62 pxList->pxIndex = ( xListItem * ) &( pxList->xListEnd );
\r
64 /* The list end value is the highest possible value in the list to
\r
65 ensure it remains at the end of the list. */
\r
66 pxList->xListEnd.xItemValue = portMAX_DELAY;
\r
68 /* The list end next and previous pointers point to itself so we know
\r
69 when the list is empty. */
\r
70 pxList->xListEnd.pxNext = ( xListItem * ) &( pxList->xListEnd );
\r
71 pxList->xListEnd.pxPrevious = ( xListItem * ) &( pxList->xListEnd );
\r
73 pxList->uxNumberOfItems = 0;
\r
75 /*-----------------------------------------------------------*/
\r
77 void vListInitialiseItem( xListItem *pxItem )
\r
79 /* Make sure the list item is not recorded as being on a list. */
\r
80 pxItem->pvContainer = NULL;
\r
82 /*-----------------------------------------------------------*/
\r
84 void vListInsertEnd( xList *pxList, xListItem *pxNewListItem )
\r
86 volatile xListItem * pxIndex;
\r
88 /* Insert a new list item into pxList, but rather than sort the list,
\r
89 makes the new list item the last item to be removed by a call to
\r
90 pvListGetOwnerOfNextEntry. This means it has to be the item pointed to by
\r
91 the pxIndex member. */
\r
92 pxIndex = pxList->pxIndex;
\r
94 pxNewListItem->pxNext = pxIndex->pxNext;
\r
95 pxNewListItem->pxPrevious = pxList->pxIndex;
\r
96 pxIndex->pxNext->pxPrevious = ( volatile xListItem * ) pxNewListItem;
\r
97 pxIndex->pxNext = ( volatile xListItem * ) pxNewListItem;
\r
98 pxList->pxIndex = ( volatile xListItem * ) pxNewListItem;
\r
100 /* Remember which list the item is in. */
\r
101 pxNewListItem->pvContainer = ( void * ) pxList;
\r
103 ( pxList->uxNumberOfItems )++;
\r
105 /*-----------------------------------------------------------*/
\r
107 void vListInsert( xList *pxList, xListItem *pxNewListItem )
\r
109 volatile xListItem *pxIterator;
\r
110 portTickType xValueOfInsertion;
\r
112 /* Insert the new list item into the list, sorted in ulListItem order. */
\r
113 xValueOfInsertion = pxNewListItem->xItemValue;
\r
115 /* If the list already contains a list item with the same item value then
\r
116 the new list item should be placed after it. This ensures that TCB's which
\r
117 are stored in ready lists (all of which have the same ulListItem value)
\r
118 get an equal share of the CPU. However, if the xItemValue is the same as
\r
119 the back marker the iteration loop below will not end. This means we need
\r
120 to guard against this by checking the value first and modifying the
\r
121 algorithm slightly if necessary. */
\r
122 if( xValueOfInsertion == portMAX_DELAY )
\r
124 pxIterator = pxList->xListEnd.pxPrevious;
\r
128 /* *** NOTE ***********************************************************
\r
129 If you find your application is crashing here then likely causes are:
\r
130 1) Stack overflow -
\r
131 see http://www.freertos.org/Stacks-and-stack-overflow-checking.html
\r
132 2) Incorrect interrupt priority assignment, especially on Cortex M3
\r
133 parts where numerically high priority values denote low actual
\r
134 interrupt priories, which can seem counter intuitive. See
\r
135 configMAX_SYSCALL_INTERRUPT_PRIORITY on http://www.freertos.org/a00110.html
\r
136 3) Calling an API function from within a critical section or when
\r
137 the scheduler is suspended.
\r
138 4) Using a queue or semaphore before it has been initialised or
\r
139 before the scheduler has been started (are interrupts firing
\r
140 before vTaskStartScheduler() has been called?).
\r
141 See http://www.freertos.org/FAQHelp.html for more tips.
\r
142 **********************************************************************/
\r
144 for( pxIterator = ( xListItem * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext )
\r
146 /* There is nothing to do here, we are just iterating to the
\r
147 wanted insertion position. */
\r
151 pxNewListItem->pxNext = pxIterator->pxNext;
\r
152 pxNewListItem->pxNext->pxPrevious = ( volatile xListItem * ) pxNewListItem;
\r
153 pxNewListItem->pxPrevious = pxIterator;
\r
154 pxIterator->pxNext = ( volatile xListItem * ) pxNewListItem;
\r
156 /* Remember which list the item is in. This allows fast removal of the
\r
158 pxNewListItem->pvContainer = ( void * ) pxList;
\r
160 ( pxList->uxNumberOfItems )++;
\r
162 /*-----------------------------------------------------------*/
\r
164 void vListRemove( xListItem *pxItemToRemove )
\r
168 pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
\r
169 pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
\r
171 /* The list item knows which list it is in. Obtain the list from the list
\r
173 pxList = ( xList * ) pxItemToRemove->pvContainer;
\r
175 /* Make sure the index is left pointing to a valid item. */
\r
176 if( pxList->pxIndex == pxItemToRemove )
\r
178 pxList->pxIndex = pxItemToRemove->pxPrevious;
\r
181 pxItemToRemove->pvContainer = NULL;
\r
182 ( pxList->uxNumberOfItems )--;
\r
184 /*-----------------------------------------------------------*/
\r