2 * FreeRTOS Kernel V10.4.6
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: MIT
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
32 /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
33 * all the API functions to use the MPU wrappers. That should only be done when
34 * task.h is included from an application file. */
35 #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
40 /* Lint e9021, e961 and e750 are suppressed as a MISRA exception justified
41 * because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be
42 * defined for the header files above, but not in this file, in order to
43 * generate the correct privileged Vs unprivileged linkage and placement. */
44 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750 !e9021. */
46 /*-----------------------------------------------------------
47 * PUBLIC LIST API documented in list.h
48 *----------------------------------------------------------*/
50 void vListInitialise( List_t * const pxList )
52 /* The list structure contains a list item which is used to mark the
53 * end of the list. To initialise the list the list end is inserted
54 * as the only list entry. */
55 pxList->pxIndex = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
57 /* The list end value is the highest possible value in the list to
58 * ensure it remains at the end of the list. */
59 pxList->xListEnd.xItemValue = portMAX_DELAY;
61 /* The list end next and previous pointers point to itself so we know
62 * when the list is empty. */
63 pxList->xListEnd.pxNext = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
64 pxList->xListEnd.pxPrevious = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
66 pxList->uxNumberOfItems = ( UBaseType_t ) 0U;
68 /* Write known values into the list if
69 * configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
70 listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList );
71 listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList );
73 /*-----------------------------------------------------------*/
75 void vListInitialiseItem( ListItem_t * const pxItem )
77 /* Make sure the list item is not recorded as being on a list. */
78 pxItem->pxContainer = NULL;
80 /* Write known values into the list item if
81 * configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
82 listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );
83 listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );
85 /*-----------------------------------------------------------*/
87 void vListInsertEnd( List_t * const pxList,
88 ListItem_t * const pxNewListItem )
90 ListItem_t * const pxIndex = pxList->pxIndex;
92 /* Only effective when configASSERT() is also defined, these tests may catch
93 * the list data structures being overwritten in memory. They will not catch
94 * data errors caused by incorrect configuration or use of FreeRTOS. */
95 listTEST_LIST_INTEGRITY( pxList );
96 listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );
98 /* Insert a new list item into pxList, but rather than sort the list,
99 * makes the new list item the last item to be removed by a call to
100 * listGET_OWNER_OF_NEXT_ENTRY(). */
101 pxNewListItem->pxNext = pxIndex;
102 pxNewListItem->pxPrevious = pxIndex->pxPrevious;
104 /* Only used during decision coverage testing. */
105 mtCOVERAGE_TEST_DELAY();
107 pxIndex->pxPrevious->pxNext = pxNewListItem;
108 pxIndex->pxPrevious = pxNewListItem;
110 /* Remember which list the item is in. */
111 pxNewListItem->pxContainer = pxList;
113 ( pxList->uxNumberOfItems )++;
115 /*-----------------------------------------------------------*/
117 void vListInsert( List_t * const pxList,
118 ListItem_t * const pxNewListItem )
120 ListItem_t * pxIterator;
121 const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
123 /* Only effective when configASSERT() is also defined, these tests may catch
124 * the list data structures being overwritten in memory. They will not catch
125 * data errors caused by incorrect configuration or use of FreeRTOS. */
126 listTEST_LIST_INTEGRITY( pxList );
127 listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );
129 /* Insert the new list item into the list, sorted in xItemValue order.
131 * If the list already contains a list item with the same item value then the
132 * new list item should be placed after it. This ensures that TCBs which are
133 * stored in ready lists (all of which have the same xItemValue value) get a
134 * share of the CPU. However, if the xItemValue is the same as the back marker
135 * the iteration loop below will not end. Therefore the value is checked
136 * first, and the algorithm slightly modified if necessary. */
137 if( xValueOfInsertion == portMAX_DELAY )
139 pxIterator = pxList->xListEnd.pxPrevious;
143 /* *** NOTE ***********************************************************
144 * If you find your application is crashing here then likely causes are
145 * listed below. In addition see https://www.FreeRTOS.org/FAQHelp.html for
146 * more tips, and ensure configASSERT() is defined!
147 * https://www.FreeRTOS.org/a00110.html#configASSERT
149 * 1) Stack overflow -
150 * see https://www.FreeRTOS.org/Stacks-and-stack-overflow-checking.html
151 * 2) Incorrect interrupt priority assignment, especially on Cortex-M
152 * parts where numerically high priority values denote low actual
153 * interrupt priorities, which can seem counter intuitive. See
154 * https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html and the definition
155 * of configMAX_SYSCALL_INTERRUPT_PRIORITY on
156 * https://www.FreeRTOS.org/a00110.html
157 * 3) Calling an API function from within a critical section or when
158 * the scheduler is suspended, or calling an API function that does
159 * not end in "FromISR" from an interrupt.
160 * 4) Using a queue or semaphore before it has been initialised or
161 * before the scheduler has been started (are interrupts firing
162 * before vTaskStartScheduler() has been called?).
163 * 5) If the FreeRTOS port supports interrupt nesting then ensure that
164 * the priority of the tick interrupt is at or below
165 * configMAX_SYSCALL_INTERRUPT_PRIORITY.
166 **********************************************************************/
168 for( pxIterator = ( ListItem_t * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. *//*lint !e440 The iterator moves to a different value, not xValueOfInsertion. */
170 /* There is nothing to do here, just iterating to the wanted
171 * insertion position. */
175 pxNewListItem->pxNext = pxIterator->pxNext;
176 pxNewListItem->pxNext->pxPrevious = pxNewListItem;
177 pxNewListItem->pxPrevious = pxIterator;
178 pxIterator->pxNext = pxNewListItem;
180 /* Remember which list the item is in. This allows fast removal of the
182 pxNewListItem->pxContainer = pxList;
184 ( pxList->uxNumberOfItems )++;
186 /*-----------------------------------------------------------*/
188 UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )
190 /* The list item knows which list it is in. Obtain the list from the list
192 List_t * const pxList = pxItemToRemove->pxContainer;
194 pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
195 pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
197 /* Only used during decision coverage testing. */
198 mtCOVERAGE_TEST_DELAY();
200 /* Make sure the index is left pointing to a valid item. */
201 if( pxList->pxIndex == pxItemToRemove )
203 pxList->pxIndex = pxItemToRemove->pxPrevious;
207 mtCOVERAGE_TEST_MARKER();
210 pxItemToRemove->pxContainer = NULL;
211 ( pxList->uxNumberOfItems )--;
213 return pxList->uxNumberOfItems;
215 /*-----------------------------------------------------------*/