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