Francisco Paez / freertos-cm3

Dependents:   mbed_lpc1768_freertos_lib

Committer:
fep
Date:
Wed May 31 02:36:43 2017 +0000
Revision:
0:5ff20db10a96
FreeRTOS v9.0.0 for ARM Cortex-M3 based boards.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fep 0:5ff20db10a96 1 /*
fep 0:5ff20db10a96 2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
fep 0:5ff20db10a96 3 All rights reserved
fep 0:5ff20db10a96 4
fep 0:5ff20db10a96 5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
fep 0:5ff20db10a96 6
fep 0:5ff20db10a96 7 This file is part of the FreeRTOS distribution.
fep 0:5ff20db10a96 8
fep 0:5ff20db10a96 9 FreeRTOS is free software; you can redistribute it and/or modify it under
fep 0:5ff20db10a96 10 the terms of the GNU General Public License (version 2) as published by the
fep 0:5ff20db10a96 11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
fep 0:5ff20db10a96 12
fep 0:5ff20db10a96 13 ***************************************************************************
fep 0:5ff20db10a96 14 >>! NOTE: The modification to the GPL is included to allow you to !<<
fep 0:5ff20db10a96 15 >>! distribute a combined work that includes FreeRTOS without being !<<
fep 0:5ff20db10a96 16 >>! obliged to provide the source code for proprietary components !<<
fep 0:5ff20db10a96 17 >>! outside of the FreeRTOS kernel. !<<
fep 0:5ff20db10a96 18 ***************************************************************************
fep 0:5ff20db10a96 19
fep 0:5ff20db10a96 20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
fep 0:5ff20db10a96 21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
fep 0:5ff20db10a96 22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
fep 0:5ff20db10a96 23 link: http://www.freertos.org/a00114.html
fep 0:5ff20db10a96 24
fep 0:5ff20db10a96 25 ***************************************************************************
fep 0:5ff20db10a96 26 * *
fep 0:5ff20db10a96 27 * FreeRTOS provides completely free yet professionally developed, *
fep 0:5ff20db10a96 28 * robust, strictly quality controlled, supported, and cross *
fep 0:5ff20db10a96 29 * platform software that is more than just the market leader, it *
fep 0:5ff20db10a96 30 * is the industry's de facto standard. *
fep 0:5ff20db10a96 31 * *
fep 0:5ff20db10a96 32 * Help yourself get started quickly while simultaneously helping *
fep 0:5ff20db10a96 33 * to support the FreeRTOS project by purchasing a FreeRTOS *
fep 0:5ff20db10a96 34 * tutorial book, reference manual, or both: *
fep 0:5ff20db10a96 35 * http://www.FreeRTOS.org/Documentation *
fep 0:5ff20db10a96 36 * *
fep 0:5ff20db10a96 37 ***************************************************************************
fep 0:5ff20db10a96 38
fep 0:5ff20db10a96 39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
fep 0:5ff20db10a96 40 the FAQ page "My application does not run, what could be wrong?". Have you
fep 0:5ff20db10a96 41 defined configASSERT()?
fep 0:5ff20db10a96 42
fep 0:5ff20db10a96 43 http://www.FreeRTOS.org/support - In return for receiving this top quality
fep 0:5ff20db10a96 44 embedded software for free we request you assist our global community by
fep 0:5ff20db10a96 45 participating in the support forum.
fep 0:5ff20db10a96 46
fep 0:5ff20db10a96 47 http://www.FreeRTOS.org/training - Investing in training allows your team to
fep 0:5ff20db10a96 48 be as productive as possible as early as possible. Now you can receive
fep 0:5ff20db10a96 49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
fep 0:5ff20db10a96 50 Ltd, and the world's leading authority on the world's leading RTOS.
fep 0:5ff20db10a96 51
fep 0:5ff20db10a96 52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
fep 0:5ff20db10a96 53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
fep 0:5ff20db10a96 54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
fep 0:5ff20db10a96 55
fep 0:5ff20db10a96 56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
fep 0:5ff20db10a96 57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
fep 0:5ff20db10a96 58
fep 0:5ff20db10a96 59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
fep 0:5ff20db10a96 60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
fep 0:5ff20db10a96 61 licenses offer ticketed support, indemnification and commercial middleware.
fep 0:5ff20db10a96 62
fep 0:5ff20db10a96 63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
fep 0:5ff20db10a96 64 engineered and independently SIL3 certified version for use in safety and
fep 0:5ff20db10a96 65 mission critical applications that require provable dependability.
fep 0:5ff20db10a96 66
fep 0:5ff20db10a96 67 1 tab == 4 spaces!
fep 0:5ff20db10a96 68 */
fep 0:5ff20db10a96 69
fep 0:5ff20db10a96 70 /*
fep 0:5ff20db10a96 71 * This is the list implementation used by the scheduler. While it is tailored
fep 0:5ff20db10a96 72 * heavily for the schedulers needs, it is also available for use by
fep 0:5ff20db10a96 73 * application code.
fep 0:5ff20db10a96 74 *
fep 0:5ff20db10a96 75 * list_ts can only store pointers to list_item_ts. Each ListItem_t contains a
fep 0:5ff20db10a96 76 * numeric value (xItemValue). Most of the time the lists are sorted in
fep 0:5ff20db10a96 77 * descending item value order.
fep 0:5ff20db10a96 78 *
fep 0:5ff20db10a96 79 * Lists are created already containing one list item. The value of this
fep 0:5ff20db10a96 80 * item is the maximum possible that can be stored, it is therefore always at
fep 0:5ff20db10a96 81 * the end of the list and acts as a marker. The list member pxHead always
fep 0:5ff20db10a96 82 * points to this marker - even though it is at the tail of the list. This
fep 0:5ff20db10a96 83 * is because the tail contains a wrap back pointer to the true head of
fep 0:5ff20db10a96 84 * the list.
fep 0:5ff20db10a96 85 *
fep 0:5ff20db10a96 86 * In addition to it's value, each list item contains a pointer to the next
fep 0:5ff20db10a96 87 * item in the list (pxNext), a pointer to the list it is in (pxContainer)
fep 0:5ff20db10a96 88 * and a pointer to back to the object that contains it. These later two
fep 0:5ff20db10a96 89 * pointers are included for efficiency of list manipulation. There is
fep 0:5ff20db10a96 90 * effectively a two way link between the object containing the list item and
fep 0:5ff20db10a96 91 * the list item itself.
fep 0:5ff20db10a96 92 *
fep 0:5ff20db10a96 93 *
fep 0:5ff20db10a96 94 * \page ListIntroduction List Implementation
fep 0:5ff20db10a96 95 * \ingroup FreeRTOSIntro
fep 0:5ff20db10a96 96 */
fep 0:5ff20db10a96 97
fep 0:5ff20db10a96 98 #ifndef INC_FREERTOS_H
fep 0:5ff20db10a96 99 #error FreeRTOS.h must be included before list.h
fep 0:5ff20db10a96 100 #endif
fep 0:5ff20db10a96 101
fep 0:5ff20db10a96 102 #ifndef LIST_H
fep 0:5ff20db10a96 103 #define LIST_H
fep 0:5ff20db10a96 104
fep 0:5ff20db10a96 105 /*
fep 0:5ff20db10a96 106 * The list structure members are modified from within interrupts, and therefore
fep 0:5ff20db10a96 107 * by rights should be declared volatile. However, they are only modified in a
fep 0:5ff20db10a96 108 * functionally atomic way (within critical sections of with the scheduler
fep 0:5ff20db10a96 109 * suspended) and are either passed by reference into a function or indexed via
fep 0:5ff20db10a96 110 * a volatile variable. Therefore, in all use cases tested so far, the volatile
fep 0:5ff20db10a96 111 * qualifier can be omitted in order to provide a moderate performance
fep 0:5ff20db10a96 112 * improvement without adversely affecting functional behaviour. The assembly
fep 0:5ff20db10a96 113 * instructions generated by the IAR, ARM and GCC compilers when the respective
fep 0:5ff20db10a96 114 * compiler's options were set for maximum optimisation has been inspected and
fep 0:5ff20db10a96 115 * deemed to be as intended. That said, as compiler technology advances, and
fep 0:5ff20db10a96 116 * especially if aggressive cross module optimisation is used (a use case that
fep 0:5ff20db10a96 117 * has not been exercised to any great extend) then it is feasible that the
fep 0:5ff20db10a96 118 * volatile qualifier will be needed for correct optimisation. It is expected
fep 0:5ff20db10a96 119 * that a compiler removing essential code because, without the volatile
fep 0:5ff20db10a96 120 * qualifier on the list structure members and with aggressive cross module
fep 0:5ff20db10a96 121 * optimisation, the compiler deemed the code unnecessary will result in
fep 0:5ff20db10a96 122 * complete and obvious failure of the scheduler. If this is ever experienced
fep 0:5ff20db10a96 123 * then the volatile qualifier can be inserted in the relevant places within the
fep 0:5ff20db10a96 124 * list structures by simply defining configLIST_VOLATILE to volatile in
fep 0:5ff20db10a96 125 * FreeRTOSConfig.h (as per the example at the bottom of this comment block).
fep 0:5ff20db10a96 126 * If configLIST_VOLATILE is not defined then the preprocessor directives below
fep 0:5ff20db10a96 127 * will simply #define configLIST_VOLATILE away completely.
fep 0:5ff20db10a96 128 *
fep 0:5ff20db10a96 129 * To use volatile list structure members then add the following line to
fep 0:5ff20db10a96 130 * FreeRTOSConfig.h (without the quotes):
fep 0:5ff20db10a96 131 * "#define configLIST_VOLATILE volatile"
fep 0:5ff20db10a96 132 */
fep 0:5ff20db10a96 133 #ifndef configLIST_VOLATILE
fep 0:5ff20db10a96 134 #define configLIST_VOLATILE
fep 0:5ff20db10a96 135 #endif /* configSUPPORT_CROSS_MODULE_OPTIMISATION */
fep 0:5ff20db10a96 136
fep 0:5ff20db10a96 137 #ifdef __cplusplus
fep 0:5ff20db10a96 138 extern "C" {
fep 0:5ff20db10a96 139 #endif
fep 0:5ff20db10a96 140
fep 0:5ff20db10a96 141 /* Macros that can be used to place known values within the list structures,
fep 0:5ff20db10a96 142 then check that the known values do not get corrupted during the execution of
fep 0:5ff20db10a96 143 the application. These may catch the list data structures being overwritten in
fep 0:5ff20db10a96 144 memory. They will not catch data errors caused by incorrect configuration or
fep 0:5ff20db10a96 145 use of FreeRTOS.*/
fep 0:5ff20db10a96 146 #if( configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES == 0 )
fep 0:5ff20db10a96 147 /* Define the macros to do nothing. */
fep 0:5ff20db10a96 148 #define listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE
fep 0:5ff20db10a96 149 #define listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE
fep 0:5ff20db10a96 150 #define listFIRST_LIST_INTEGRITY_CHECK_VALUE
fep 0:5ff20db10a96 151 #define listSECOND_LIST_INTEGRITY_CHECK_VALUE
fep 0:5ff20db10a96 152 #define listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem )
fep 0:5ff20db10a96 153 #define listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem )
fep 0:5ff20db10a96 154 #define listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList )
fep 0:5ff20db10a96 155 #define listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList )
fep 0:5ff20db10a96 156 #define listTEST_LIST_ITEM_INTEGRITY( pxItem )
fep 0:5ff20db10a96 157 #define listTEST_LIST_INTEGRITY( pxList )
fep 0:5ff20db10a96 158 #else
fep 0:5ff20db10a96 159 /* Define macros that add new members into the list structures. */
fep 0:5ff20db10a96 160 #define listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE TickType_t xListItemIntegrityValue1;
fep 0:5ff20db10a96 161 #define listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE TickType_t xListItemIntegrityValue2;
fep 0:5ff20db10a96 162 #define listFIRST_LIST_INTEGRITY_CHECK_VALUE TickType_t xListIntegrityValue1;
fep 0:5ff20db10a96 163 #define listSECOND_LIST_INTEGRITY_CHECK_VALUE TickType_t xListIntegrityValue2;
fep 0:5ff20db10a96 164
fep 0:5ff20db10a96 165 /* Define macros that set the new structure members to known values. */
fep 0:5ff20db10a96 166 #define listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ) ( pxItem )->xListItemIntegrityValue1 = pdINTEGRITY_CHECK_VALUE
fep 0:5ff20db10a96 167 #define listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ) ( pxItem )->xListItemIntegrityValue2 = pdINTEGRITY_CHECK_VALUE
fep 0:5ff20db10a96 168 #define listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList ) ( pxList )->xListIntegrityValue1 = pdINTEGRITY_CHECK_VALUE
fep 0:5ff20db10a96 169 #define listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList ) ( pxList )->xListIntegrityValue2 = pdINTEGRITY_CHECK_VALUE
fep 0:5ff20db10a96 170
fep 0:5ff20db10a96 171 /* Define macros that will assert if one of the structure members does not
fep 0:5ff20db10a96 172 contain its expected value. */
fep 0:5ff20db10a96 173 #define listTEST_LIST_ITEM_INTEGRITY( pxItem ) configASSERT( ( ( pxItem )->xListItemIntegrityValue1 == pdINTEGRITY_CHECK_VALUE ) && ( ( pxItem )->xListItemIntegrityValue2 == pdINTEGRITY_CHECK_VALUE ) )
fep 0:5ff20db10a96 174 #define listTEST_LIST_INTEGRITY( pxList ) configASSERT( ( ( pxList )->xListIntegrityValue1 == pdINTEGRITY_CHECK_VALUE ) && ( ( pxList )->xListIntegrityValue2 == pdINTEGRITY_CHECK_VALUE ) )
fep 0:5ff20db10a96 175 #endif /* configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES */
fep 0:5ff20db10a96 176
fep 0:5ff20db10a96 177
fep 0:5ff20db10a96 178 /*
fep 0:5ff20db10a96 179 * Definition of the only type of object that a list can contain.
fep 0:5ff20db10a96 180 */
fep 0:5ff20db10a96 181 struct xLIST_ITEM
fep 0:5ff20db10a96 182 {
fep 0:5ff20db10a96 183 listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
fep 0:5ff20db10a96 184 configLIST_VOLATILE TickType_t xItemValue; /*< The value being listed. In most cases this is used to sort the list in descending order. */
fep 0:5ff20db10a96 185 struct xLIST_ITEM * configLIST_VOLATILE pxNext; /*< Pointer to the next ListItem_t in the list. */
fep 0:5ff20db10a96 186 struct xLIST_ITEM * configLIST_VOLATILE pxPrevious; /*< Pointer to the previous ListItem_t in the list. */
fep 0:5ff20db10a96 187 void * pvOwner; /*< Pointer to the object (normally a TCB) that contains the list item. There is therefore a two way link between the object containing the list item and the list item itself. */
fep 0:5ff20db10a96 188 void * configLIST_VOLATILE pvContainer; /*< Pointer to the list in which this list item is placed (if any). */
fep 0:5ff20db10a96 189 listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
fep 0:5ff20db10a96 190 };
fep 0:5ff20db10a96 191 typedef struct xLIST_ITEM ListItem_t; /* For some reason lint wants this as two separate definitions. */
fep 0:5ff20db10a96 192
fep 0:5ff20db10a96 193 struct xMINI_LIST_ITEM
fep 0:5ff20db10a96 194 {
fep 0:5ff20db10a96 195 listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
fep 0:5ff20db10a96 196 configLIST_VOLATILE TickType_t xItemValue;
fep 0:5ff20db10a96 197 struct xLIST_ITEM * configLIST_VOLATILE pxNext;
fep 0:5ff20db10a96 198 struct xLIST_ITEM * configLIST_VOLATILE pxPrevious;
fep 0:5ff20db10a96 199 };
fep 0:5ff20db10a96 200 typedef struct xMINI_LIST_ITEM MiniListItem_t;
fep 0:5ff20db10a96 201
fep 0:5ff20db10a96 202 /*
fep 0:5ff20db10a96 203 * Definition of the type of queue used by the scheduler.
fep 0:5ff20db10a96 204 */
fep 0:5ff20db10a96 205 typedef struct xLIST
fep 0:5ff20db10a96 206 {
fep 0:5ff20db10a96 207 listFIRST_LIST_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
fep 0:5ff20db10a96 208 configLIST_VOLATILE UBaseType_t uxNumberOfItems;
fep 0:5ff20db10a96 209 ListItem_t * configLIST_VOLATILE pxIndex; /*< Used to walk through the list. Points to the last item returned by a call to listGET_OWNER_OF_NEXT_ENTRY (). */
fep 0:5ff20db10a96 210 MiniListItem_t xListEnd; /*< List item that contains the maximum possible item value meaning it is always at the end of the list and is therefore used as a marker. */
fep 0:5ff20db10a96 211 listSECOND_LIST_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
fep 0:5ff20db10a96 212 } List_t;
fep 0:5ff20db10a96 213
fep 0:5ff20db10a96 214 /*
fep 0:5ff20db10a96 215 * Access macro to set the owner of a list item. The owner of a list item
fep 0:5ff20db10a96 216 * is the object (usually a TCB) that contains the list item.
fep 0:5ff20db10a96 217 *
fep 0:5ff20db10a96 218 * \page listSET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER
fep 0:5ff20db10a96 219 * \ingroup LinkedList
fep 0:5ff20db10a96 220 */
fep 0:5ff20db10a96 221 #define listSET_LIST_ITEM_OWNER( pxListItem, pxOwner ) ( ( pxListItem )->pvOwner = ( void * ) ( pxOwner ) )
fep 0:5ff20db10a96 222
fep 0:5ff20db10a96 223 /*
fep 0:5ff20db10a96 224 * Access macro to get the owner of a list item. The owner of a list item
fep 0:5ff20db10a96 225 * is the object (usually a TCB) that contains the list item.
fep 0:5ff20db10a96 226 *
fep 0:5ff20db10a96 227 * \page listSET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER
fep 0:5ff20db10a96 228 * \ingroup LinkedList
fep 0:5ff20db10a96 229 */
fep 0:5ff20db10a96 230 #define listGET_LIST_ITEM_OWNER( pxListItem ) ( ( pxListItem )->pvOwner )
fep 0:5ff20db10a96 231
fep 0:5ff20db10a96 232 /*
fep 0:5ff20db10a96 233 * Access macro to set the value of the list item. In most cases the value is
fep 0:5ff20db10a96 234 * used to sort the list in descending order.
fep 0:5ff20db10a96 235 *
fep 0:5ff20db10a96 236 * \page listSET_LIST_ITEM_VALUE listSET_LIST_ITEM_VALUE
fep 0:5ff20db10a96 237 * \ingroup LinkedList
fep 0:5ff20db10a96 238 */
fep 0:5ff20db10a96 239 #define listSET_LIST_ITEM_VALUE( pxListItem, xValue ) ( ( pxListItem )->xItemValue = ( xValue ) )
fep 0:5ff20db10a96 240
fep 0:5ff20db10a96 241 /*
fep 0:5ff20db10a96 242 * Access macro to retrieve the value of the list item. The value can
fep 0:5ff20db10a96 243 * represent anything - for example the priority of a task, or the time at
fep 0:5ff20db10a96 244 * which a task should be unblocked.
fep 0:5ff20db10a96 245 *
fep 0:5ff20db10a96 246 * \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE
fep 0:5ff20db10a96 247 * \ingroup LinkedList
fep 0:5ff20db10a96 248 */
fep 0:5ff20db10a96 249 #define listGET_LIST_ITEM_VALUE( pxListItem ) ( ( pxListItem )->xItemValue )
fep 0:5ff20db10a96 250
fep 0:5ff20db10a96 251 /*
fep 0:5ff20db10a96 252 * Access macro to retrieve the value of the list item at the head of a given
fep 0:5ff20db10a96 253 * list.
fep 0:5ff20db10a96 254 *
fep 0:5ff20db10a96 255 * \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE
fep 0:5ff20db10a96 256 * \ingroup LinkedList
fep 0:5ff20db10a96 257 */
fep 0:5ff20db10a96 258 #define listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxList ) ( ( ( pxList )->xListEnd ).pxNext->xItemValue )
fep 0:5ff20db10a96 259
fep 0:5ff20db10a96 260 /*
fep 0:5ff20db10a96 261 * Return the list item at the head of the list.
fep 0:5ff20db10a96 262 *
fep 0:5ff20db10a96 263 * \page listGET_HEAD_ENTRY listGET_HEAD_ENTRY
fep 0:5ff20db10a96 264 * \ingroup LinkedList
fep 0:5ff20db10a96 265 */
fep 0:5ff20db10a96 266 #define listGET_HEAD_ENTRY( pxList ) ( ( ( pxList )->xListEnd ).pxNext )
fep 0:5ff20db10a96 267
fep 0:5ff20db10a96 268 /*
fep 0:5ff20db10a96 269 * Return the list item at the head of the list.
fep 0:5ff20db10a96 270 *
fep 0:5ff20db10a96 271 * \page listGET_NEXT listGET_NEXT
fep 0:5ff20db10a96 272 * \ingroup LinkedList
fep 0:5ff20db10a96 273 */
fep 0:5ff20db10a96 274 #define listGET_NEXT( pxListItem ) ( ( pxListItem )->pxNext )
fep 0:5ff20db10a96 275
fep 0:5ff20db10a96 276 /*
fep 0:5ff20db10a96 277 * Return the list item that marks the end of the list
fep 0:5ff20db10a96 278 *
fep 0:5ff20db10a96 279 * \page listGET_END_MARKER listGET_END_MARKER
fep 0:5ff20db10a96 280 * \ingroup LinkedList
fep 0:5ff20db10a96 281 */
fep 0:5ff20db10a96 282 #define listGET_END_MARKER( pxList ) ( ( ListItem_t const * ) ( &( ( pxList )->xListEnd ) ) )
fep 0:5ff20db10a96 283
fep 0:5ff20db10a96 284 /*
fep 0:5ff20db10a96 285 * Access macro to determine if a list contains any items. The macro will
fep 0:5ff20db10a96 286 * only have the value true if the list is empty.
fep 0:5ff20db10a96 287 *
fep 0:5ff20db10a96 288 * \page listLIST_IS_EMPTY listLIST_IS_EMPTY
fep 0:5ff20db10a96 289 * \ingroup LinkedList
fep 0:5ff20db10a96 290 */
fep 0:5ff20db10a96 291 #define listLIST_IS_EMPTY( pxList ) ( ( BaseType_t ) ( ( pxList )->uxNumberOfItems == ( UBaseType_t ) 0 ) )
fep 0:5ff20db10a96 292
fep 0:5ff20db10a96 293 /*
fep 0:5ff20db10a96 294 * Access macro to return the number of items in the list.
fep 0:5ff20db10a96 295 */
fep 0:5ff20db10a96 296 #define listCURRENT_LIST_LENGTH( pxList ) ( ( pxList )->uxNumberOfItems )
fep 0:5ff20db10a96 297
fep 0:5ff20db10a96 298 /*
fep 0:5ff20db10a96 299 * Access function to obtain the owner of the next entry in a list.
fep 0:5ff20db10a96 300 *
fep 0:5ff20db10a96 301 * The list member pxIndex is used to walk through a list. Calling
fep 0:5ff20db10a96 302 * listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list
fep 0:5ff20db10a96 303 * and returns that entry's pxOwner parameter. Using multiple calls to this
fep 0:5ff20db10a96 304 * function it is therefore possible to move through every item contained in
fep 0:5ff20db10a96 305 * a list.
fep 0:5ff20db10a96 306 *
fep 0:5ff20db10a96 307 * The pxOwner parameter of a list item is a pointer to the object that owns
fep 0:5ff20db10a96 308 * the list item. In the scheduler this is normally a task control block.
fep 0:5ff20db10a96 309 * The pxOwner parameter effectively creates a two way link between the list
fep 0:5ff20db10a96 310 * item and its owner.
fep 0:5ff20db10a96 311 *
fep 0:5ff20db10a96 312 * @param pxTCB pxTCB is set to the address of the owner of the next list item.
fep 0:5ff20db10a96 313 * @param pxList The list from which the next item owner is to be returned.
fep 0:5ff20db10a96 314 *
fep 0:5ff20db10a96 315 * \page listGET_OWNER_OF_NEXT_ENTRY listGET_OWNER_OF_NEXT_ENTRY
fep 0:5ff20db10a96 316 * \ingroup LinkedList
fep 0:5ff20db10a96 317 */
fep 0:5ff20db10a96 318 #define listGET_OWNER_OF_NEXT_ENTRY( pxTCB, pxList ) \
fep 0:5ff20db10a96 319 { \
fep 0:5ff20db10a96 320 List_t * const pxConstList = ( pxList ); \
fep 0:5ff20db10a96 321 /* Increment the index to the next item and return the item, ensuring */ \
fep 0:5ff20db10a96 322 /* we don't return the marker used at the end of the list. */ \
fep 0:5ff20db10a96 323 ( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext; \
fep 0:5ff20db10a96 324 if( ( void * ) ( pxConstList )->pxIndex == ( void * ) &( ( pxConstList )->xListEnd ) ) \
fep 0:5ff20db10a96 325 { \
fep 0:5ff20db10a96 326 ( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext; \
fep 0:5ff20db10a96 327 } \
fep 0:5ff20db10a96 328 ( pxTCB ) = ( pxConstList )->pxIndex->pvOwner; \
fep 0:5ff20db10a96 329 }
fep 0:5ff20db10a96 330
fep 0:5ff20db10a96 331
fep 0:5ff20db10a96 332 /*
fep 0:5ff20db10a96 333 * Access function to obtain the owner of the first entry in a list. Lists
fep 0:5ff20db10a96 334 * are normally sorted in ascending item value order.
fep 0:5ff20db10a96 335 *
fep 0:5ff20db10a96 336 * This function returns the pxOwner member of the first item in the list.
fep 0:5ff20db10a96 337 * The pxOwner parameter of a list item is a pointer to the object that owns
fep 0:5ff20db10a96 338 * the list item. In the scheduler this is normally a task control block.
fep 0:5ff20db10a96 339 * The pxOwner parameter effectively creates a two way link between the list
fep 0:5ff20db10a96 340 * item and its owner.
fep 0:5ff20db10a96 341 *
fep 0:5ff20db10a96 342 * @param pxList The list from which the owner of the head item is to be
fep 0:5ff20db10a96 343 * returned.
fep 0:5ff20db10a96 344 *
fep 0:5ff20db10a96 345 * \page listGET_OWNER_OF_HEAD_ENTRY listGET_OWNER_OF_HEAD_ENTRY
fep 0:5ff20db10a96 346 * \ingroup LinkedList
fep 0:5ff20db10a96 347 */
fep 0:5ff20db10a96 348 #define listGET_OWNER_OF_HEAD_ENTRY( pxList ) ( (&( ( pxList )->xListEnd ))->pxNext->pvOwner )
fep 0:5ff20db10a96 349
fep 0:5ff20db10a96 350 /*
fep 0:5ff20db10a96 351 * Check to see if a list item is within a list. The list item maintains a
fep 0:5ff20db10a96 352 * "container" pointer that points to the list it is in. All this macro does
fep 0:5ff20db10a96 353 * is check to see if the container and the list match.
fep 0:5ff20db10a96 354 *
fep 0:5ff20db10a96 355 * @param pxList The list we want to know if the list item is within.
fep 0:5ff20db10a96 356 * @param pxListItem The list item we want to know if is in the list.
fep 0:5ff20db10a96 357 * @return pdTRUE if the list item is in the list, otherwise pdFALSE.
fep 0:5ff20db10a96 358 */
fep 0:5ff20db10a96 359 #define listIS_CONTAINED_WITHIN( pxList, pxListItem ) ( ( BaseType_t ) ( ( pxListItem )->pvContainer == ( void * ) ( pxList ) ) )
fep 0:5ff20db10a96 360
fep 0:5ff20db10a96 361 /*
fep 0:5ff20db10a96 362 * Return the list a list item is contained within (referenced from).
fep 0:5ff20db10a96 363 *
fep 0:5ff20db10a96 364 * @param pxListItem The list item being queried.
fep 0:5ff20db10a96 365 * @return A pointer to the List_t object that references the pxListItem
fep 0:5ff20db10a96 366 */
fep 0:5ff20db10a96 367 #define listLIST_ITEM_CONTAINER( pxListItem ) ( ( pxListItem )->pvContainer )
fep 0:5ff20db10a96 368
fep 0:5ff20db10a96 369 /*
fep 0:5ff20db10a96 370 * This provides a crude means of knowing if a list has been initialised, as
fep 0:5ff20db10a96 371 * pxList->xListEnd.xItemValue is set to portMAX_DELAY by the vListInitialise()
fep 0:5ff20db10a96 372 * function.
fep 0:5ff20db10a96 373 */
fep 0:5ff20db10a96 374 #define listLIST_IS_INITIALISED( pxList ) ( ( pxList )->xListEnd.xItemValue == portMAX_DELAY )
fep 0:5ff20db10a96 375
fep 0:5ff20db10a96 376 /*
fep 0:5ff20db10a96 377 * Must be called before a list is used! This initialises all the members
fep 0:5ff20db10a96 378 * of the list structure and inserts the xListEnd item into the list as a
fep 0:5ff20db10a96 379 * marker to the back of the list.
fep 0:5ff20db10a96 380 *
fep 0:5ff20db10a96 381 * @param pxList Pointer to the list being initialised.
fep 0:5ff20db10a96 382 *
fep 0:5ff20db10a96 383 * \page vListInitialise vListInitialise
fep 0:5ff20db10a96 384 * \ingroup LinkedList
fep 0:5ff20db10a96 385 */
fep 0:5ff20db10a96 386 void vListInitialise( List_t * const pxList ) PRIVILEGED_FUNCTION;
fep 0:5ff20db10a96 387
fep 0:5ff20db10a96 388 /*
fep 0:5ff20db10a96 389 * Must be called before a list item is used. This sets the list container to
fep 0:5ff20db10a96 390 * null so the item does not think that it is already contained in a list.
fep 0:5ff20db10a96 391 *
fep 0:5ff20db10a96 392 * @param pxItem Pointer to the list item being initialised.
fep 0:5ff20db10a96 393 *
fep 0:5ff20db10a96 394 * \page vListInitialiseItem vListInitialiseItem
fep 0:5ff20db10a96 395 * \ingroup LinkedList
fep 0:5ff20db10a96 396 */
fep 0:5ff20db10a96 397 void vListInitialiseItem( ListItem_t * const pxItem ) PRIVILEGED_FUNCTION;
fep 0:5ff20db10a96 398
fep 0:5ff20db10a96 399 /*
fep 0:5ff20db10a96 400 * Insert a list item into a list. The item will be inserted into the list in
fep 0:5ff20db10a96 401 * a position determined by its item value (descending item value order).
fep 0:5ff20db10a96 402 *
fep 0:5ff20db10a96 403 * @param pxList The list into which the item is to be inserted.
fep 0:5ff20db10a96 404 *
fep 0:5ff20db10a96 405 * @param pxNewListItem The item that is to be placed in the list.
fep 0:5ff20db10a96 406 *
fep 0:5ff20db10a96 407 * \page vListInsert vListInsert
fep 0:5ff20db10a96 408 * \ingroup LinkedList
fep 0:5ff20db10a96 409 */
fep 0:5ff20db10a96 410 void vListInsert( List_t * const pxList, ListItem_t * const pxNewListItem ) PRIVILEGED_FUNCTION;
fep 0:5ff20db10a96 411
fep 0:5ff20db10a96 412 /*
fep 0:5ff20db10a96 413 * Insert a list item into a list. The item will be inserted in a position
fep 0:5ff20db10a96 414 * such that it will be the last item within the list returned by multiple
fep 0:5ff20db10a96 415 * calls to listGET_OWNER_OF_NEXT_ENTRY.
fep 0:5ff20db10a96 416 *
fep 0:5ff20db10a96 417 * The list member pxIndex is used to walk through a list. Calling
fep 0:5ff20db10a96 418 * listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list.
fep 0:5ff20db10a96 419 * Placing an item in a list using vListInsertEnd effectively places the item
fep 0:5ff20db10a96 420 * in the list position pointed to by pxIndex. This means that every other
fep 0:5ff20db10a96 421 * item within the list will be returned by listGET_OWNER_OF_NEXT_ENTRY before
fep 0:5ff20db10a96 422 * the pxIndex parameter again points to the item being inserted.
fep 0:5ff20db10a96 423 *
fep 0:5ff20db10a96 424 * @param pxList The list into which the item is to be inserted.
fep 0:5ff20db10a96 425 *
fep 0:5ff20db10a96 426 * @param pxNewListItem The list item to be inserted into the list.
fep 0:5ff20db10a96 427 *
fep 0:5ff20db10a96 428 * \page vListInsertEnd vListInsertEnd
fep 0:5ff20db10a96 429 * \ingroup LinkedList
fep 0:5ff20db10a96 430 */
fep 0:5ff20db10a96 431 void vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem ) PRIVILEGED_FUNCTION;
fep 0:5ff20db10a96 432
fep 0:5ff20db10a96 433 /*
fep 0:5ff20db10a96 434 * Remove an item from a list. The list item has a pointer to the list that
fep 0:5ff20db10a96 435 * it is in, so only the list item need be passed into the function.
fep 0:5ff20db10a96 436 *
fep 0:5ff20db10a96 437 * @param uxListRemove The item to be removed. The item will remove itself from
fep 0:5ff20db10a96 438 * the list pointed to by it's pxContainer parameter.
fep 0:5ff20db10a96 439 *
fep 0:5ff20db10a96 440 * @return The number of items that remain in the list after the list item has
fep 0:5ff20db10a96 441 * been removed.
fep 0:5ff20db10a96 442 *
fep 0:5ff20db10a96 443 * \page uxListRemove uxListRemove
fep 0:5ff20db10a96 444 * \ingroup LinkedList
fep 0:5ff20db10a96 445 */
fep 0:5ff20db10a96 446 UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove ) PRIVILEGED_FUNCTION;
fep 0:5ff20db10a96 447
fep 0:5ff20db10a96 448 #ifdef __cplusplus
fep 0:5ff20db10a96 449 }
fep 0:5ff20db10a96 450 #endif
fep 0:5ff20db10a96 451
fep 0:5ff20db10a96 452 #endif
fep 0:5ff20db10a96 453
fep 0:5ff20db10a96 454