root/webserver/example/freeRTOS/Source/list.c

Revision 14, 7.2 kB (checked in by phil, 15 years ago)

added unmodified FreeRTOS package V5.4.1 with only web srv demo source for LPC2368 for CrossWorks?

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