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