2 FreeRTOS V9.0.0 - Copyright (C) 2016 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;
132 /* Only used during decision coverage testing. */
133 mtCOVERAGE_TEST_DELAY();
135 pxIndex->pxPrevious->pxNext = pxNewListItem;
136 pxIndex->pxPrevious = pxNewListItem;
138 /* Remember which list the item is in. */
139 pxNewListItem->pvContainer = ( void * ) pxList;
141 ( pxList->uxNumberOfItems )++;
143 /*-----------------------------------------------------------*/
145 void vListInsert( List_t * const pxList, ListItem_t * const pxNewListItem )
147 ListItem_t *pxIterator;
148 const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
150 /* Only effective when configASSERT() is also defined, these tests may catch
151 the list data structures being overwritten in memory. They will not catch
152 data errors caused by incorrect configuration or use of FreeRTOS. */
153 listTEST_LIST_INTEGRITY( pxList );
154 listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );
156 /* Insert the new list item into the list, sorted in xItemValue order.
158 If the list already contains a list item with the same item value then the
159 new list item should be placed after it. This ensures that TCB's which are
160 stored in ready lists (all of which have the same xItemValue value) get a
161 share of the CPU. However, if the xItemValue is the same as the back marker
162 the iteration loop below will not end. Therefore the value is checked
163 first, and the algorithm slightly modified if necessary. */
164 if( xValueOfInsertion == portMAX_DELAY )
166 pxIterator = pxList->xListEnd.pxPrevious;
170 /* *** NOTE ***********************************************************
171 If you find your application is crashing here then likely causes are
172 listed below. In addition see http://www.freertos.org/FAQHelp.html for
173 more tips, and ensure configASSERT() is defined!
174 http://www.freertos.org/a00110.html#configASSERT
177 see http://www.freertos.org/Stacks-and-stack-overflow-checking.html
178 2) Incorrect interrupt priority assignment, especially on Cortex-M
179 parts where numerically high priority values denote low actual
180 interrupt priorities, which can seem counter intuitive. See
181 http://www.freertos.org/RTOS-Cortex-M3-M4.html and the definition
182 of configMAX_SYSCALL_INTERRUPT_PRIORITY on
183 http://www.freertos.org/a00110.html
184 3) Calling an API function from within a critical section or when
185 the scheduler is suspended, or calling an API function that does
186 not end in "FromISR" from an interrupt.
187 4) Using a queue or semaphore before it has been initialised or
188 before the scheduler has been started (are interrupts firing
189 before vTaskStartScheduler() has been called?).
190 **********************************************************************/
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. */
194 /* There is nothing to do here, just iterating to the wanted
195 insertion position. */
199 pxNewListItem->pxNext = pxIterator->pxNext;
200 pxNewListItem->pxNext->pxPrevious = pxNewListItem;
201 pxNewListItem->pxPrevious = pxIterator;
202 pxIterator->pxNext = pxNewListItem;
204 /* Remember which list the item is in. This allows fast removal of the
206 pxNewListItem->pvContainer = ( void * ) pxList;
208 ( pxList->uxNumberOfItems )++;
210 /*-----------------------------------------------------------*/
212 UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )
214 /* The list item knows which list it is in. Obtain the list from the list
216 List_t * const pxList = ( List_t * ) pxItemToRemove->pvContainer;
218 pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
219 pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
221 /* Only used during decision coverage testing. */
222 mtCOVERAGE_TEST_DELAY();
224 /* Make sure the index is left pointing to a valid item. */
225 if( pxList->pxIndex == pxItemToRemove )
227 pxList->pxIndex = pxItemToRemove->pxPrevious;
231 mtCOVERAGE_TEST_MARKER();
234 pxItemToRemove->pvContainer = NULL;
235 ( pxList->uxNumberOfItems )--;
237 return pxList->uxNumberOfItems;
239 /*-----------------------------------------------------------*/