2 FreeRTOS V8.2.3 - Copyright (C) 2015 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
72 #include "FreeRTOS.h"
\r
75 /*-----------------------------------------------------------
\r
76 * PUBLIC LIST API documented in list.h
\r
77 *----------------------------------------------------------*/
\r
79 void vListInitialise( List_t * const pxList )
\r
81 /* The list structure contains a list item which is used to mark the
\r
82 end of the list. To initialise the list the list end is inserted
\r
83 as the only list entry. */
\r
84 pxList->pxIndex = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */
\r
86 /* The list end value is the highest possible value in the list to
\r
87 ensure it remains at the end of the list. */
\r
88 pxList->xListEnd.xItemValue = portMAX_DELAY;
\r
90 /* The list end next and previous pointers point to itself so we know
\r
91 when the list is empty. */
\r
92 pxList->xListEnd.pxNext = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */
\r
93 pxList->xListEnd.pxPrevious = ( ListItem_t * ) &( pxList->xListEnd );/*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */
\r
95 pxList->uxNumberOfItems = ( UBaseType_t ) 0U;
\r
97 /* Write known values into the list if
\r
98 configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
\r
99 listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList );
\r
100 listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList );
\r
102 /*-----------------------------------------------------------*/
\r
104 void vListInitialiseItem( ListItem_t * const pxItem )
\r
106 /* Make sure the list item is not recorded as being on a list. */
\r
107 pxItem->pvContainer = NULL;
\r
109 /* Write known values into the list item if
\r
110 configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
\r
111 listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );
\r
112 listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );
\r
114 /*-----------------------------------------------------------*/
\r
116 void vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem )
\r
118 ListItem_t * const pxIndex = pxList->pxIndex;
\r
120 /* Only effective when configASSERT() is also defined, these tests may catch
\r
121 the list data structures being overwritten in memory. They will not catch
\r
122 data errors caused by incorrect configuration or use of FreeRTOS. */
\r
123 listTEST_LIST_INTEGRITY( pxList );
\r
124 listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );
\r
126 /* Insert a new list item into pxList, but rather than sort the list,
\r
127 makes the new list item the last item to be removed by a call to
\r
128 listGET_OWNER_OF_NEXT_ENTRY(). */
\r
129 pxNewListItem->pxNext = pxIndex;
\r
130 pxNewListItem->pxPrevious = pxIndex->pxPrevious;
\r
132 /* Only used during decision coverage testing. */
\r
133 mtCOVERAGE_TEST_DELAY();
\r
135 pxIndex->pxPrevious->pxNext = pxNewListItem;
\r
136 pxIndex->pxPrevious = pxNewListItem;
\r
138 /* Remember which list the item is in. */
\r
139 pxNewListItem->pvContainer = ( void * ) pxList;
\r
141 ( pxList->uxNumberOfItems )++;
\r
143 /*-----------------------------------------------------------*/
\r
145 void vListInsert( List_t * const pxList, ListItem_t * const pxNewListItem )
\r
147 ListItem_t *pxIterator;
\r
148 const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
\r
150 /* Only effective when configASSERT() is also defined, these tests may catch
\r
151 the list data structures being overwritten in memory. They will not catch
\r
152 data errors caused by incorrect configuration or use of FreeRTOS. */
\r
153 listTEST_LIST_INTEGRITY( pxList );
\r
154 listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );
\r
156 /* Insert the new list item into the list, sorted in xItemValue order.
\r
158 If the list already contains a list item with the same item value then the
\r
159 new list item should be placed after it. This ensures that TCB's which are
\r
160 stored in ready lists (all of which have the same xItemValue value) get a
\r
161 share of the CPU. However, if the xItemValue is the same as the back marker
\r
162 the iteration loop below will not end. Therefore the value is checked
\r
163 first, and the algorithm slightly modified if necessary. */
\r
164 if( xValueOfInsertion == portMAX_DELAY )
\r
166 pxIterator = pxList->xListEnd.pxPrevious;
\r
170 /* *** NOTE ***********************************************************
\r
171 If you find your application is crashing here then likely causes are
\r
172 listed below. In addition see http://www.freertos.org/FAQHelp.html for
\r
173 more tips, and ensure configASSERT() is defined!
\r
174 http://www.freertos.org/a00110.html#configASSERT
\r
176 1) Stack overflow -
\r
177 see http://www.freertos.org/Stacks-and-stack-overflow-checking.html
\r
178 2) Incorrect interrupt priority assignment, especially on Cortex-M
\r
179 parts where numerically high priority values denote low actual
\r
180 interrupt priorities, which can seem counter intuitive. See
\r
181 http://www.freertos.org/RTOS-Cortex-M3-M4.html and the definition
\r
182 of configMAX_SYSCALL_INTERRUPT_PRIORITY on
\r
183 http://www.freertos.org/a00110.html
\r
184 3) Calling an API function from within a critical section or when
\r
185 the scheduler is suspended, or calling an API function that does
\r
186 not end in "FromISR" from an interrupt.
\r
187 4) Using a queue or semaphore before it has been initialised or
\r
188 before the scheduler has been started (are interrupts firing
\r
189 before vTaskStartScheduler() has been called?).
\r
190 **********************************************************************/
\r
192 for( pxIterator = ( ListItem_t * ) &( 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
194 /* There is nothing to do here, just iterating to the wanted
\r
195 insertion position. */
\r
199 pxNewListItem->pxNext = pxIterator->pxNext;
\r
200 pxNewListItem->pxNext->pxPrevious = pxNewListItem;
\r
201 pxNewListItem->pxPrevious = pxIterator;
\r
202 pxIterator->pxNext = pxNewListItem;
\r
204 /* Remember which list the item is in. This allows fast removal of the
\r
206 pxNewListItem->pvContainer = ( void * ) pxList;
\r
208 ( pxList->uxNumberOfItems )++;
\r
210 /*-----------------------------------------------------------*/
\r
212 UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )
\r
214 /* The list item knows which list it is in. Obtain the list from the list
\r
216 List_t * const pxList = ( List_t * ) pxItemToRemove->pvContainer;
\r
218 pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
\r
219 pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
\r
221 /* Only used during decision coverage testing. */
\r
222 mtCOVERAGE_TEST_DELAY();
\r
224 /* Make sure the index is left pointing to a valid item. */
\r
225 if( pxList->pxIndex == pxItemToRemove )
\r
227 pxList->pxIndex = pxItemToRemove->pxPrevious;
\r
231 mtCOVERAGE_TEST_MARKER();
\r
234 pxItemToRemove->pvContainer = NULL;
\r
235 ( pxList->uxNumberOfItems )--;
\r
237 return pxList->uxNumberOfItems;
\r
239 /*-----------------------------------------------------------*/
\r