├── LICENSE ├── README.md └── Simulator_Linux ├── FreeRTOS_Kernel ├── croutine.c ├── include │ ├── FreeRTOS.h │ ├── StackMacros.h │ ├── croutine.h │ ├── deprecated_definitions.h │ ├── event_groups.h │ ├── list.h │ ├── message_buffer.h │ ├── mpu_prototypes.h │ ├── mpu_wrappers.h │ ├── portable.h │ ├── projdefs.h │ ├── queue.h │ ├── semphr.h │ ├── stack_macros.h │ ├── stdint.readme │ ├── stream_buffer.h │ ├── task.h │ └── timers.h ├── list.c ├── portable │ ├── GCC │ │ └── Posix │ │ │ ├── port.c │ │ │ └── portmacro.h │ ├── MemMang │ │ └── heap_3.c │ └── readme.txt ├── queue.c ├── subdir.mk └── tasks.c ├── Makefile ├── SConstruct ├── inc ├── FreeRTOSConfig.h └── main.h ├── src └── main.c └── subdir.mk /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Crazy Skady 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FreeRTOS_study 2 | This project created for studying FreeRTOS. 3 | 4 | # Simulator_Linux: 5 | 6 | This is a simulator of freeRTOS in LINUX. 7 | 8 | make all/clean are supported. 9 | 10 | Two simple tasks created and send/receive data between them in the example. 11 | 12 | SConstruct have been added for build. "scons" for build, "scons -c" for clear all build target. 13 | 14 | Note: please create a directory named "tmp" in root directory before make, otherwise will make failed. I am lazy to auto create a blank "tmp" in Makefile. >_< 15 | -------------------------------------------------------------------------------- /Simulator_Linux/FreeRTOS_Kernel/croutine.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.0.0 3 | * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. If you wish to use our Amazon 14 | * FreeRTOS name, please do so in a fair use way that does not cause confusion. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | * http://www.FreeRTOS.org 24 | * http://aws.amazon.com/freertos 25 | * 26 | * 1 tab == 4 spaces! 27 | */ 28 | 29 | #include "FreeRTOS.h" 30 | #include "task.h" 31 | #include "croutine.h" 32 | 33 | /* Remove the whole file is co-routines are not being used. */ 34 | #if( configUSE_CO_ROUTINES != 0 ) 35 | 36 | /* 37 | * Some kernel aware debuggers require data to be viewed to be global, rather 38 | * than file scope. 39 | */ 40 | #ifdef portREMOVE_STATIC_QUALIFIER 41 | #define static 42 | #endif 43 | 44 | 45 | /* Lists for ready and blocked co-routines. --------------------*/ 46 | static List_t pxReadyCoRoutineLists[ configMAX_CO_ROUTINE_PRIORITIES ]; /*< Prioritised ready co-routines. */ 47 | static List_t xDelayedCoRoutineList1; /*< Delayed co-routines. */ 48 | static List_t xDelayedCoRoutineList2; /*< Delayed co-routines (two lists are used - one for delays that have overflowed the current tick count. */ 49 | static List_t * pxDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used. */ 50 | static List_t * pxOverflowDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used to hold co-routines that have overflowed the current tick count. */ 51 | static List_t xPendingReadyCoRoutineList; /*< Holds co-routines that have been readied by an external event. They cannot be added directly to the ready lists as the ready lists cannot be accessed by interrupts. */ 52 | 53 | /* Other file private variables. --------------------------------*/ 54 | CRCB_t * pxCurrentCoRoutine = NULL; 55 | static UBaseType_t uxTopCoRoutineReadyPriority = 0; 56 | static TickType_t xCoRoutineTickCount = 0, xLastTickCount = 0, xPassedTicks = 0; 57 | 58 | /* The initial state of the co-routine when it is created. */ 59 | #define corINITIAL_STATE ( 0 ) 60 | 61 | /* 62 | * Place the co-routine represented by pxCRCB into the appropriate ready queue 63 | * for the priority. It is inserted at the end of the list. 64 | * 65 | * This macro accesses the co-routine ready lists and therefore must not be 66 | * used from within an ISR. 67 | */ 68 | #define prvAddCoRoutineToReadyQueue( pxCRCB ) \ 69 | { \ 70 | if( pxCRCB->uxPriority > uxTopCoRoutineReadyPriority ) \ 71 | { \ 72 | uxTopCoRoutineReadyPriority = pxCRCB->uxPriority; \ 73 | } \ 74 | vListInsertEnd( ( List_t * ) &( pxReadyCoRoutineLists[ pxCRCB->uxPriority ] ), &( pxCRCB->xGenericListItem ) ); \ 75 | } 76 | 77 | /* 78 | * Utility to ready all the lists used by the scheduler. This is called 79 | * automatically upon the creation of the first co-routine. 80 | */ 81 | static void prvInitialiseCoRoutineLists( void ); 82 | 83 | /* 84 | * Co-routines that are readied by an interrupt cannot be placed directly into 85 | * the ready lists (there is no mutual exclusion). Instead they are placed in 86 | * in the pending ready list in order that they can later be moved to the ready 87 | * list by the co-routine scheduler. 88 | */ 89 | static void prvCheckPendingReadyList( void ); 90 | 91 | /* 92 | * Macro that looks at the list of co-routines that are currently delayed to 93 | * see if any require waking. 94 | * 95 | * Co-routines are stored in the queue in the order of their wake time - 96 | * meaning once one co-routine has been found whose timer has not expired 97 | * we need not look any further down the list. 98 | */ 99 | static void prvCheckDelayedList( void ); 100 | 101 | /*-----------------------------------------------------------*/ 102 | 103 | BaseType_t xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, UBaseType_t uxPriority, UBaseType_t uxIndex ) 104 | { 105 | BaseType_t xReturn; 106 | CRCB_t *pxCoRoutine; 107 | 108 | /* Allocate the memory that will store the co-routine control block. */ 109 | pxCoRoutine = ( CRCB_t * ) pvPortMalloc( sizeof( CRCB_t ) ); 110 | if( pxCoRoutine ) 111 | { 112 | /* If pxCurrentCoRoutine is NULL then this is the first co-routine to 113 | be created and the co-routine data structures need initialising. */ 114 | if( pxCurrentCoRoutine == NULL ) 115 | { 116 | pxCurrentCoRoutine = pxCoRoutine; 117 | prvInitialiseCoRoutineLists(); 118 | } 119 | 120 | /* Check the priority is within limits. */ 121 | if( uxPriority >= configMAX_CO_ROUTINE_PRIORITIES ) 122 | { 123 | uxPriority = configMAX_CO_ROUTINE_PRIORITIES - 1; 124 | } 125 | 126 | /* Fill out the co-routine control block from the function parameters. */ 127 | pxCoRoutine->uxState = corINITIAL_STATE; 128 | pxCoRoutine->uxPriority = uxPriority; 129 | pxCoRoutine->uxIndex = uxIndex; 130 | pxCoRoutine->pxCoRoutineFunction = pxCoRoutineCode; 131 | 132 | /* Initialise all the other co-routine control block parameters. */ 133 | vListInitialiseItem( &( pxCoRoutine->xGenericListItem ) ); 134 | vListInitialiseItem( &( pxCoRoutine->xEventListItem ) ); 135 | 136 | /* Set the co-routine control block as a link back from the ListItem_t. 137 | This is so we can get back to the containing CRCB from a generic item 138 | in a list. */ 139 | listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xGenericListItem ), pxCoRoutine ); 140 | listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xEventListItem ), pxCoRoutine ); 141 | 142 | /* Event lists are always in priority order. */ 143 | listSET_LIST_ITEM_VALUE( &( pxCoRoutine->xEventListItem ), ( ( TickType_t ) configMAX_CO_ROUTINE_PRIORITIES - ( TickType_t ) uxPriority ) ); 144 | 145 | /* Now the co-routine has been initialised it can be added to the ready 146 | list at the correct priority. */ 147 | prvAddCoRoutineToReadyQueue( pxCoRoutine ); 148 | 149 | xReturn = pdPASS; 150 | } 151 | else 152 | { 153 | xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY; 154 | } 155 | 156 | return xReturn; 157 | } 158 | /*-----------------------------------------------------------*/ 159 | 160 | void vCoRoutineAddToDelayedList( TickType_t xTicksToDelay, List_t *pxEventList ) 161 | { 162 | TickType_t xTimeToWake; 163 | 164 | /* Calculate the time to wake - this may overflow but this is 165 | not a problem. */ 166 | xTimeToWake = xCoRoutineTickCount + xTicksToDelay; 167 | 168 | /* We must remove ourselves from the ready list before adding 169 | ourselves to the blocked list as the same list item is used for 170 | both lists. */ 171 | ( void ) uxListRemove( ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) ); 172 | 173 | /* The list item will be inserted in wake time order. */ 174 | listSET_LIST_ITEM_VALUE( &( pxCurrentCoRoutine->xGenericListItem ), xTimeToWake ); 175 | 176 | if( xTimeToWake < xCoRoutineTickCount ) 177 | { 178 | /* Wake time has overflowed. Place this item in the 179 | overflow list. */ 180 | vListInsert( ( List_t * ) pxOverflowDelayedCoRoutineList, ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) ); 181 | } 182 | else 183 | { 184 | /* The wake time has not overflowed, so we can use the 185 | current block list. */ 186 | vListInsert( ( List_t * ) pxDelayedCoRoutineList, ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) ); 187 | } 188 | 189 | if( pxEventList ) 190 | { 191 | /* Also add the co-routine to an event list. If this is done then the 192 | function must be called with interrupts disabled. */ 193 | vListInsert( pxEventList, &( pxCurrentCoRoutine->xEventListItem ) ); 194 | } 195 | } 196 | /*-----------------------------------------------------------*/ 197 | 198 | static void prvCheckPendingReadyList( void ) 199 | { 200 | /* Are there any co-routines waiting to get moved to the ready list? These 201 | are co-routines that have been readied by an ISR. The ISR cannot access 202 | the ready lists itself. */ 203 | while( listLIST_IS_EMPTY( &xPendingReadyCoRoutineList ) == pdFALSE ) 204 | { 205 | CRCB_t *pxUnblockedCRCB; 206 | 207 | /* The pending ready list can be accessed by an ISR. */ 208 | portDISABLE_INTERRUPTS(); 209 | { 210 | pxUnblockedCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( (&xPendingReadyCoRoutineList) ); 211 | ( void ) uxListRemove( &( pxUnblockedCRCB->xEventListItem ) ); 212 | } 213 | portENABLE_INTERRUPTS(); 214 | 215 | ( void ) uxListRemove( &( pxUnblockedCRCB->xGenericListItem ) ); 216 | prvAddCoRoutineToReadyQueue( pxUnblockedCRCB ); 217 | } 218 | } 219 | /*-----------------------------------------------------------*/ 220 | 221 | static void prvCheckDelayedList( void ) 222 | { 223 | CRCB_t *pxCRCB; 224 | 225 | xPassedTicks = xTaskGetTickCount() - xLastTickCount; 226 | while( xPassedTicks ) 227 | { 228 | xCoRoutineTickCount++; 229 | xPassedTicks--; 230 | 231 | /* If the tick count has overflowed we need to swap the ready lists. */ 232 | if( xCoRoutineTickCount == 0 ) 233 | { 234 | List_t * pxTemp; 235 | 236 | /* Tick count has overflowed so we need to swap the delay lists. If there are 237 | any items in pxDelayedCoRoutineList here then there is an error! */ 238 | pxTemp = pxDelayedCoRoutineList; 239 | pxDelayedCoRoutineList = pxOverflowDelayedCoRoutineList; 240 | pxOverflowDelayedCoRoutineList = pxTemp; 241 | } 242 | 243 | /* See if this tick has made a timeout expire. */ 244 | while( listLIST_IS_EMPTY( pxDelayedCoRoutineList ) == pdFALSE ) 245 | { 246 | pxCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedCoRoutineList ); 247 | 248 | if( xCoRoutineTickCount < listGET_LIST_ITEM_VALUE( &( pxCRCB->xGenericListItem ) ) ) 249 | { 250 | /* Timeout not yet expired. */ 251 | break; 252 | } 253 | 254 | portDISABLE_INTERRUPTS(); 255 | { 256 | /* The event could have occurred just before this critical 257 | section. If this is the case then the generic list item will 258 | have been moved to the pending ready list and the following 259 | line is still valid. Also the pvContainer parameter will have 260 | been set to NULL so the following lines are also valid. */ 261 | ( void ) uxListRemove( &( pxCRCB->xGenericListItem ) ); 262 | 263 | /* Is the co-routine waiting on an event also? */ 264 | if( pxCRCB->xEventListItem.pvContainer ) 265 | { 266 | ( void ) uxListRemove( &( pxCRCB->xEventListItem ) ); 267 | } 268 | } 269 | portENABLE_INTERRUPTS(); 270 | 271 | prvAddCoRoutineToReadyQueue( pxCRCB ); 272 | } 273 | } 274 | 275 | xLastTickCount = xCoRoutineTickCount; 276 | } 277 | /*-----------------------------------------------------------*/ 278 | 279 | void vCoRoutineSchedule( void ) 280 | { 281 | /* See if any co-routines readied by events need moving to the ready lists. */ 282 | prvCheckPendingReadyList(); 283 | 284 | /* See if any delayed co-routines have timed out. */ 285 | prvCheckDelayedList(); 286 | 287 | /* Find the highest priority queue that contains ready co-routines. */ 288 | while( listLIST_IS_EMPTY( &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) ) ) 289 | { 290 | if( uxTopCoRoutineReadyPriority == 0 ) 291 | { 292 | /* No more co-routines to check. */ 293 | return; 294 | } 295 | --uxTopCoRoutineReadyPriority; 296 | } 297 | 298 | /* listGET_OWNER_OF_NEXT_ENTRY walks through the list, so the co-routines 299 | of the same priority get an equal share of the processor time. */ 300 | listGET_OWNER_OF_NEXT_ENTRY( pxCurrentCoRoutine, &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) ); 301 | 302 | /* Call the co-routine. */ 303 | ( pxCurrentCoRoutine->pxCoRoutineFunction )( pxCurrentCoRoutine, pxCurrentCoRoutine->uxIndex ); 304 | 305 | return; 306 | } 307 | /*-----------------------------------------------------------*/ 308 | 309 | static void prvInitialiseCoRoutineLists( void ) 310 | { 311 | UBaseType_t uxPriority; 312 | 313 | for( uxPriority = 0; uxPriority < configMAX_CO_ROUTINE_PRIORITIES; uxPriority++ ) 314 | { 315 | vListInitialise( ( List_t * ) &( pxReadyCoRoutineLists[ uxPriority ] ) ); 316 | } 317 | 318 | vListInitialise( ( List_t * ) &xDelayedCoRoutineList1 ); 319 | vListInitialise( ( List_t * ) &xDelayedCoRoutineList2 ); 320 | vListInitialise( ( List_t * ) &xPendingReadyCoRoutineList ); 321 | 322 | /* Start with pxDelayedCoRoutineList using list1 and the 323 | pxOverflowDelayedCoRoutineList using list2. */ 324 | pxDelayedCoRoutineList = &xDelayedCoRoutineList1; 325 | pxOverflowDelayedCoRoutineList = &xDelayedCoRoutineList2; 326 | } 327 | /*-----------------------------------------------------------*/ 328 | 329 | BaseType_t xCoRoutineRemoveFromEventList( const List_t *pxEventList ) 330 | { 331 | CRCB_t *pxUnblockedCRCB; 332 | BaseType_t xReturn; 333 | 334 | /* This function is called from within an interrupt. It can only access 335 | event lists and the pending ready list. This function assumes that a 336 | check has already been made to ensure pxEventList is not empty. */ 337 | pxUnblockedCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList ); 338 | ( void ) uxListRemove( &( pxUnblockedCRCB->xEventListItem ) ); 339 | vListInsertEnd( ( List_t * ) &( xPendingReadyCoRoutineList ), &( pxUnblockedCRCB->xEventListItem ) ); 340 | 341 | if( pxUnblockedCRCB->uxPriority >= pxCurrentCoRoutine->uxPriority ) 342 | { 343 | xReturn = pdTRUE; 344 | } 345 | else 346 | { 347 | xReturn = pdFALSE; 348 | } 349 | 350 | return xReturn; 351 | } 352 | 353 | #endif /* configUSE_CO_ROUTINES == 0 */ 354 | 355 | -------------------------------------------------------------------------------- /Simulator_Linux/FreeRTOS_Kernel/include/StackMacros.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.0.0 3 | * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. If you wish to use our Amazon 14 | * FreeRTOS name, please do so in a fair use way that does not cause confusion. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | * http://www.FreeRTOS.org 24 | * http://aws.amazon.com/freertos 25 | * 26 | * 1 tab == 4 spaces! 27 | */ 28 | 29 | #ifndef STACK_MACROS_H 30 | #define STACK_MACROS_H 31 | 32 | #ifndef _MSC_VER /* Visual Studio doesn't support #warning. */ 33 | #warning The name of this file has changed to stack_macros.h. Please update your code accordingly. This source file (which has the original name) will be removed in future released. 34 | #endif 35 | 36 | /* 37 | * Call the stack overflow hook function if the stack of the task being swapped 38 | * out is currently overflowed, or looks like it might have overflowed in the 39 | * past. 40 | * 41 | * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check 42 | * the current stack state only - comparing the current top of stack value to 43 | * the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1 44 | * will also cause the last few stack bytes to be checked to ensure the value 45 | * to which the bytes were set when the task was created have not been 46 | * overwritten. Note this second test does not guarantee that an overflowed 47 | * stack will always be recognised. 48 | */ 49 | 50 | /*-----------------------------------------------------------*/ 51 | 52 | #if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) ) 53 | 54 | /* Only the current stack state is to be checked. */ 55 | #define taskCHECK_FOR_STACK_OVERFLOW() \ 56 | { \ 57 | /* Is the currently saved stack pointer within the stack limit? */ \ 58 | if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \ 59 | { \ 60 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 61 | } \ 62 | } 63 | 64 | #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ 65 | /*-----------------------------------------------------------*/ 66 | 67 | #if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) ) 68 | 69 | /* Only the current stack state is to be checked. */ 70 | #define taskCHECK_FOR_STACK_OVERFLOW() \ 71 | { \ 72 | \ 73 | /* Is the currently saved stack pointer within the stack limit? */ \ 74 | if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \ 75 | { \ 76 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 77 | } \ 78 | } 79 | 80 | #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ 81 | /*-----------------------------------------------------------*/ 82 | 83 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) ) 84 | 85 | #define taskCHECK_FOR_STACK_OVERFLOW() \ 86 | { \ 87 | const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \ 88 | const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5; \ 89 | \ 90 | if( ( pulStack[ 0 ] != ulCheckValue ) || \ 91 | ( pulStack[ 1 ] != ulCheckValue ) || \ 92 | ( pulStack[ 2 ] != ulCheckValue ) || \ 93 | ( pulStack[ 3 ] != ulCheckValue ) ) \ 94 | { \ 95 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 96 | } \ 97 | } 98 | 99 | #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ 100 | /*-----------------------------------------------------------*/ 101 | 102 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) ) 103 | 104 | #define taskCHECK_FOR_STACK_OVERFLOW() \ 105 | { \ 106 | int8_t *pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \ 107 | static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 108 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 109 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 110 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 111 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ 112 | \ 113 | \ 114 | pcEndOfStack -= sizeof( ucExpectedStackBytes ); \ 115 | \ 116 | /* Has the extremity of the task stack ever been written over? */ \ 117 | if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \ 118 | { \ 119 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 120 | } \ 121 | } 122 | 123 | #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ 124 | /*-----------------------------------------------------------*/ 125 | 126 | /* Remove stack overflow macro if not being used. */ 127 | #ifndef taskCHECK_FOR_STACK_OVERFLOW 128 | #define taskCHECK_FOR_STACK_OVERFLOW() 129 | #endif 130 | 131 | 132 | 133 | #endif /* STACK_MACROS_H */ 134 | 135 | -------------------------------------------------------------------------------- /Simulator_Linux/FreeRTOS_Kernel/include/croutine.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.0.0 3 | * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. If you wish to use our Amazon 14 | * FreeRTOS name, please do so in a fair use way that does not cause confusion. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | * http://www.FreeRTOS.org 24 | * http://aws.amazon.com/freertos 25 | * 26 | * 1 tab == 4 spaces! 27 | */ 28 | 29 | #ifndef CO_ROUTINE_H 30 | #define CO_ROUTINE_H 31 | 32 | #ifndef INC_FREERTOS_H 33 | #error "include FreeRTOS.h must appear in source files before include croutine.h" 34 | #endif 35 | 36 | #include "list.h" 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* Used to hide the implementation of the co-routine control block. The 43 | control block structure however has to be included in the header due to 44 | the macro implementation of the co-routine functionality. */ 45 | typedef void * CoRoutineHandle_t; 46 | 47 | /* Defines the prototype to which co-routine functions must conform. */ 48 | typedef void (*crCOROUTINE_CODE)( CoRoutineHandle_t, UBaseType_t ); 49 | 50 | typedef struct corCoRoutineControlBlock 51 | { 52 | crCOROUTINE_CODE pxCoRoutineFunction; 53 | ListItem_t xGenericListItem; /*< List item used to place the CRCB in ready and blocked queues. */ 54 | ListItem_t xEventListItem; /*< List item used to place the CRCB in event lists. */ 55 | UBaseType_t uxPriority; /*< The priority of the co-routine in relation to other co-routines. */ 56 | UBaseType_t uxIndex; /*< Used to distinguish between co-routines when multiple co-routines use the same co-routine function. */ 57 | uint16_t uxState; /*< Used internally by the co-routine implementation. */ 58 | } CRCB_t; /* Co-routine control block. Note must be identical in size down to uxPriority with TCB_t. */ 59 | 60 | /** 61 | * croutine. h 62 | *
63 | BaseType_t xCoRoutineCreate( 64 | crCOROUTINE_CODE pxCoRoutineCode, 65 | UBaseType_t uxPriority, 66 | UBaseType_t uxIndex 67 | );68 | * 69 | * Create a new co-routine and add it to the list of co-routines that are 70 | * ready to run. 71 | * 72 | * @param pxCoRoutineCode Pointer to the co-routine function. Co-routine 73 | * functions require special syntax - see the co-routine section of the WEB 74 | * documentation for more information. 75 | * 76 | * @param uxPriority The priority with respect to other co-routines at which 77 | * the co-routine will run. 78 | * 79 | * @param uxIndex Used to distinguish between different co-routines that 80 | * execute the same function. See the example below and the co-routine section 81 | * of the WEB documentation for further information. 82 | * 83 | * @return pdPASS if the co-routine was successfully created and added to a ready 84 | * list, otherwise an error code defined with ProjDefs.h. 85 | * 86 | * Example usage: 87 |
88 | // Co-routine to be created. 89 | void vFlashCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex ) 90 | { 91 | // Variables in co-routines must be declared static if they must maintain value across a blocking call. 92 | // This may not be necessary for const variables. 93 | static const char cLedToFlash[ 2 ] = { 5, 6 }; 94 | static const TickType_t uxFlashRates[ 2 ] = { 200, 400 }; 95 | 96 | // Must start every co-routine with a call to crSTART(); 97 | crSTART( xHandle ); 98 | 99 | for( ;; ) 100 | { 101 | // This co-routine just delays for a fixed period, then toggles 102 | // an LED. Two co-routines are created using this function, so 103 | // the uxIndex parameter is used to tell the co-routine which 104 | // LED to flash and how int32_t to delay. This assumes xQueue has 105 | // already been created. 106 | vParTestToggleLED( cLedToFlash[ uxIndex ] ); 107 | crDELAY( xHandle, uxFlashRates[ uxIndex ] ); 108 | } 109 | 110 | // Must end every co-routine with a call to crEND(); 111 | crEND(); 112 | } 113 | 114 | // Function that creates two co-routines. 115 | void vOtherFunction( void ) 116 | { 117 | uint8_t ucParameterToPass; 118 | TaskHandle_t xHandle; 119 | 120 | // Create two co-routines at priority 0. The first is given index 0 121 | // so (from the code above) toggles LED 5 every 200 ticks. The second 122 | // is given index 1 so toggles LED 6 every 400 ticks. 123 | for( uxIndex = 0; uxIndex < 2; uxIndex++ ) 124 | { 125 | xCoRoutineCreate( vFlashCoRoutine, 0, uxIndex ); 126 | } 127 | } 128 |129 | * \defgroup xCoRoutineCreate xCoRoutineCreate 130 | * \ingroup Tasks 131 | */ 132 | BaseType_t xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, UBaseType_t uxPriority, UBaseType_t uxIndex ); 133 | 134 | 135 | /** 136 | * croutine. h 137 | *
138 | void vCoRoutineSchedule( void );139 | * 140 | * Run a co-routine. 141 | * 142 | * vCoRoutineSchedule() executes the highest priority co-routine that is able 143 | * to run. The co-routine will execute until it either blocks, yields or is 144 | * preempted by a task. Co-routines execute cooperatively so one 145 | * co-routine cannot be preempted by another, but can be preempted by a task. 146 | * 147 | * If an application comprises of both tasks and co-routines then 148 | * vCoRoutineSchedule should be called from the idle task (in an idle task 149 | * hook). 150 | * 151 | * Example usage: 152 |
153 | // This idle task hook will schedule a co-routine each time it is called. 154 | // The rest of the idle task will execute between co-routine calls. 155 | void vApplicationIdleHook( void ) 156 | { 157 | vCoRoutineSchedule(); 158 | } 159 | 160 | // Alternatively, if you do not require any other part of the idle task to 161 | // execute, the idle task hook can call vCoRoutineScheduler() within an 162 | // infinite loop. 163 | void vApplicationIdleHook( void ) 164 | { 165 | for( ;; ) 166 | { 167 | vCoRoutineSchedule(); 168 | } 169 | } 170 |171 | * \defgroup vCoRoutineSchedule vCoRoutineSchedule 172 | * \ingroup Tasks 173 | */ 174 | void vCoRoutineSchedule( void ); 175 | 176 | /** 177 | * croutine. h 178 | *
179 | crSTART( CoRoutineHandle_t xHandle );180 | * 181 | * This macro MUST always be called at the start of a co-routine function. 182 | * 183 | * Example usage: 184 |
185 | // Co-routine to be created. 186 | void vACoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex ) 187 | { 188 | // Variables in co-routines must be declared static if they must maintain value across a blocking call. 189 | static int32_t ulAVariable; 190 | 191 | // Must start every co-routine with a call to crSTART(); 192 | crSTART( xHandle ); 193 | 194 | for( ;; ) 195 | { 196 | // Co-routine functionality goes here. 197 | } 198 | 199 | // Must end every co-routine with a call to crEND(); 200 | crEND(); 201 | }202 | * \defgroup crSTART crSTART 203 | * \ingroup Tasks 204 | */ 205 | #define crSTART( pxCRCB ) switch( ( ( CRCB_t * )( pxCRCB ) )->uxState ) { case 0: 206 | 207 | /** 208 | * croutine. h 209 | *
210 | crEND();211 | * 212 | * This macro MUST always be called at the end of a co-routine function. 213 | * 214 | * Example usage: 215 |
216 | // Co-routine to be created. 217 | void vACoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex ) 218 | { 219 | // Variables in co-routines must be declared static if they must maintain value across a blocking call. 220 | static int32_t ulAVariable; 221 | 222 | // Must start every co-routine with a call to crSTART(); 223 | crSTART( xHandle ); 224 | 225 | for( ;; ) 226 | { 227 | // Co-routine functionality goes here. 228 | } 229 | 230 | // Must end every co-routine with a call to crEND(); 231 | crEND(); 232 | }233 | * \defgroup crSTART crSTART 234 | * \ingroup Tasks 235 | */ 236 | #define crEND() } 237 | 238 | /* 239 | * These macros are intended for internal use by the co-routine implementation 240 | * only. The macros should not be used directly by application writers. 241 | */ 242 | #define crSET_STATE0( xHandle ) ( ( CRCB_t * )( xHandle ) )->uxState = (__LINE__ * 2); return; case (__LINE__ * 2): 243 | #define crSET_STATE1( xHandle ) ( ( CRCB_t * )( xHandle ) )->uxState = ((__LINE__ * 2)+1); return; case ((__LINE__ * 2)+1): 244 | 245 | /** 246 | * croutine. h 247 | *
248 | crDELAY( CoRoutineHandle_t xHandle, TickType_t xTicksToDelay );249 | * 250 | * Delay a co-routine for a fixed period of time. 251 | * 252 | * crDELAY can only be called from the co-routine function itself - not 253 | * from within a function called by the co-routine function. This is because 254 | * co-routines do not maintain their own stack. 255 | * 256 | * @param xHandle The handle of the co-routine to delay. This is the xHandle 257 | * parameter of the co-routine function. 258 | * 259 | * @param xTickToDelay The number of ticks that the co-routine should delay 260 | * for. The actual amount of time this equates to is defined by 261 | * configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant portTICK_PERIOD_MS 262 | * can be used to convert ticks to milliseconds. 263 | * 264 | * Example usage: 265 |
266 | // Co-routine to be created. 267 | void vACoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex ) 268 | { 269 | // Variables in co-routines must be declared static if they must maintain value across a blocking call. 270 | // This may not be necessary for const variables. 271 | // We are to delay for 200ms. 272 | static const xTickType xDelayTime = 200 / portTICK_PERIOD_MS; 273 | 274 | // Must start every co-routine with a call to crSTART(); 275 | crSTART( xHandle ); 276 | 277 | for( ;; ) 278 | { 279 | // Delay for 200ms. 280 | crDELAY( xHandle, xDelayTime ); 281 | 282 | // Do something here. 283 | } 284 | 285 | // Must end every co-routine with a call to crEND(); 286 | crEND(); 287 | }288 | * \defgroup crDELAY crDELAY 289 | * \ingroup Tasks 290 | */ 291 | #define crDELAY( xHandle, xTicksToDelay ) \ 292 | if( ( xTicksToDelay ) > 0 ) \ 293 | { \ 294 | vCoRoutineAddToDelayedList( ( xTicksToDelay ), NULL ); \ 295 | } \ 296 | crSET_STATE0( ( xHandle ) ); 297 | 298 | /** 299 | *
300 | crQUEUE_SEND( 301 | CoRoutineHandle_t xHandle, 302 | QueueHandle_t pxQueue, 303 | void *pvItemToQueue, 304 | TickType_t xTicksToWait, 305 | BaseType_t *pxResult 306 | )307 | * 308 | * The macro's crQUEUE_SEND() and crQUEUE_RECEIVE() are the co-routine 309 | * equivalent to the xQueueSend() and xQueueReceive() functions used by tasks. 310 | * 311 | * crQUEUE_SEND and crQUEUE_RECEIVE can only be used from a co-routine whereas 312 | * xQueueSend() and xQueueReceive() can only be used from tasks. 313 | * 314 | * crQUEUE_SEND can only be called from the co-routine function itself - not 315 | * from within a function called by the co-routine function. This is because 316 | * co-routines do not maintain their own stack. 317 | * 318 | * See the co-routine section of the WEB documentation for information on 319 | * passing data between tasks and co-routines and between ISR's and 320 | * co-routines. 321 | * 322 | * @param xHandle The handle of the calling co-routine. This is the xHandle 323 | * parameter of the co-routine function. 324 | * 325 | * @param pxQueue The handle of the queue on which the data will be posted. 326 | * The handle is obtained as the return value when the queue is created using 327 | * the xQueueCreate() API function. 328 | * 329 | * @param pvItemToQueue A pointer to the data being posted onto the queue. 330 | * The number of bytes of each queued item is specified when the queue is 331 | * created. This number of bytes is copied from pvItemToQueue into the queue 332 | * itself. 333 | * 334 | * @param xTickToDelay The number of ticks that the co-routine should block 335 | * to wait for space to become available on the queue, should space not be 336 | * available immediately. The actual amount of time this equates to is defined 337 | * by configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant 338 | * portTICK_PERIOD_MS can be used to convert ticks to milliseconds (see example 339 | * below). 340 | * 341 | * @param pxResult The variable pointed to by pxResult will be set to pdPASS if 342 | * data was successfully posted onto the queue, otherwise it will be set to an 343 | * error defined within ProjDefs.h. 344 | * 345 | * Example usage: 346 |
347 | // Co-routine function that blocks for a fixed period then posts a number onto 348 | // a queue. 349 | static void prvCoRoutineFlashTask( CoRoutineHandle_t xHandle, UBaseType_t uxIndex ) 350 | { 351 | // Variables in co-routines must be declared static if they must maintain value across a blocking call. 352 | static BaseType_t xNumberToPost = 0; 353 | static BaseType_t xResult; 354 | 355 | // Co-routines must begin with a call to crSTART(). 356 | crSTART( xHandle ); 357 | 358 | for( ;; ) 359 | { 360 | // This assumes the queue has already been created. 361 | crQUEUE_SEND( xHandle, xCoRoutineQueue, &xNumberToPost, NO_DELAY, &xResult ); 362 | 363 | if( xResult != pdPASS ) 364 | { 365 | // The message was not posted! 366 | } 367 | 368 | // Increment the number to be posted onto the queue. 369 | xNumberToPost++; 370 | 371 | // Delay for 100 ticks. 372 | crDELAY( xHandle, 100 ); 373 | } 374 | 375 | // Co-routines must end with a call to crEND(). 376 | crEND(); 377 | }378 | * \defgroup crQUEUE_SEND crQUEUE_SEND 379 | * \ingroup Tasks 380 | */ 381 | #define crQUEUE_SEND( xHandle, pxQueue, pvItemToQueue, xTicksToWait, pxResult ) \ 382 | { \ 383 | *( pxResult ) = xQueueCRSend( ( pxQueue) , ( pvItemToQueue) , ( xTicksToWait ) ); \ 384 | if( *( pxResult ) == errQUEUE_BLOCKED ) \ 385 | { \ 386 | crSET_STATE0( ( xHandle ) ); \ 387 | *pxResult = xQueueCRSend( ( pxQueue ), ( pvItemToQueue ), 0 ); \ 388 | } \ 389 | if( *pxResult == errQUEUE_YIELD ) \ 390 | { \ 391 | crSET_STATE1( ( xHandle ) ); \ 392 | *pxResult = pdPASS; \ 393 | } \ 394 | } 395 | 396 | /** 397 | * croutine. h 398 | *
399 | crQUEUE_RECEIVE( 400 | CoRoutineHandle_t xHandle, 401 | QueueHandle_t pxQueue, 402 | void *pvBuffer, 403 | TickType_t xTicksToWait, 404 | BaseType_t *pxResult 405 | )406 | * 407 | * The macro's crQUEUE_SEND() and crQUEUE_RECEIVE() are the co-routine 408 | * equivalent to the xQueueSend() and xQueueReceive() functions used by tasks. 409 | * 410 | * crQUEUE_SEND and crQUEUE_RECEIVE can only be used from a co-routine whereas 411 | * xQueueSend() and xQueueReceive() can only be used from tasks. 412 | * 413 | * crQUEUE_RECEIVE can only be called from the co-routine function itself - not 414 | * from within a function called by the co-routine function. This is because 415 | * co-routines do not maintain their own stack. 416 | * 417 | * See the co-routine section of the WEB documentation for information on 418 | * passing data between tasks and co-routines and between ISR's and 419 | * co-routines. 420 | * 421 | * @param xHandle The handle of the calling co-routine. This is the xHandle 422 | * parameter of the co-routine function. 423 | * 424 | * @param pxQueue The handle of the queue from which the data will be received. 425 | * The handle is obtained as the return value when the queue is created using 426 | * the xQueueCreate() API function. 427 | * 428 | * @param pvBuffer The buffer into which the received item is to be copied. 429 | * The number of bytes of each queued item is specified when the queue is 430 | * created. This number of bytes is copied into pvBuffer. 431 | * 432 | * @param xTickToDelay The number of ticks that the co-routine should block 433 | * to wait for data to become available from the queue, should data not be 434 | * available immediately. The actual amount of time this equates to is defined 435 | * by configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant 436 | * portTICK_PERIOD_MS can be used to convert ticks to milliseconds (see the 437 | * crQUEUE_SEND example). 438 | * 439 | * @param pxResult The variable pointed to by pxResult will be set to pdPASS if 440 | * data was successfully retrieved from the queue, otherwise it will be set to 441 | * an error code as defined within ProjDefs.h. 442 | * 443 | * Example usage: 444 |
445 | // A co-routine receives the number of an LED to flash from a queue. It 446 | // blocks on the queue until the number is received. 447 | static void prvCoRoutineFlashWorkTask( CoRoutineHandle_t xHandle, UBaseType_t uxIndex ) 448 | { 449 | // Variables in co-routines must be declared static if they must maintain value across a blocking call. 450 | static BaseType_t xResult; 451 | static UBaseType_t uxLEDToFlash; 452 | 453 | // All co-routines must start with a call to crSTART(). 454 | crSTART( xHandle ); 455 | 456 | for( ;; ) 457 | { 458 | // Wait for data to become available on the queue. 459 | crQUEUE_RECEIVE( xHandle, xCoRoutineQueue, &uxLEDToFlash, portMAX_DELAY, &xResult ); 460 | 461 | if( xResult == pdPASS ) 462 | { 463 | // We received the LED to flash - flash it! 464 | vParTestToggleLED( uxLEDToFlash ); 465 | } 466 | } 467 | 468 | crEND(); 469 | }470 | * \defgroup crQUEUE_RECEIVE crQUEUE_RECEIVE 471 | * \ingroup Tasks 472 | */ 473 | #define crQUEUE_RECEIVE( xHandle, pxQueue, pvBuffer, xTicksToWait, pxResult ) \ 474 | { \ 475 | *( pxResult ) = xQueueCRReceive( ( pxQueue) , ( pvBuffer ), ( xTicksToWait ) ); \ 476 | if( *( pxResult ) == errQUEUE_BLOCKED ) \ 477 | { \ 478 | crSET_STATE0( ( xHandle ) ); \ 479 | *( pxResult ) = xQueueCRReceive( ( pxQueue) , ( pvBuffer ), 0 ); \ 480 | } \ 481 | if( *( pxResult ) == errQUEUE_YIELD ) \ 482 | { \ 483 | crSET_STATE1( ( xHandle ) ); \ 484 | *( pxResult ) = pdPASS; \ 485 | } \ 486 | } 487 | 488 | /** 489 | * croutine. h 490 | *
491 | crQUEUE_SEND_FROM_ISR( 492 | QueueHandle_t pxQueue, 493 | void *pvItemToQueue, 494 | BaseType_t xCoRoutinePreviouslyWoken 495 | )496 | * 497 | * The macro's crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() are the 498 | * co-routine equivalent to the xQueueSendFromISR() and xQueueReceiveFromISR() 499 | * functions used by tasks. 500 | * 501 | * crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() can only be used to 502 | * pass data between a co-routine and and ISR, whereas xQueueSendFromISR() and 503 | * xQueueReceiveFromISR() can only be used to pass data between a task and and 504 | * ISR. 505 | * 506 | * crQUEUE_SEND_FROM_ISR can only be called from an ISR to send data to a queue 507 | * that is being used from within a co-routine. 508 | * 509 | * See the co-routine section of the WEB documentation for information on 510 | * passing data between tasks and co-routines and between ISR's and 511 | * co-routines. 512 | * 513 | * @param xQueue The handle to the queue on which the item is to be posted. 514 | * 515 | * @param pvItemToQueue A pointer to the item that is to be placed on the 516 | * queue. The size of the items the queue will hold was defined when the 517 | * queue was created, so this many bytes will be copied from pvItemToQueue 518 | * into the queue storage area. 519 | * 520 | * @param xCoRoutinePreviouslyWoken This is included so an ISR can post onto 521 | * the same queue multiple times from a single interrupt. The first call 522 | * should always pass in pdFALSE. Subsequent calls should pass in 523 | * the value returned from the previous call. 524 | * 525 | * @return pdTRUE if a co-routine was woken by posting onto the queue. This is 526 | * used by the ISR to determine if a context switch may be required following 527 | * the ISR. 528 | * 529 | * Example usage: 530 |
531 | // A co-routine that blocks on a queue waiting for characters to be received. 532 | static void vReceivingCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex ) 533 | { 534 | char cRxedChar; 535 | BaseType_t xResult; 536 | 537 | // All co-routines must start with a call to crSTART(). 538 | crSTART( xHandle ); 539 | 540 | for( ;; ) 541 | { 542 | // Wait for data to become available on the queue. This assumes the 543 | // queue xCommsRxQueue has already been created! 544 | crQUEUE_RECEIVE( xHandle, xCommsRxQueue, &uxLEDToFlash, portMAX_DELAY, &xResult ); 545 | 546 | // Was a character received? 547 | if( xResult == pdPASS ) 548 | { 549 | // Process the character here. 550 | } 551 | } 552 | 553 | // All co-routines must end with a call to crEND(). 554 | crEND(); 555 | } 556 | 557 | // An ISR that uses a queue to send characters received on a serial port to 558 | // a co-routine. 559 | void vUART_ISR( void ) 560 | { 561 | char cRxedChar; 562 | BaseType_t xCRWokenByPost = pdFALSE; 563 | 564 | // We loop around reading characters until there are none left in the UART. 565 | while( UART_RX_REG_NOT_EMPTY() ) 566 | { 567 | // Obtain the character from the UART. 568 | cRxedChar = UART_RX_REG; 569 | 570 | // Post the character onto a queue. xCRWokenByPost will be pdFALSE 571 | // the first time around the loop. If the post causes a co-routine 572 | // to be woken (unblocked) then xCRWokenByPost will be set to pdTRUE. 573 | // In this manner we can ensure that if more than one co-routine is 574 | // blocked on the queue only one is woken by this ISR no matter how 575 | // many characters are posted to the queue. 576 | xCRWokenByPost = crQUEUE_SEND_FROM_ISR( xCommsRxQueue, &cRxedChar, xCRWokenByPost ); 577 | } 578 | }579 | * \defgroup crQUEUE_SEND_FROM_ISR crQUEUE_SEND_FROM_ISR 580 | * \ingroup Tasks 581 | */ 582 | #define crQUEUE_SEND_FROM_ISR( pxQueue, pvItemToQueue, xCoRoutinePreviouslyWoken ) xQueueCRSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( xCoRoutinePreviouslyWoken ) ) 583 | 584 | 585 | /** 586 | * croutine. h 587 | *
588 | crQUEUE_SEND_FROM_ISR( 589 | QueueHandle_t pxQueue, 590 | void *pvBuffer, 591 | BaseType_t * pxCoRoutineWoken 592 | )593 | * 594 | * The macro's crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() are the 595 | * co-routine equivalent to the xQueueSendFromISR() and xQueueReceiveFromISR() 596 | * functions used by tasks. 597 | * 598 | * crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() can only be used to 599 | * pass data between a co-routine and and ISR, whereas xQueueSendFromISR() and 600 | * xQueueReceiveFromISR() can only be used to pass data between a task and and 601 | * ISR. 602 | * 603 | * crQUEUE_RECEIVE_FROM_ISR can only be called from an ISR to receive data 604 | * from a queue that is being used from within a co-routine (a co-routine 605 | * posted to the queue). 606 | * 607 | * See the co-routine section of the WEB documentation for information on 608 | * passing data between tasks and co-routines and between ISR's and 609 | * co-routines. 610 | * 611 | * @param xQueue The handle to the queue on which the item is to be posted. 612 | * 613 | * @param pvBuffer A pointer to a buffer into which the received item will be 614 | * placed. The size of the items the queue will hold was defined when the 615 | * queue was created, so this many bytes will be copied from the queue into 616 | * pvBuffer. 617 | * 618 | * @param pxCoRoutineWoken A co-routine may be blocked waiting for space to become 619 | * available on the queue. If crQUEUE_RECEIVE_FROM_ISR causes such a 620 | * co-routine to unblock *pxCoRoutineWoken will get set to pdTRUE, otherwise 621 | * *pxCoRoutineWoken will remain unchanged. 622 | * 623 | * @return pdTRUE an item was successfully received from the queue, otherwise 624 | * pdFALSE. 625 | * 626 | * Example usage: 627 |
628 | // A co-routine that posts a character to a queue then blocks for a fixed 629 | // period. The character is incremented each time. 630 | static void vSendingCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex ) 631 | { 632 | // cChar holds its value while this co-routine is blocked and must therefore 633 | // be declared static. 634 | static char cCharToTx = 'a'; 635 | BaseType_t xResult; 636 | 637 | // All co-routines must start with a call to crSTART(). 638 | crSTART( xHandle ); 639 | 640 | for( ;; ) 641 | { 642 | // Send the next character to the queue. 643 | crQUEUE_SEND( xHandle, xCoRoutineQueue, &cCharToTx, NO_DELAY, &xResult ); 644 | 645 | if( xResult == pdPASS ) 646 | { 647 | // The character was successfully posted to the queue. 648 | } 649 | else 650 | { 651 | // Could not post the character to the queue. 652 | } 653 | 654 | // Enable the UART Tx interrupt to cause an interrupt in this 655 | // hypothetical UART. The interrupt will obtain the character 656 | // from the queue and send it. 657 | ENABLE_RX_INTERRUPT(); 658 | 659 | // Increment to the next character then block for a fixed period. 660 | // cCharToTx will maintain its value across the delay as it is 661 | // declared static. 662 | cCharToTx++; 663 | if( cCharToTx > 'x' ) 664 | { 665 | cCharToTx = 'a'; 666 | } 667 | crDELAY( 100 ); 668 | } 669 | 670 | // All co-routines must end with a call to crEND(). 671 | crEND(); 672 | } 673 | 674 | // An ISR that uses a queue to receive characters to send on a UART. 675 | void vUART_ISR( void ) 676 | { 677 | char cCharToTx; 678 | BaseType_t xCRWokenByPost = pdFALSE; 679 | 680 | while( UART_TX_REG_EMPTY() ) 681 | { 682 | // Are there any characters in the queue waiting to be sent? 683 | // xCRWokenByPost will automatically be set to pdTRUE if a co-routine 684 | // is woken by the post - ensuring that only a single co-routine is 685 | // woken no matter how many times we go around this loop. 686 | if( crQUEUE_RECEIVE_FROM_ISR( pxQueue, &cCharToTx, &xCRWokenByPost ) ) 687 | { 688 | SEND_CHARACTER( cCharToTx ); 689 | } 690 | } 691 | }692 | * \defgroup crQUEUE_RECEIVE_FROM_ISR crQUEUE_RECEIVE_FROM_ISR 693 | * \ingroup Tasks 694 | */ 695 | #define crQUEUE_RECEIVE_FROM_ISR( pxQueue, pvBuffer, pxCoRoutineWoken ) xQueueCRReceiveFromISR( ( pxQueue ), ( pvBuffer ), ( pxCoRoutineWoken ) ) 696 | 697 | /* 698 | * This function is intended for internal use by the co-routine macros only. 699 | * The macro nature of the co-routine implementation requires that the 700 | * prototype appears here. The function should not be used by application 701 | * writers. 702 | * 703 | * Removes the current co-routine from its ready list and places it in the 704 | * appropriate delayed list. 705 | */ 706 | void vCoRoutineAddToDelayedList( TickType_t xTicksToDelay, List_t *pxEventList ); 707 | 708 | /* 709 | * This function is intended for internal use by the queue implementation only. 710 | * The function should not be used by application writers. 711 | * 712 | * Removes the highest priority co-routine from the event list and places it in 713 | * the pending ready list. 714 | */ 715 | BaseType_t xCoRoutineRemoveFromEventList( const List_t *pxEventList ); 716 | 717 | #ifdef __cplusplus 718 | } 719 | #endif 720 | 721 | #endif /* CO_ROUTINE_H */ 722 | -------------------------------------------------------------------------------- /Simulator_Linux/FreeRTOS_Kernel/include/deprecated_definitions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.0.0 3 | * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. If you wish to use our Amazon 14 | * FreeRTOS name, please do so in a fair use way that does not cause confusion. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | * http://www.FreeRTOS.org 24 | * http://aws.amazon.com/freertos 25 | * 26 | * 1 tab == 4 spaces! 27 | */ 28 | 29 | #ifndef DEPRECATED_DEFINITIONS_H 30 | #define DEPRECATED_DEFINITIONS_H 31 | 32 | 33 | /* Each FreeRTOS port has a unique portmacro.h header file. Originally a 34 | pre-processor definition was used to ensure the pre-processor found the correct 35 | portmacro.h file for the port being used. That scheme was deprecated in favour 36 | of setting the compiler's include path such that it found the correct 37 | portmacro.h file - removing the need for the constant and allowing the 38 | portmacro.h file to be located anywhere in relation to the port being used. The 39 | definitions below remain in the code for backward compatibility only. New 40 | projects should not use them. */ 41 | 42 | #ifdef OPEN_WATCOM_INDUSTRIAL_PC_PORT 43 | #include "..\..\Source\portable\owatcom\16bitdos\pc\portmacro.h" 44 | typedef void ( __interrupt __far *pxISR )(); 45 | #endif 46 | 47 | #ifdef OPEN_WATCOM_FLASH_LITE_186_PORT 48 | #include "..\..\Source\portable\owatcom\16bitdos\flsh186\portmacro.h" 49 | typedef void ( __interrupt __far *pxISR )(); 50 | #endif 51 | 52 | #ifdef GCC_MEGA_AVR 53 | #include "../portable/GCC/ATMega323/portmacro.h" 54 | #endif 55 | 56 | #ifdef IAR_MEGA_AVR 57 | #include "../portable/IAR/ATMega323/portmacro.h" 58 | #endif 59 | 60 | #ifdef MPLAB_PIC24_PORT 61 | #include "../../Source/portable/MPLAB/PIC24_dsPIC/portmacro.h" 62 | #endif 63 | 64 | #ifdef MPLAB_DSPIC_PORT 65 | #include "../../Source/portable/MPLAB/PIC24_dsPIC/portmacro.h" 66 | #endif 67 | 68 | #ifdef MPLAB_PIC18F_PORT 69 | #include "../../Source/portable/MPLAB/PIC18F/portmacro.h" 70 | #endif 71 | 72 | #ifdef MPLAB_PIC32MX_PORT 73 | #include "../../Source/portable/MPLAB/PIC32MX/portmacro.h" 74 | #endif 75 | 76 | #ifdef _FEDPICC 77 | #include "libFreeRTOS/Include/portmacro.h" 78 | #endif 79 | 80 | #ifdef SDCC_CYGNAL 81 | #include "../../Source/portable/SDCC/Cygnal/portmacro.h" 82 | #endif 83 | 84 | #ifdef GCC_ARM7 85 | #include "../../Source/portable/GCC/ARM7_LPC2000/portmacro.h" 86 | #endif 87 | 88 | #ifdef GCC_ARM7_ECLIPSE 89 | #include "portmacro.h" 90 | #endif 91 | 92 | #ifdef ROWLEY_LPC23xx 93 | #include "../../Source/portable/GCC/ARM7_LPC23xx/portmacro.h" 94 | #endif 95 | 96 | #ifdef IAR_MSP430 97 | #include "..\..\Source\portable\IAR\MSP430\portmacro.h" 98 | #endif 99 | 100 | #ifdef GCC_MSP430 101 | #include "../../Source/portable/GCC/MSP430F449/portmacro.h" 102 | #endif 103 | 104 | #ifdef ROWLEY_MSP430 105 | #include "../../Source/portable/Rowley/MSP430F449/portmacro.h" 106 | #endif 107 | 108 | #ifdef ARM7_LPC21xx_KEIL_RVDS 109 | #include "..\..\Source\portable\RVDS\ARM7_LPC21xx\portmacro.h" 110 | #endif 111 | 112 | #ifdef SAM7_GCC 113 | #include "../../Source/portable/GCC/ARM7_AT91SAM7S/portmacro.h" 114 | #endif 115 | 116 | #ifdef SAM7_IAR 117 | #include "..\..\Source\portable\IAR\AtmelSAM7S64\portmacro.h" 118 | #endif 119 | 120 | #ifdef SAM9XE_IAR 121 | #include "..\..\Source\portable\IAR\AtmelSAM9XE\portmacro.h" 122 | #endif 123 | 124 | #ifdef LPC2000_IAR 125 | #include "..\..\Source\portable\IAR\LPC2000\portmacro.h" 126 | #endif 127 | 128 | #ifdef STR71X_IAR 129 | #include "..\..\Source\portable\IAR\STR71x\portmacro.h" 130 | #endif 131 | 132 | #ifdef STR75X_IAR 133 | #include "..\..\Source\portable\IAR\STR75x\portmacro.h" 134 | #endif 135 | 136 | #ifdef STR75X_GCC 137 | #include "..\..\Source\portable\GCC\STR75x\portmacro.h" 138 | #endif 139 | 140 | #ifdef STR91X_IAR 141 | #include "..\..\Source\portable\IAR\STR91x\portmacro.h" 142 | #endif 143 | 144 | #ifdef GCC_H8S 145 | #include "../../Source/portable/GCC/H8S2329/portmacro.h" 146 | #endif 147 | 148 | #ifdef GCC_AT91FR40008 149 | #include "../../Source/portable/GCC/ARM7_AT91FR40008/portmacro.h" 150 | #endif 151 | 152 | #ifdef RVDS_ARMCM3_LM3S102 153 | #include "../../Source/portable/RVDS/ARM_CM3/portmacro.h" 154 | #endif 155 | 156 | #ifdef GCC_ARMCM3_LM3S102 157 | #include "../../Source/portable/GCC/ARM_CM3/portmacro.h" 158 | #endif 159 | 160 | #ifdef GCC_ARMCM3 161 | #include "../../Source/portable/GCC/ARM_CM3/portmacro.h" 162 | #endif 163 | 164 | #ifdef IAR_ARM_CM3 165 | #include "../../Source/portable/IAR/ARM_CM3/portmacro.h" 166 | #endif 167 | 168 | #ifdef IAR_ARMCM3_LM 169 | #include "../../Source/portable/IAR/ARM_CM3/portmacro.h" 170 | #endif 171 | 172 | #ifdef HCS12_CODE_WARRIOR 173 | #include "../../Source/portable/CodeWarrior/HCS12/portmacro.h" 174 | #endif 175 | 176 | #ifdef MICROBLAZE_GCC 177 | #include "../../Source/portable/GCC/MicroBlaze/portmacro.h" 178 | #endif 179 | 180 | #ifdef TERN_EE 181 | #include "..\..\Source\portable\Paradigm\Tern_EE\small\portmacro.h" 182 | #endif 183 | 184 | #ifdef GCC_HCS12 185 | #include "../../Source/portable/GCC/HCS12/portmacro.h" 186 | #endif 187 | 188 | #ifdef GCC_MCF5235 189 | #include "../../Source/portable/GCC/MCF5235/portmacro.h" 190 | #endif 191 | 192 | #ifdef COLDFIRE_V2_GCC 193 | #include "../../../Source/portable/GCC/ColdFire_V2/portmacro.h" 194 | #endif 195 | 196 | #ifdef COLDFIRE_V2_CODEWARRIOR 197 | #include "../../Source/portable/CodeWarrior/ColdFire_V2/portmacro.h" 198 | #endif 199 | 200 | #ifdef GCC_PPC405 201 | #include "../../Source/portable/GCC/PPC405_Xilinx/portmacro.h" 202 | #endif 203 | 204 | #ifdef GCC_PPC440 205 | #include "../../Source/portable/GCC/PPC440_Xilinx/portmacro.h" 206 | #endif 207 | 208 | #ifdef _16FX_SOFTUNE 209 | #include "..\..\Source\portable\Softune\MB96340\portmacro.h" 210 | #endif 211 | 212 | #ifdef BCC_INDUSTRIAL_PC_PORT 213 | /* A short file name has to be used in place of the normal 214 | FreeRTOSConfig.h when using the Borland compiler. */ 215 | #include "frconfig.h" 216 | #include "..\portable\BCC\16BitDOS\PC\prtmacro.h" 217 | typedef void ( __interrupt __far *pxISR )(); 218 | #endif 219 | 220 | #ifdef BCC_FLASH_LITE_186_PORT 221 | /* A short file name has to be used in place of the normal 222 | FreeRTOSConfig.h when using the Borland compiler. */ 223 | #include "frconfig.h" 224 | #include "..\portable\BCC\16BitDOS\flsh186\prtmacro.h" 225 | typedef void ( __interrupt __far *pxISR )(); 226 | #endif 227 | 228 | #ifdef __GNUC__ 229 | #ifdef __AVR32_AVR32A__ 230 | #include "portmacro.h" 231 | #endif 232 | #endif 233 | 234 | #ifdef __ICCAVR32__ 235 | #ifdef __CORE__ 236 | #if __CORE__ == __AVR32A__ 237 | #include "portmacro.h" 238 | #endif 239 | #endif 240 | #endif 241 | 242 | #ifdef __91467D 243 | #include "portmacro.h" 244 | #endif 245 | 246 | #ifdef __96340 247 | #include "portmacro.h" 248 | #endif 249 | 250 | 251 | #ifdef __IAR_V850ES_Fx3__ 252 | #include "../../Source/portable/IAR/V850ES/portmacro.h" 253 | #endif 254 | 255 | #ifdef __IAR_V850ES_Jx3__ 256 | #include "../../Source/portable/IAR/V850ES/portmacro.h" 257 | #endif 258 | 259 | #ifdef __IAR_V850ES_Jx3_L__ 260 | #include "../../Source/portable/IAR/V850ES/portmacro.h" 261 | #endif 262 | 263 | #ifdef __IAR_V850ES_Jx2__ 264 | #include "../../Source/portable/IAR/V850ES/portmacro.h" 265 | #endif 266 | 267 | #ifdef __IAR_V850ES_Hx2__ 268 | #include "../../Source/portable/IAR/V850ES/portmacro.h" 269 | #endif 270 | 271 | #ifdef __IAR_78K0R_Kx3__ 272 | #include "../../Source/portable/IAR/78K0R/portmacro.h" 273 | #endif 274 | 275 | #ifdef __IAR_78K0R_Kx3L__ 276 | #include "../../Source/portable/IAR/78K0R/portmacro.h" 277 | #endif 278 | 279 | #endif /* DEPRECATED_DEFINITIONS_H */ 280 | 281 | -------------------------------------------------------------------------------- /Simulator_Linux/FreeRTOS_Kernel/include/event_groups.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.0.0 3 | * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. If you wish to use our Amazon 14 | * FreeRTOS name, please do so in a fair use way that does not cause confusion. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | * http://www.FreeRTOS.org 24 | * http://aws.amazon.com/freertos 25 | * 26 | * 1 tab == 4 spaces! 27 | */ 28 | 29 | #ifndef EVENT_GROUPS_H 30 | #define EVENT_GROUPS_H 31 | 32 | #ifndef INC_FREERTOS_H 33 | #error "include FreeRTOS.h" must appear in source files before "include event_groups.h" 34 | #endif 35 | 36 | /* FreeRTOS includes. */ 37 | #include "timers.h" 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /** 44 | * An event group is a collection of bits to which an application can assign a 45 | * meaning. For example, an application may create an event group to convey 46 | * the status of various CAN bus related events in which bit 0 might mean "A CAN 47 | * message has been received and is ready for processing", bit 1 might mean "The 48 | * application has queued a message that is ready for sending onto the CAN 49 | * network", and bit 2 might mean "It is time to send a SYNC message onto the 50 | * CAN network" etc. A task can then test the bit values to see which events 51 | * are active, and optionally enter the Blocked state to wait for a specified 52 | * bit or a group of specified bits to be active. To continue the CAN bus 53 | * example, a CAN controlling task can enter the Blocked state (and therefore 54 | * not consume any processing time) until either bit 0, bit 1 or bit 2 are 55 | * active, at which time the bit that was actually active would inform the task 56 | * which action it had to take (process a received message, send a message, or 57 | * send a SYNC). 58 | * 59 | * The event groups implementation contains intelligence to avoid race 60 | * conditions that would otherwise occur were an application to use a simple 61 | * variable for the same purpose. This is particularly important with respect 62 | * to when a bit within an event group is to be cleared, and when bits have to 63 | * be set and then tested atomically - as is the case where event groups are 64 | * used to create a synchronisation point between multiple tasks (a 65 | * 'rendezvous'). 66 | * 67 | * \defgroup EventGroup 68 | */ 69 | 70 | 71 | 72 | /** 73 | * event_groups.h 74 | * 75 | * Type by which event groups are referenced. For example, a call to 76 | * xEventGroupCreate() returns an EventGroupHandle_t variable that can then 77 | * be used as a parameter to other event group functions. 78 | * 79 | * \defgroup EventGroupHandle_t EventGroupHandle_t 80 | * \ingroup EventGroup 81 | */ 82 | typedef void * EventGroupHandle_t; 83 | 84 | /* 85 | * The type that holds event bits always matches TickType_t - therefore the 86 | * number of bits it holds is set by configUSE_16_BIT_TICKS (16 bits if set to 1, 87 | * 32 bits if set to 0. 88 | * 89 | * \defgroup EventBits_t EventBits_t 90 | * \ingroup EventGroup 91 | */ 92 | typedef TickType_t EventBits_t; 93 | 94 | /** 95 | * event_groups.h 96 | *
97 | EventGroupHandle_t xEventGroupCreate( void ); 98 |99 | * 100 | * Create a new event group. 101 | * 102 | * Internally, within the FreeRTOS implementation, event groups use a [small] 103 | * block of memory, in which the event group's structure is stored. If an event 104 | * groups is created using xEventGropuCreate() then the required memory is 105 | * automatically dynamically allocated inside the xEventGroupCreate() function. 106 | * (see http://www.freertos.org/a00111.html). If an event group is created 107 | * using xEventGropuCreateStatic() then the application writer must instead 108 | * provide the memory that will get used by the event group. 109 | * xEventGroupCreateStatic() therefore allows an event group to be created 110 | * without using any dynamic memory allocation. 111 | * 112 | * Although event groups are not related to ticks, for internal implementation 113 | * reasons the number of bits available for use in an event group is dependent 114 | * on the configUSE_16_BIT_TICKS setting in FreeRTOSConfig.h. If 115 | * configUSE_16_BIT_TICKS is 1 then each event group contains 8 usable bits (bit 116 | * 0 to bit 7). If configUSE_16_BIT_TICKS is set to 0 then each event group has 117 | * 24 usable bits (bit 0 to bit 23). The EventBits_t type is used to store 118 | * event bits within an event group. 119 | * 120 | * @return If the event group was created then a handle to the event group is 121 | * returned. If there was insufficient FreeRTOS heap available to create the 122 | * event group then NULL is returned. See http://www.freertos.org/a00111.html 123 | * 124 | * Example usage: 125 |
126 | // Declare a variable to hold the created event group. 127 | EventGroupHandle_t xCreatedEventGroup; 128 | 129 | // Attempt to create the event group. 130 | xCreatedEventGroup = xEventGroupCreate(); 131 | 132 | // Was the event group created successfully? 133 | if( xCreatedEventGroup == NULL ) 134 | { 135 | // The event group was not created because there was insufficient 136 | // FreeRTOS heap available. 137 | } 138 | else 139 | { 140 | // The event group was created. 141 | } 142 |143 | * \defgroup xEventGroupCreate xEventGroupCreate 144 | * \ingroup EventGroup 145 | */ 146 | #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) 147 | EventGroupHandle_t xEventGroupCreate( void ) PRIVILEGED_FUNCTION; 148 | #endif 149 | 150 | /** 151 | * event_groups.h 152 | *
153 | EventGroupHandle_t xEventGroupCreateStatic( EventGroupHandle_t * pxEventGroupBuffer ); 154 |155 | * 156 | * Create a new event group. 157 | * 158 | * Internally, within the FreeRTOS implementation, event groups use a [small] 159 | * block of memory, in which the event group's structure is stored. If an event 160 | * groups is created using xEventGropuCreate() then the required memory is 161 | * automatically dynamically allocated inside the xEventGroupCreate() function. 162 | * (see http://www.freertos.org/a00111.html). If an event group is created 163 | * using xEventGropuCreateStatic() then the application writer must instead 164 | * provide the memory that will get used by the event group. 165 | * xEventGroupCreateStatic() therefore allows an event group to be created 166 | * without using any dynamic memory allocation. 167 | * 168 | * Although event groups are not related to ticks, for internal implementation 169 | * reasons the number of bits available for use in an event group is dependent 170 | * on the configUSE_16_BIT_TICKS setting in FreeRTOSConfig.h. If 171 | * configUSE_16_BIT_TICKS is 1 then each event group contains 8 usable bits (bit 172 | * 0 to bit 7). If configUSE_16_BIT_TICKS is set to 0 then each event group has 173 | * 24 usable bits (bit 0 to bit 23). The EventBits_t type is used to store 174 | * event bits within an event group. 175 | * 176 | * @param pxEventGroupBuffer pxEventGroupBuffer must point to a variable of type 177 | * StaticEventGroup_t, which will be then be used to hold the event group's data 178 | * structures, removing the need for the memory to be allocated dynamically. 179 | * 180 | * @return If the event group was created then a handle to the event group is 181 | * returned. If pxEventGroupBuffer was NULL then NULL is returned. 182 | * 183 | * Example usage: 184 |
185 | // StaticEventGroup_t is a publicly accessible structure that has the same 186 | // size and alignment requirements as the real event group structure. It is 187 | // provided as a mechanism for applications to know the size of the event 188 | // group (which is dependent on the architecture and configuration file 189 | // settings) without breaking the strict data hiding policy by exposing the 190 | // real event group internals. This StaticEventGroup_t variable is passed 191 | // into the xSemaphoreCreateEventGroupStatic() function and is used to store 192 | // the event group's data structures 193 | StaticEventGroup_t xEventGroupBuffer; 194 | 195 | // Create the event group without dynamically allocating any memory. 196 | xEventGroup = xEventGroupCreateStatic( &xEventGroupBuffer ); 197 |198 | */ 199 | #if( configSUPPORT_STATIC_ALLOCATION == 1 ) 200 | EventGroupHandle_t xEventGroupCreateStatic( StaticEventGroup_t *pxEventGroupBuffer ) PRIVILEGED_FUNCTION; 201 | #endif 202 | 203 | /** 204 | * event_groups.h 205 | *
206 | EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup, 207 | const EventBits_t uxBitsToWaitFor, 208 | const BaseType_t xClearOnExit, 209 | const BaseType_t xWaitForAllBits, 210 | const TickType_t xTicksToWait ); 211 |212 | * 213 | * [Potentially] block to wait for one or more bits to be set within a 214 | * previously created event group. 215 | * 216 | * This function cannot be called from an interrupt. 217 | * 218 | * @param xEventGroup The event group in which the bits are being tested. The 219 | * event group must have previously been created using a call to 220 | * xEventGroupCreate(). 221 | * 222 | * @param uxBitsToWaitFor A bitwise value that indicates the bit or bits to test 223 | * inside the event group. For example, to wait for bit 0 and/or bit 2 set 224 | * uxBitsToWaitFor to 0x05. To wait for bits 0 and/or bit 1 and/or bit 2 set 225 | * uxBitsToWaitFor to 0x07. Etc. 226 | * 227 | * @param xClearOnExit If xClearOnExit is set to pdTRUE then any bits within 228 | * uxBitsToWaitFor that are set within the event group will be cleared before 229 | * xEventGroupWaitBits() returns if the wait condition was met (if the function 230 | * returns for a reason other than a timeout). If xClearOnExit is set to 231 | * pdFALSE then the bits set in the event group are not altered when the call to 232 | * xEventGroupWaitBits() returns. 233 | * 234 | * @param xWaitForAllBits If xWaitForAllBits is set to pdTRUE then 235 | * xEventGroupWaitBits() will return when either all the bits in uxBitsToWaitFor 236 | * are set or the specified block time expires. If xWaitForAllBits is set to 237 | * pdFALSE then xEventGroupWaitBits() will return when any one of the bits set 238 | * in uxBitsToWaitFor is set or the specified block time expires. The block 239 | * time is specified by the xTicksToWait parameter. 240 | * 241 | * @param xTicksToWait The maximum amount of time (specified in 'ticks') to wait 242 | * for one/all (depending on the xWaitForAllBits value) of the bits specified by 243 | * uxBitsToWaitFor to become set. 244 | * 245 | * @return The value of the event group at the time either the bits being waited 246 | * for became set, or the block time expired. Test the return value to know 247 | * which bits were set. If xEventGroupWaitBits() returned because its timeout 248 | * expired then not all the bits being waited for will be set. If 249 | * xEventGroupWaitBits() returned because the bits it was waiting for were set 250 | * then the returned value is the event group value before any bits were 251 | * automatically cleared in the case that xClearOnExit parameter was set to 252 | * pdTRUE. 253 | * 254 | * Example usage: 255 |
256 | #define BIT_0 ( 1 << 0 ) 257 | #define BIT_4 ( 1 << 4 ) 258 | 259 | void aFunction( EventGroupHandle_t xEventGroup ) 260 | { 261 | EventBits_t uxBits; 262 | const TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS; 263 | 264 | // Wait a maximum of 100ms for either bit 0 or bit 4 to be set within 265 | // the event group. Clear the bits before exiting. 266 | uxBits = xEventGroupWaitBits( 267 | xEventGroup, // The event group being tested. 268 | BIT_0 | BIT_4, // The bits within the event group to wait for. 269 | pdTRUE, // BIT_0 and BIT_4 should be cleared before returning. 270 | pdFALSE, // Don't wait for both bits, either bit will do. 271 | xTicksToWait ); // Wait a maximum of 100ms for either bit to be set. 272 | 273 | if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) ) 274 | { 275 | // xEventGroupWaitBits() returned because both bits were set. 276 | } 277 | else if( ( uxBits & BIT_0 ) != 0 ) 278 | { 279 | // xEventGroupWaitBits() returned because just BIT_0 was set. 280 | } 281 | else if( ( uxBits & BIT_4 ) != 0 ) 282 | { 283 | // xEventGroupWaitBits() returned because just BIT_4 was set. 284 | } 285 | else 286 | { 287 | // xEventGroupWaitBits() returned because xTicksToWait ticks passed 288 | // without either BIT_0 or BIT_4 becoming set. 289 | } 290 | } 291 |292 | * \defgroup xEventGroupWaitBits xEventGroupWaitBits 293 | * \ingroup EventGroup 294 | */ 295 | EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; 296 | 297 | /** 298 | * event_groups.h 299 | *
300 | EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear ); 301 |302 | * 303 | * Clear bits within an event group. This function cannot be called from an 304 | * interrupt. 305 | * 306 | * @param xEventGroup The event group in which the bits are to be cleared. 307 | * 308 | * @param uxBitsToClear A bitwise value that indicates the bit or bits to clear 309 | * in the event group. For example, to clear bit 3 only, set uxBitsToClear to 310 | * 0x08. To clear bit 3 and bit 0 set uxBitsToClear to 0x09. 311 | * 312 | * @return The value of the event group before the specified bits were cleared. 313 | * 314 | * Example usage: 315 |
316 | #define BIT_0 ( 1 << 0 ) 317 | #define BIT_4 ( 1 << 4 ) 318 | 319 | void aFunction( EventGroupHandle_t xEventGroup ) 320 | { 321 | EventBits_t uxBits; 322 | 323 | // Clear bit 0 and bit 4 in xEventGroup. 324 | uxBits = xEventGroupClearBits( 325 | xEventGroup, // The event group being updated. 326 | BIT_0 | BIT_4 );// The bits being cleared. 327 | 328 | if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) ) 329 | { 330 | // Both bit 0 and bit 4 were set before xEventGroupClearBits() was 331 | // called. Both will now be clear (not set). 332 | } 333 | else if( ( uxBits & BIT_0 ) != 0 ) 334 | { 335 | // Bit 0 was set before xEventGroupClearBits() was called. It will 336 | // now be clear. 337 | } 338 | else if( ( uxBits & BIT_4 ) != 0 ) 339 | { 340 | // Bit 4 was set before xEventGroupClearBits() was called. It will 341 | // now be clear. 342 | } 343 | else 344 | { 345 | // Neither bit 0 nor bit 4 were set in the first place. 346 | } 347 | } 348 |349 | * \defgroup xEventGroupClearBits xEventGroupClearBits 350 | * \ingroup EventGroup 351 | */ 352 | EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear ) PRIVILEGED_FUNCTION; 353 | 354 | /** 355 | * event_groups.h 356 | *
357 | BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet ); 358 |359 | * 360 | * A version of xEventGroupClearBits() that can be called from an interrupt. 361 | * 362 | * Setting bits in an event group is not a deterministic operation because there 363 | * are an unknown number of tasks that may be waiting for the bit or bits being 364 | * set. FreeRTOS does not allow nondeterministic operations to be performed 365 | * while interrupts are disabled, so protects event groups that are accessed 366 | * from tasks by suspending the scheduler rather than disabling interrupts. As 367 | * a result event groups cannot be accessed directly from an interrupt service 368 | * routine. Therefore xEventGroupClearBitsFromISR() sends a message to the 369 | * timer task to have the clear operation performed in the context of the timer 370 | * task. 371 | * 372 | * @param xEventGroup The event group in which the bits are to be cleared. 373 | * 374 | * @param uxBitsToClear A bitwise value that indicates the bit or bits to clear. 375 | * For example, to clear bit 3 only, set uxBitsToClear to 0x08. To clear bit 3 376 | * and bit 0 set uxBitsToClear to 0x09. 377 | * 378 | * @return If the request to execute the function was posted successfully then 379 | * pdPASS is returned, otherwise pdFALSE is returned. pdFALSE will be returned 380 | * if the timer service queue was full. 381 | * 382 | * Example usage: 383 |
384 | #define BIT_0 ( 1 << 0 ) 385 | #define BIT_4 ( 1 << 4 ) 386 | 387 | // An event group which it is assumed has already been created by a call to 388 | // xEventGroupCreate(). 389 | EventGroupHandle_t xEventGroup; 390 | 391 | void anInterruptHandler( void ) 392 | { 393 | // Clear bit 0 and bit 4 in xEventGroup. 394 | xResult = xEventGroupClearBitsFromISR( 395 | xEventGroup, // The event group being updated. 396 | BIT_0 | BIT_4 ); // The bits being set. 397 | 398 | if( xResult == pdPASS ) 399 | { 400 | // The message was posted successfully. 401 | } 402 | } 403 |404 | * \defgroup xEventGroupClearBitsFromISR xEventGroupClearBitsFromISR 405 | * \ingroup EventGroup 406 | */ 407 | #if( configUSE_TRACE_FACILITY == 1 ) 408 | BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet ) PRIVILEGED_FUNCTION; 409 | #else 410 | #define xEventGroupClearBitsFromISR( xEventGroup, uxBitsToClear ) xTimerPendFunctionCallFromISR( vEventGroupClearBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToClear, NULL ) 411 | #endif 412 | 413 | /** 414 | * event_groups.h 415 | *
416 | EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet ); 417 |418 | * 419 | * Set bits within an event group. 420 | * This function cannot be called from an interrupt. xEventGroupSetBitsFromISR() 421 | * is a version that can be called from an interrupt. 422 | * 423 | * Setting bits in an event group will automatically unblock tasks that are 424 | * blocked waiting for the bits. 425 | * 426 | * @param xEventGroup The event group in which the bits are to be set. 427 | * 428 | * @param uxBitsToSet A bitwise value that indicates the bit or bits to set. 429 | * For example, to set bit 3 only, set uxBitsToSet to 0x08. To set bit 3 430 | * and bit 0 set uxBitsToSet to 0x09. 431 | * 432 | * @return The value of the event group at the time the call to 433 | * xEventGroupSetBits() returns. There are two reasons why the returned value 434 | * might have the bits specified by the uxBitsToSet parameter cleared. First, 435 | * if setting a bit results in a task that was waiting for the bit leaving the 436 | * blocked state then it is possible the bit will be cleared automatically 437 | * (see the xClearBitOnExit parameter of xEventGroupWaitBits()). Second, any 438 | * unblocked (or otherwise Ready state) task that has a priority above that of 439 | * the task that called xEventGroupSetBits() will execute and may change the 440 | * event group value before the call to xEventGroupSetBits() returns. 441 | * 442 | * Example usage: 443 |
444 | #define BIT_0 ( 1 << 0 ) 445 | #define BIT_4 ( 1 << 4 ) 446 | 447 | void aFunction( EventGroupHandle_t xEventGroup ) 448 | { 449 | EventBits_t uxBits; 450 | 451 | // Set bit 0 and bit 4 in xEventGroup. 452 | uxBits = xEventGroupSetBits( 453 | xEventGroup, // The event group being updated. 454 | BIT_0 | BIT_4 );// The bits being set. 455 | 456 | if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) ) 457 | { 458 | // Both bit 0 and bit 4 remained set when the function returned. 459 | } 460 | else if( ( uxBits & BIT_0 ) != 0 ) 461 | { 462 | // Bit 0 remained set when the function returned, but bit 4 was 463 | // cleared. It might be that bit 4 was cleared automatically as a 464 | // task that was waiting for bit 4 was removed from the Blocked 465 | // state. 466 | } 467 | else if( ( uxBits & BIT_4 ) != 0 ) 468 | { 469 | // Bit 4 remained set when the function returned, but bit 0 was 470 | // cleared. It might be that bit 0 was cleared automatically as a 471 | // task that was waiting for bit 0 was removed from the Blocked 472 | // state. 473 | } 474 | else 475 | { 476 | // Neither bit 0 nor bit 4 remained set. It might be that a task 477 | // was waiting for both of the bits to be set, and the bits were 478 | // cleared as the task left the Blocked state. 479 | } 480 | } 481 |482 | * \defgroup xEventGroupSetBits xEventGroupSetBits 483 | * \ingroup EventGroup 484 | */ 485 | EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet ) PRIVILEGED_FUNCTION; 486 | 487 | /** 488 | * event_groups.h 489 | *
490 | BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken ); 491 |492 | * 493 | * A version of xEventGroupSetBits() that can be called from an interrupt. 494 | * 495 | * Setting bits in an event group is not a deterministic operation because there 496 | * are an unknown number of tasks that may be waiting for the bit or bits being 497 | * set. FreeRTOS does not allow nondeterministic operations to be performed in 498 | * interrupts or from critical sections. Therefore xEventGroupSetBitsFromISR() 499 | * sends a message to the timer task to have the set operation performed in the 500 | * context of the timer task - where a scheduler lock is used in place of a 501 | * critical section. 502 | * 503 | * @param xEventGroup The event group in which the bits are to be set. 504 | * 505 | * @param uxBitsToSet A bitwise value that indicates the bit or bits to set. 506 | * For example, to set bit 3 only, set uxBitsToSet to 0x08. To set bit 3 507 | * and bit 0 set uxBitsToSet to 0x09. 508 | * 509 | * @param pxHigherPriorityTaskWoken As mentioned above, calling this function 510 | * will result in a message being sent to the timer daemon task. If the 511 | * priority of the timer daemon task is higher than the priority of the 512 | * currently running task (the task the interrupt interrupted) then 513 | * *pxHigherPriorityTaskWoken will be set to pdTRUE by 514 | * xEventGroupSetBitsFromISR(), indicating that a context switch should be 515 | * requested before the interrupt exits. For that reason 516 | * *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the 517 | * example code below. 518 | * 519 | * @return If the request to execute the function was posted successfully then 520 | * pdPASS is returned, otherwise pdFALSE is returned. pdFALSE will be returned 521 | * if the timer service queue was full. 522 | * 523 | * Example usage: 524 |
525 | #define BIT_0 ( 1 << 0 ) 526 | #define BIT_4 ( 1 << 4 ) 527 | 528 | // An event group which it is assumed has already been created by a call to 529 | // xEventGroupCreate(). 530 | EventGroupHandle_t xEventGroup; 531 | 532 | void anInterruptHandler( void ) 533 | { 534 | BaseType_t xHigherPriorityTaskWoken, xResult; 535 | 536 | // xHigherPriorityTaskWoken must be initialised to pdFALSE. 537 | xHigherPriorityTaskWoken = pdFALSE; 538 | 539 | // Set bit 0 and bit 4 in xEventGroup. 540 | xResult = xEventGroupSetBitsFromISR( 541 | xEventGroup, // The event group being updated. 542 | BIT_0 | BIT_4 // The bits being set. 543 | &xHigherPriorityTaskWoken ); 544 | 545 | // Was the message posted successfully? 546 | if( xResult == pdPASS ) 547 | { 548 | // If xHigherPriorityTaskWoken is now set to pdTRUE then a context 549 | // switch should be requested. The macro used is port specific and 550 | // will be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() - 551 | // refer to the documentation page for the port being used. 552 | portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); 553 | } 554 | } 555 |556 | * \defgroup xEventGroupSetBitsFromISR xEventGroupSetBitsFromISR 557 | * \ingroup EventGroup 558 | */ 559 | #if( configUSE_TRACE_FACILITY == 1 ) 560 | BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; 561 | #else 562 | #define xEventGroupSetBitsFromISR( xEventGroup, uxBitsToSet, pxHigherPriorityTaskWoken ) xTimerPendFunctionCallFromISR( vEventGroupSetBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToSet, pxHigherPriorityTaskWoken ) 563 | #endif 564 | 565 | /** 566 | * event_groups.h 567 | *
568 | EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup, 569 | const EventBits_t uxBitsToSet, 570 | const EventBits_t uxBitsToWaitFor, 571 | TickType_t xTicksToWait ); 572 |573 | * 574 | * Atomically set bits within an event group, then wait for a combination of 575 | * bits to be set within the same event group. This functionality is typically 576 | * used to synchronise multiple tasks, where each task has to wait for the other 577 | * tasks to reach a synchronisation point before proceeding. 578 | * 579 | * This function cannot be used from an interrupt. 580 | * 581 | * The function will return before its block time expires if the bits specified 582 | * by the uxBitsToWait parameter are set, or become set within that time. In 583 | * this case all the bits specified by uxBitsToWait will be automatically 584 | * cleared before the function returns. 585 | * 586 | * @param xEventGroup The event group in which the bits are being tested. The 587 | * event group must have previously been created using a call to 588 | * xEventGroupCreate(). 589 | * 590 | * @param uxBitsToSet The bits to set in the event group before determining 591 | * if, and possibly waiting for, all the bits specified by the uxBitsToWait 592 | * parameter are set. 593 | * 594 | * @param uxBitsToWaitFor A bitwise value that indicates the bit or bits to test 595 | * inside the event group. For example, to wait for bit 0 and bit 2 set 596 | * uxBitsToWaitFor to 0x05. To wait for bits 0 and bit 1 and bit 2 set 597 | * uxBitsToWaitFor to 0x07. Etc. 598 | * 599 | * @param xTicksToWait The maximum amount of time (specified in 'ticks') to wait 600 | * for all of the bits specified by uxBitsToWaitFor to become set. 601 | * 602 | * @return The value of the event group at the time either the bits being waited 603 | * for became set, or the block time expired. Test the return value to know 604 | * which bits were set. If xEventGroupSync() returned because its timeout 605 | * expired then not all the bits being waited for will be set. If 606 | * xEventGroupSync() returned because all the bits it was waiting for were 607 | * set then the returned value is the event group value before any bits were 608 | * automatically cleared. 609 | * 610 | * Example usage: 611 |
612 | // Bits used by the three tasks. 613 | #define TASK_0_BIT ( 1 << 0 ) 614 | #define TASK_1_BIT ( 1 << 1 ) 615 | #define TASK_2_BIT ( 1 << 2 ) 616 | 617 | #define ALL_SYNC_BITS ( TASK_0_BIT | TASK_1_BIT | TASK_2_BIT ) 618 | 619 | // Use an event group to synchronise three tasks. It is assumed this event 620 | // group has already been created elsewhere. 621 | EventGroupHandle_t xEventBits; 622 | 623 | void vTask0( void *pvParameters ) 624 | { 625 | EventBits_t uxReturn; 626 | TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS; 627 | 628 | for( ;; ) 629 | { 630 | // Perform task functionality here. 631 | 632 | // Set bit 0 in the event flag to note this task has reached the 633 | // sync point. The other two tasks will set the other two bits defined 634 | // by ALL_SYNC_BITS. All three tasks have reached the synchronisation 635 | // point when all the ALL_SYNC_BITS are set. Wait a maximum of 100ms 636 | // for this to happen. 637 | uxReturn = xEventGroupSync( xEventBits, TASK_0_BIT, ALL_SYNC_BITS, xTicksToWait ); 638 | 639 | if( ( uxReturn & ALL_SYNC_BITS ) == ALL_SYNC_BITS ) 640 | { 641 | // All three tasks reached the synchronisation point before the call 642 | // to xEventGroupSync() timed out. 643 | } 644 | } 645 | } 646 | 647 | void vTask1( void *pvParameters ) 648 | { 649 | for( ;; ) 650 | { 651 | // Perform task functionality here. 652 | 653 | // Set bit 1 in the event flag to note this task has reached the 654 | // synchronisation point. The other two tasks will set the other two 655 | // bits defined by ALL_SYNC_BITS. All three tasks have reached the 656 | // synchronisation point when all the ALL_SYNC_BITS are set. Wait 657 | // indefinitely for this to happen. 658 | xEventGroupSync( xEventBits, TASK_1_BIT, ALL_SYNC_BITS, portMAX_DELAY ); 659 | 660 | // xEventGroupSync() was called with an indefinite block time, so 661 | // this task will only reach here if the syncrhonisation was made by all 662 | // three tasks, so there is no need to test the return value. 663 | } 664 | } 665 | 666 | void vTask2( void *pvParameters ) 667 | { 668 | for( ;; ) 669 | { 670 | // Perform task functionality here. 671 | 672 | // Set bit 2 in the event flag to note this task has reached the 673 | // synchronisation point. The other two tasks will set the other two 674 | // bits defined by ALL_SYNC_BITS. All three tasks have reached the 675 | // synchronisation point when all the ALL_SYNC_BITS are set. Wait 676 | // indefinitely for this to happen. 677 | xEventGroupSync( xEventBits, TASK_2_BIT, ALL_SYNC_BITS, portMAX_DELAY ); 678 | 679 | // xEventGroupSync() was called with an indefinite block time, so 680 | // this task will only reach here if the syncrhonisation was made by all 681 | // three tasks, so there is no need to test the return value. 682 | } 683 | } 684 | 685 |686 | * \defgroup xEventGroupSync xEventGroupSync 687 | * \ingroup EventGroup 688 | */ 689 | EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, const EventBits_t uxBitsToWaitFor, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; 690 | 691 | 692 | /** 693 | * event_groups.h 694 | *
695 | EventBits_t xEventGroupGetBits( EventGroupHandle_t xEventGroup ); 696 |697 | * 698 | * Returns the current value of the bits in an event group. This function 699 | * cannot be used from an interrupt. 700 | * 701 | * @param xEventGroup The event group being queried. 702 | * 703 | * @return The event group bits at the time xEventGroupGetBits() was called. 704 | * 705 | * \defgroup xEventGroupGetBits xEventGroupGetBits 706 | * \ingroup EventGroup 707 | */ 708 | #define xEventGroupGetBits( xEventGroup ) xEventGroupClearBits( xEventGroup, 0 ) 709 | 710 | /** 711 | * event_groups.h 712 | *
713 | EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup ); 714 |715 | * 716 | * A version of xEventGroupGetBits() that can be called from an ISR. 717 | * 718 | * @param xEventGroup The event group being queried. 719 | * 720 | * @return The event group bits at the time xEventGroupGetBitsFromISR() was called. 721 | * 722 | * \defgroup xEventGroupGetBitsFromISR xEventGroupGetBitsFromISR 723 | * \ingroup EventGroup 724 | */ 725 | EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup ) PRIVILEGED_FUNCTION; 726 | 727 | /** 728 | * event_groups.h 729 | *
730 | void xEventGroupDelete( EventGroupHandle_t xEventGroup ); 731 |732 | * 733 | * Delete an event group that was previously created by a call to 734 | * xEventGroupCreate(). Tasks that are blocked on the event group will be 735 | * unblocked and obtain 0 as the event group's value. 736 | * 737 | * @param xEventGroup The event group being deleted. 738 | */ 739 | void vEventGroupDelete( EventGroupHandle_t xEventGroup ) PRIVILEGED_FUNCTION; 740 | 741 | /* For internal use only. */ 742 | void vEventGroupSetBitsCallback( void *pvEventGroup, const uint32_t ulBitsToSet ) PRIVILEGED_FUNCTION; 743 | void vEventGroupClearBitsCallback( void *pvEventGroup, const uint32_t ulBitsToClear ) PRIVILEGED_FUNCTION; 744 | 745 | 746 | #if (configUSE_TRACE_FACILITY == 1) 747 | UBaseType_t uxEventGroupGetNumber( void* xEventGroup ) PRIVILEGED_FUNCTION; 748 | void vEventGroupSetNumber( void* xEventGroup, UBaseType_t uxEventGroupNumber ) PRIVILEGED_FUNCTION; 749 | #endif 750 | 751 | #ifdef __cplusplus 752 | } 753 | #endif 754 | 755 | #endif /* EVENT_GROUPS_H */ 756 | 757 | 758 | -------------------------------------------------------------------------------- /Simulator_Linux/FreeRTOS_Kernel/include/list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.0.0 3 | * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. If you wish to use our Amazon 14 | * FreeRTOS name, please do so in a fair use way that does not cause confusion. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | * http://www.FreeRTOS.org 24 | * http://aws.amazon.com/freertos 25 | * 26 | * 1 tab == 4 spaces! 27 | */ 28 | 29 | /* 30 | * This is the list implementation used by the scheduler. While it is tailored 31 | * heavily for the schedulers needs, it is also available for use by 32 | * application code. 33 | * 34 | * list_ts can only store pointers to list_item_ts. Each ListItem_t contains a 35 | * numeric value (xItemValue). Most of the time the lists are sorted in 36 | * descending item value order. 37 | * 38 | * Lists are created already containing one list item. The value of this 39 | * item is the maximum possible that can be stored, it is therefore always at 40 | * the end of the list and acts as a marker. The list member pxHead always 41 | * points to this marker - even though it is at the tail of the list. This 42 | * is because the tail contains a wrap back pointer to the true head of 43 | * the list. 44 | * 45 | * In addition to it's value, each list item contains a pointer to the next 46 | * item in the list (pxNext), a pointer to the list it is in (pxContainer) 47 | * and a pointer to back to the object that contains it. These later two 48 | * pointers are included for efficiency of list manipulation. There is 49 | * effectively a two way link between the object containing the list item and 50 | * the list item itself. 51 | * 52 | * 53 | * \page ListIntroduction List Implementation 54 | * \ingroup FreeRTOSIntro 55 | */ 56 | 57 | #ifndef INC_FREERTOS_H 58 | #error FreeRTOS.h must be included before list.h 59 | #endif 60 | 61 | #ifndef LIST_H 62 | #define LIST_H 63 | 64 | /* 65 | * The list structure members are modified from within interrupts, and therefore 66 | * by rights should be declared volatile. However, they are only modified in a 67 | * functionally atomic way (within critical sections of with the scheduler 68 | * suspended) and are either passed by reference into a function or indexed via 69 | * a volatile variable. Therefore, in all use cases tested so far, the volatile 70 | * qualifier can be omitted in order to provide a moderate performance 71 | * improvement without adversely affecting functional behaviour. The assembly 72 | * instructions generated by the IAR, ARM and GCC compilers when the respective 73 | * compiler's options were set for maximum optimisation has been inspected and 74 | * deemed to be as intended. That said, as compiler technology advances, and 75 | * especially if aggressive cross module optimisation is used (a use case that 76 | * has not been exercised to any great extend) then it is feasible that the 77 | * volatile qualifier will be needed for correct optimisation. It is expected 78 | * that a compiler removing essential code because, without the volatile 79 | * qualifier on the list structure members and with aggressive cross module 80 | * optimisation, the compiler deemed the code unnecessary will result in 81 | * complete and obvious failure of the scheduler. If this is ever experienced 82 | * then the volatile qualifier can be inserted in the relevant places within the 83 | * list structures by simply defining configLIST_VOLATILE to volatile in 84 | * FreeRTOSConfig.h (as per the example at the bottom of this comment block). 85 | * If configLIST_VOLATILE is not defined then the preprocessor directives below 86 | * will simply #define configLIST_VOLATILE away completely. 87 | * 88 | * To use volatile list structure members then add the following line to 89 | * FreeRTOSConfig.h (without the quotes): 90 | * "#define configLIST_VOLATILE volatile" 91 | */ 92 | #ifndef configLIST_VOLATILE 93 | #define configLIST_VOLATILE 94 | #endif /* configSUPPORT_CROSS_MODULE_OPTIMISATION */ 95 | 96 | #ifdef __cplusplus 97 | extern "C" { 98 | #endif 99 | 100 | /* Macros that can be used to place known values within the list structures, 101 | then check that the known values do not get corrupted during the execution of 102 | the application. These may catch the list data structures being overwritten in 103 | memory. They will not catch data errors caused by incorrect configuration or 104 | use of FreeRTOS.*/ 105 | #if( configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES == 0 ) 106 | /* Define the macros to do nothing. */ 107 | #define listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE 108 | #define listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE 109 | #define listFIRST_LIST_INTEGRITY_CHECK_VALUE 110 | #define listSECOND_LIST_INTEGRITY_CHECK_VALUE 111 | #define listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ) 112 | #define listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ) 113 | #define listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList ) 114 | #define listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList ) 115 | #define listTEST_LIST_ITEM_INTEGRITY( pxItem ) 116 | #define listTEST_LIST_INTEGRITY( pxList ) 117 | #else 118 | /* Define macros that add new members into the list structures. */ 119 | #define listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE TickType_t xListItemIntegrityValue1; 120 | #define listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE TickType_t xListItemIntegrityValue2; 121 | #define listFIRST_LIST_INTEGRITY_CHECK_VALUE TickType_t xListIntegrityValue1; 122 | #define listSECOND_LIST_INTEGRITY_CHECK_VALUE TickType_t xListIntegrityValue2; 123 | 124 | /* Define macros that set the new structure members to known values. */ 125 | #define listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ) ( pxItem )->xListItemIntegrityValue1 = pdINTEGRITY_CHECK_VALUE 126 | #define listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ) ( pxItem )->xListItemIntegrityValue2 = pdINTEGRITY_CHECK_VALUE 127 | #define listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList ) ( pxList )->xListIntegrityValue1 = pdINTEGRITY_CHECK_VALUE 128 | #define listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList ) ( pxList )->xListIntegrityValue2 = pdINTEGRITY_CHECK_VALUE 129 | 130 | /* Define macros that will assert if one of the structure members does not 131 | contain its expected value. */ 132 | #define listTEST_LIST_ITEM_INTEGRITY( pxItem ) configASSERT( ( ( pxItem )->xListItemIntegrityValue1 == pdINTEGRITY_CHECK_VALUE ) && ( ( pxItem )->xListItemIntegrityValue2 == pdINTEGRITY_CHECK_VALUE ) ) 133 | #define listTEST_LIST_INTEGRITY( pxList ) configASSERT( ( ( pxList )->xListIntegrityValue1 == pdINTEGRITY_CHECK_VALUE ) && ( ( pxList )->xListIntegrityValue2 == pdINTEGRITY_CHECK_VALUE ) ) 134 | #endif /* configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES */ 135 | 136 | 137 | /* 138 | * Definition of the only type of object that a list can contain. 139 | */ 140 | struct xLIST_ITEM 141 | { 142 | listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ 143 | configLIST_VOLATILE TickType_t xItemValue; /*< The value being listed. In most cases this is used to sort the list in descending order. */ 144 | struct xLIST_ITEM * configLIST_VOLATILE pxNext; /*< Pointer to the next ListItem_t in the list. */ 145 | struct xLIST_ITEM * configLIST_VOLATILE pxPrevious; /*< Pointer to the previous ListItem_t in the list. */ 146 | 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. */ 147 | void * configLIST_VOLATILE pvContainer; /*< Pointer to the list in which this list item is placed (if any). */ 148 | listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ 149 | }; 150 | typedef struct xLIST_ITEM ListItem_t; /* For some reason lint wants this as two separate definitions. */ 151 | 152 | struct xMINI_LIST_ITEM 153 | { 154 | listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ 155 | configLIST_VOLATILE TickType_t xItemValue; 156 | struct xLIST_ITEM * configLIST_VOLATILE pxNext; 157 | struct xLIST_ITEM * configLIST_VOLATILE pxPrevious; 158 | }; 159 | typedef struct xMINI_LIST_ITEM MiniListItem_t; 160 | 161 | /* 162 | * Definition of the type of queue used by the scheduler. 163 | */ 164 | typedef struct xLIST 165 | { 166 | listFIRST_LIST_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ 167 | volatile UBaseType_t uxNumberOfItems; 168 | 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 (). */ 169 | 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. */ 170 | listSECOND_LIST_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ 171 | } List_t; 172 | 173 | /* 174 | * Access macro to set the owner of a list item. The owner of a list item 175 | * is the object (usually a TCB) that contains the list item. 176 | * 177 | * \page listSET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER 178 | * \ingroup LinkedList 179 | */ 180 | #define listSET_LIST_ITEM_OWNER( pxListItem, pxOwner ) ( ( pxListItem )->pvOwner = ( void * ) ( pxOwner ) ) 181 | 182 | /* 183 | * Access macro to get the owner of a list item. The owner of a list item 184 | * is the object (usually a TCB) that contains the list item. 185 | * 186 | * \page listSET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER 187 | * \ingroup LinkedList 188 | */ 189 | #define listGET_LIST_ITEM_OWNER( pxListItem ) ( ( pxListItem )->pvOwner ) 190 | 191 | /* 192 | * Access macro to set the value of the list item. In most cases the value is 193 | * used to sort the list in descending order. 194 | * 195 | * \page listSET_LIST_ITEM_VALUE listSET_LIST_ITEM_VALUE 196 | * \ingroup LinkedList 197 | */ 198 | #define listSET_LIST_ITEM_VALUE( pxListItem, xValue ) ( ( pxListItem )->xItemValue = ( xValue ) ) 199 | 200 | /* 201 | * Access macro to retrieve the value of the list item. The value can 202 | * represent anything - for example the priority of a task, or the time at 203 | * which a task should be unblocked. 204 | * 205 | * \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE 206 | * \ingroup LinkedList 207 | */ 208 | #define listGET_LIST_ITEM_VALUE( pxListItem ) ( ( pxListItem )->xItemValue ) 209 | 210 | /* 211 | * Access macro to retrieve the value of the list item at the head of a given 212 | * list. 213 | * 214 | * \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE 215 | * \ingroup LinkedList 216 | */ 217 | #define listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxList ) ( ( ( pxList )->xListEnd ).pxNext->xItemValue ) 218 | 219 | /* 220 | * Return the list item at the head of the list. 221 | * 222 | * \page listGET_HEAD_ENTRY listGET_HEAD_ENTRY 223 | * \ingroup LinkedList 224 | */ 225 | #define listGET_HEAD_ENTRY( pxList ) ( ( ( pxList )->xListEnd ).pxNext ) 226 | 227 | /* 228 | * Return the list item at the head of the list. 229 | * 230 | * \page listGET_NEXT listGET_NEXT 231 | * \ingroup LinkedList 232 | */ 233 | #define listGET_NEXT( pxListItem ) ( ( pxListItem )->pxNext ) 234 | 235 | /* 236 | * Return the list item that marks the end of the list 237 | * 238 | * \page listGET_END_MARKER listGET_END_MARKER 239 | * \ingroup LinkedList 240 | */ 241 | #define listGET_END_MARKER( pxList ) ( ( ListItem_t const * ) ( &( ( pxList )->xListEnd ) ) ) 242 | 243 | /* 244 | * Access macro to determine if a list contains any items. The macro will 245 | * only have the value true if the list is empty. 246 | * 247 | * \page listLIST_IS_EMPTY listLIST_IS_EMPTY 248 | * \ingroup LinkedList 249 | */ 250 | #define listLIST_IS_EMPTY( pxList ) ( ( BaseType_t ) ( ( pxList )->uxNumberOfItems == ( UBaseType_t ) 0 ) ) 251 | 252 | /* 253 | * Access macro to return the number of items in the list. 254 | */ 255 | #define listCURRENT_LIST_LENGTH( pxList ) ( ( pxList )->uxNumberOfItems ) 256 | 257 | /* 258 | * Access function to obtain the owner of the next entry in a list. 259 | * 260 | * The list member pxIndex is used to walk through a list. Calling 261 | * listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list 262 | * and returns that entry's pxOwner parameter. Using multiple calls to this 263 | * function it is therefore possible to move through every item contained in 264 | * a list. 265 | * 266 | * The pxOwner parameter of a list item is a pointer to the object that owns 267 | * the list item. In the scheduler this is normally a task control block. 268 | * The pxOwner parameter effectively creates a two way link between the list 269 | * item and its owner. 270 | * 271 | * @param pxTCB pxTCB is set to the address of the owner of the next list item. 272 | * @param pxList The list from which the next item owner is to be returned. 273 | * 274 | * \page listGET_OWNER_OF_NEXT_ENTRY listGET_OWNER_OF_NEXT_ENTRY 275 | * \ingroup LinkedList 276 | */ 277 | #define listGET_OWNER_OF_NEXT_ENTRY( pxTCB, pxList ) \ 278 | { \ 279 | List_t * const pxConstList = ( pxList ); \ 280 | /* Increment the index to the next item and return the item, ensuring */ \ 281 | /* we don't return the marker used at the end of the list. */ \ 282 | ( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext; \ 283 | if( ( void * ) ( pxConstList )->pxIndex == ( void * ) &( ( pxConstList )->xListEnd ) ) \ 284 | { \ 285 | ( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext; \ 286 | } \ 287 | ( pxTCB ) = ( pxConstList )->pxIndex->pvOwner; \ 288 | } 289 | 290 | 291 | /* 292 | * Access function to obtain the owner of the first entry in a list. Lists 293 | * are normally sorted in ascending item value order. 294 | * 295 | * This function returns the pxOwner member of the first item in the list. 296 | * The pxOwner parameter of a list item is a pointer to the object that owns 297 | * the list item. In the scheduler this is normally a task control block. 298 | * The pxOwner parameter effectively creates a two way link between the list 299 | * item and its owner. 300 | * 301 | * @param pxList The list from which the owner of the head item is to be 302 | * returned. 303 | * 304 | * \page listGET_OWNER_OF_HEAD_ENTRY listGET_OWNER_OF_HEAD_ENTRY 305 | * \ingroup LinkedList 306 | */ 307 | #define listGET_OWNER_OF_HEAD_ENTRY( pxList ) ( (&( ( pxList )->xListEnd ))->pxNext->pvOwner ) 308 | 309 | /* 310 | * Check to see if a list item is within a list. The list item maintains a 311 | * "container" pointer that points to the list it is in. All this macro does 312 | * is check to see if the container and the list match. 313 | * 314 | * @param pxList The list we want to know if the list item is within. 315 | * @param pxListItem The list item we want to know if is in the list. 316 | * @return pdTRUE if the list item is in the list, otherwise pdFALSE. 317 | */ 318 | #define listIS_CONTAINED_WITHIN( pxList, pxListItem ) ( ( BaseType_t ) ( ( pxListItem )->pvContainer == ( void * ) ( pxList ) ) ) 319 | 320 | /* 321 | * Return the list a list item is contained within (referenced from). 322 | * 323 | * @param pxListItem The list item being queried. 324 | * @return A pointer to the List_t object that references the pxListItem 325 | */ 326 | #define listLIST_ITEM_CONTAINER( pxListItem ) ( ( pxListItem )->pvContainer ) 327 | 328 | /* 329 | * This provides a crude means of knowing if a list has been initialised, as 330 | * pxList->xListEnd.xItemValue is set to portMAX_DELAY by the vListInitialise() 331 | * function. 332 | */ 333 | #define listLIST_IS_INITIALISED( pxList ) ( ( pxList )->xListEnd.xItemValue == portMAX_DELAY ) 334 | 335 | /* 336 | * Must be called before a list is used! This initialises all the members 337 | * of the list structure and inserts the xListEnd item into the list as a 338 | * marker to the back of the list. 339 | * 340 | * @param pxList Pointer to the list being initialised. 341 | * 342 | * \page vListInitialise vListInitialise 343 | * \ingroup LinkedList 344 | */ 345 | void vListInitialise( List_t * const pxList ) PRIVILEGED_FUNCTION; 346 | 347 | /* 348 | * Must be called before a list item is used. This sets the list container to 349 | * null so the item does not think that it is already contained in a list. 350 | * 351 | * @param pxItem Pointer to the list item being initialised. 352 | * 353 | * \page vListInitialiseItem vListInitialiseItem 354 | * \ingroup LinkedList 355 | */ 356 | void vListInitialiseItem( ListItem_t * const pxItem ) PRIVILEGED_FUNCTION; 357 | 358 | /* 359 | * Insert a list item into a list. The item will be inserted into the list in 360 | * a position determined by its item value (descending item value order). 361 | * 362 | * @param pxList The list into which the item is to be inserted. 363 | * 364 | * @param pxNewListItem The item that is to be placed in the list. 365 | * 366 | * \page vListInsert vListInsert 367 | * \ingroup LinkedList 368 | */ 369 | void vListInsert( List_t * const pxList, ListItem_t * const pxNewListItem ) PRIVILEGED_FUNCTION; 370 | 371 | /* 372 | * Insert a list item into a list. The item will be inserted in a position 373 | * such that it will be the last item within the list returned by multiple 374 | * calls to listGET_OWNER_OF_NEXT_ENTRY. 375 | * 376 | * The list member pxIndex is used to walk through a list. Calling 377 | * listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list. 378 | * Placing an item in a list using vListInsertEnd effectively places the item 379 | * in the list position pointed to by pxIndex. This means that every other 380 | * item within the list will be returned by listGET_OWNER_OF_NEXT_ENTRY before 381 | * the pxIndex parameter again points to the item being inserted. 382 | * 383 | * @param pxList The list into which the item is to be inserted. 384 | * 385 | * @param pxNewListItem The list item to be inserted into the list. 386 | * 387 | * \page vListInsertEnd vListInsertEnd 388 | * \ingroup LinkedList 389 | */ 390 | void vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem ) PRIVILEGED_FUNCTION; 391 | 392 | /* 393 | * Remove an item from a list. The list item has a pointer to the list that 394 | * it is in, so only the list item need be passed into the function. 395 | * 396 | * @param uxListRemove The item to be removed. The item will remove itself from 397 | * the list pointed to by it's pxContainer parameter. 398 | * 399 | * @return The number of items that remain in the list after the list item has 400 | * been removed. 401 | * 402 | * \page uxListRemove uxListRemove 403 | * \ingroup LinkedList 404 | */ 405 | UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove ) PRIVILEGED_FUNCTION; 406 | 407 | #ifdef __cplusplus 408 | } 409 | #endif 410 | 411 | #endif 412 | 413 | -------------------------------------------------------------------------------- /Simulator_Linux/FreeRTOS_Kernel/include/mpu_prototypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.0.0 3 | * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. If you wish to use our Amazon 14 | * FreeRTOS name, please do so in a fair use way that does not cause confusion. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | * http://www.FreeRTOS.org 24 | * http://aws.amazon.com/freertos 25 | * 26 | * 1 tab == 4 spaces! 27 | */ 28 | 29 | /* 30 | * When the MPU is used the standard (non MPU) API functions are mapped to 31 | * equivalents that start "MPU_", the prototypes for which are defined in this 32 | * header files. This will cause the application code to call the MPU_ version 33 | * which wraps the non-MPU version with privilege promoting then demoting code, 34 | * so the kernel code always runs will full privileges. 35 | */ 36 | 37 | 38 | #ifndef MPU_PROTOTYPES_H 39 | #define MPU_PROTOTYPES_H 40 | 41 | /* MPU versions of tasks.h API functions. */ 42 | BaseType_t MPU_xTaskCreate( TaskFunction_t pxTaskCode, const char * const pcName, const uint16_t usStackDepth, void * const pvParameters, UBaseType_t uxPriority, TaskHandle_t * const pxCreatedTask ); 43 | TaskHandle_t MPU_xTaskCreateStatic( TaskFunction_t pxTaskCode, const char * const pcName, const uint32_t ulStackDepth, void * const pvParameters, UBaseType_t uxPriority, StackType_t * const puxStackBuffer, StaticTask_t * const pxTaskBuffer ); 44 | BaseType_t MPU_xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ); 45 | BaseType_t MPU_xTaskCreateRestrictedStatic( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ); 46 | void MPU_vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions ); 47 | void MPU_vTaskDelete( TaskHandle_t xTaskToDelete ); 48 | void MPU_vTaskDelay( const TickType_t xTicksToDelay ); 49 | void MPU_vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, const TickType_t xTimeIncrement ); 50 | BaseType_t MPU_xTaskAbortDelay( TaskHandle_t xTask ); 51 | UBaseType_t MPU_uxTaskPriorityGet( TaskHandle_t xTask ); 52 | eTaskState MPU_eTaskGetState( TaskHandle_t xTask ); 53 | void MPU_vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState ); 54 | void MPU_vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority ); 55 | void MPU_vTaskSuspend( TaskHandle_t xTaskToSuspend ); 56 | void MPU_vTaskResume( TaskHandle_t xTaskToResume ); 57 | void MPU_vTaskStartScheduler( void ); 58 | void MPU_vTaskSuspendAll( void ); 59 | BaseType_t MPU_xTaskResumeAll( void ); 60 | TickType_t MPU_xTaskGetTickCount( void ); 61 | UBaseType_t MPU_uxTaskGetNumberOfTasks( void ); 62 | char * MPU_pcTaskGetName( TaskHandle_t xTaskToQuery ); 63 | TaskHandle_t MPU_xTaskGetHandle( const char *pcNameToQuery ); 64 | UBaseType_t MPU_uxTaskGetStackHighWaterMark( TaskHandle_t xTask ); 65 | void MPU_vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction ); 66 | TaskHookFunction_t MPU_xTaskGetApplicationTaskTag( TaskHandle_t xTask ); 67 | void MPU_vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue ); 68 | void * MPU_pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, BaseType_t xIndex ); 69 | BaseType_t MPU_xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter ); 70 | TaskHandle_t MPU_xTaskGetIdleTaskHandle( void ); 71 | UBaseType_t MPU_uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime ); 72 | void MPU_vTaskList( char * pcWriteBuffer ); 73 | void MPU_vTaskGetRunTimeStats( char *pcWriteBuffer ); 74 | BaseType_t MPU_xTaskGenericNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue ); 75 | BaseType_t MPU_xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait ); 76 | uint32_t MPU_ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait ); 77 | BaseType_t MPU_xTaskNotifyStateClear( TaskHandle_t xTask ); 78 | BaseType_t MPU_xTaskIncrementTick( void ); 79 | TaskHandle_t MPU_xTaskGetCurrentTaskHandle( void ); 80 | void MPU_vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ); 81 | BaseType_t MPU_xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait ); 82 | void MPU_vTaskMissedYield( void ); 83 | BaseType_t MPU_xTaskGetSchedulerState( void ); 84 | 85 | /* MPU versions of queue.h API functions. */ 86 | BaseType_t MPU_xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, const BaseType_t xCopyPosition ); 87 | BaseType_t MPU_xQueueReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait ); 88 | BaseType_t xQueuePeek( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait ); 89 | BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue, TickType_t xTicksToWait ); 90 | UBaseType_t MPU_uxQueueMessagesWaiting( const QueueHandle_t xQueue ); 91 | UBaseType_t MPU_uxQueueSpacesAvailable( const QueueHandle_t xQueue ); 92 | void MPU_vQueueDelete( QueueHandle_t xQueue ); 93 | QueueHandle_t MPU_xQueueCreateMutex( const uint8_t ucQueueType ); 94 | QueueHandle_t MPU_xQueueCreateMutexStatic( const uint8_t ucQueueType, StaticQueue_t *pxStaticQueue ); 95 | QueueHandle_t MPU_xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount ); 96 | QueueHandle_t MPU_xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount, StaticQueue_t *pxStaticQueue ); 97 | void* MPU_xQueueGetMutexHolder( QueueHandle_t xSemaphore ); 98 | BaseType_t MPU_xQueueTakeMutexRecursive( QueueHandle_t xMutex, TickType_t xTicksToWait ); 99 | BaseType_t MPU_xQueueGiveMutexRecursive( QueueHandle_t pxMutex ); 100 | void MPU_vQueueAddToRegistry( QueueHandle_t xQueue, const char *pcName ); 101 | void MPU_vQueueUnregisterQueue( QueueHandle_t xQueue ); 102 | const char * MPU_pcQueueGetName( QueueHandle_t xQueue ); 103 | QueueHandle_t MPU_xQueueGenericCreate( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, const uint8_t ucQueueType ); 104 | QueueHandle_t MPU_xQueueGenericCreateStatic( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, uint8_t *pucQueueStorage, StaticQueue_t *pxStaticQueue, const uint8_t ucQueueType ); 105 | QueueSetHandle_t MPU_xQueueCreateSet( const UBaseType_t uxEventQueueLength ); 106 | BaseType_t MPU_xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ); 107 | BaseType_t MPU_xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ); 108 | QueueSetMemberHandle_t MPU_xQueueSelectFromSet( QueueSetHandle_t xQueueSet, const TickType_t xTicksToWait ); 109 | BaseType_t MPU_xQueueGenericReset( QueueHandle_t xQueue, BaseType_t xNewQueue ); 110 | void MPU_vQueueSetQueueNumber( QueueHandle_t xQueue, UBaseType_t uxQueueNumber ); 111 | UBaseType_t MPU_uxQueueGetQueueNumber( QueueHandle_t xQueue ); 112 | uint8_t MPU_ucQueueGetQueueType( QueueHandle_t xQueue ); 113 | 114 | /* MPU versions of timers.h API functions. */ 115 | TimerHandle_t MPU_xTimerCreate( const char * const pcTimerName, const TickType_t xTimerPeriodInTicks, const UBaseType_t uxAutoReload, void * const pvTimerID, TimerCallbackFunction_t pxCallbackFunction ); 116 | TimerHandle_t MPU_xTimerCreateStatic( const char * const pcTimerName, const TickType_t xTimerPeriodInTicks, const UBaseType_t uxAutoReload, void * const pvTimerID, TimerCallbackFunction_t pxCallbackFunction, StaticTimer_t *pxTimerBuffer ); 117 | void * MPU_pvTimerGetTimerID( const TimerHandle_t xTimer ); 118 | void MPU_vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID ); 119 | BaseType_t MPU_xTimerIsTimerActive( TimerHandle_t xTimer ); 120 | TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandle( void ); 121 | BaseType_t MPU_xTimerPendFunctionCall( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, TickType_t xTicksToWait ); 122 | const char * MPU_pcTimerGetName( TimerHandle_t xTimer ); 123 | TickType_t MPU_xTimerGetPeriod( TimerHandle_t xTimer ); 124 | TickType_t MPU_xTimerGetExpiryTime( TimerHandle_t xTimer ); 125 | BaseType_t MPU_xTimerCreateTimerTask( void ); 126 | BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t * const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait ); 127 | 128 | /* MPU versions of event_group.h API functions. */ 129 | EventGroupHandle_t MPU_xEventGroupCreate( void ); 130 | EventGroupHandle_t MPU_xEventGroupCreateStatic( StaticEventGroup_t *pxEventGroupBuffer ); 131 | EventBits_t MPU_xEventGroupWaitBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait ); 132 | EventBits_t MPU_xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear ); 133 | EventBits_t MPU_xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet ); 134 | EventBits_t MPU_xEventGroupSync( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, const EventBits_t uxBitsToWaitFor, TickType_t xTicksToWait ); 135 | void MPU_vEventGroupDelete( EventGroupHandle_t xEventGroup ); 136 | UBaseType_t MPU_uxEventGroupGetNumber( void* xEventGroup ); 137 | 138 | /* MPU versions of message/stream_buffer.h API functions. */ 139 | size_t MPU_xStreamBufferSend( StreamBufferHandle_t xStreamBuffer, const void *pvTxData, size_t xDataLengthBytes, TickType_t xTicksToWait ); 140 | size_t MPU_xStreamBufferSendFromISR( StreamBufferHandle_t xStreamBuffer, const void *pvTxData, size_t xDataLengthBytes, BaseType_t * const pxHigherPriorityTaskWoken ); 141 | size_t MPU_xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer, void *pvRxData, size_t xBufferLengthBytes, TickType_t xTicksToWait ); 142 | size_t MPU_xStreamBufferReceiveFromISR( StreamBufferHandle_t xStreamBuffer, void *pvRxData, size_t xBufferLengthBytes, BaseType_t * const pxHigherPriorityTaskWoken ); 143 | void MPU_vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer ); 144 | BaseType_t MPU_xStreamBufferIsFull( StreamBufferHandle_t xStreamBuffer ); 145 | BaseType_t MPU_xStreamBufferIsEmpty( StreamBufferHandle_t xStreamBuffer ); 146 | BaseType_t MPU_xStreamBufferReset( StreamBufferHandle_t xStreamBuffer ); 147 | size_t MPU_xStreamBufferSpacesAvailable( StreamBufferHandle_t xStreamBuffer ); 148 | size_t MPU_xStreamBufferBytesAvailable( StreamBufferHandle_t xStreamBuffer ); 149 | BaseType_t MPU_xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer, size_t xTriggerLevel ); 150 | StreamBufferHandle_t MPU_xStreamBufferGenericCreate( size_t xBufferSizeBytes, size_t xTriggerLevelBytes, BaseType_t xIsMessageBuffer ); 151 | StreamBufferHandle_t MPU_xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes, size_t xTriggerLevelBytes, BaseType_t xIsMessageBuffer, uint8_t * const pucStreamBufferStorageArea, StaticStreamBuffer_t * const pxStaticStreamBuffer ); 152 | 153 | 154 | 155 | #endif /* MPU_PROTOTYPES_H */ 156 | 157 | -------------------------------------------------------------------------------- /Simulator_Linux/FreeRTOS_Kernel/include/mpu_wrappers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.0.0 3 | * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. If you wish to use our Amazon 14 | * FreeRTOS name, please do so in a fair use way that does not cause confusion. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | * http://www.FreeRTOS.org 24 | * http://aws.amazon.com/freertos 25 | * 26 | * 1 tab == 4 spaces! 27 | */ 28 | 29 | #ifndef MPU_WRAPPERS_H 30 | #define MPU_WRAPPERS_H 31 | 32 | /* This file redefines API functions to be called through a wrapper macro, but 33 | only for ports that are using the MPU. */ 34 | #ifdef portUSING_MPU_WRAPPERS 35 | 36 | /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE will be defined when this file is 37 | included from queue.c or task.c to prevent it from having an effect within 38 | those files. */ 39 | #ifndef MPU_WRAPPERS_INCLUDED_FROM_API_FILE 40 | 41 | /* 42 | * Map standard (non MPU) API functions to equivalents that start 43 | * "MPU_". This will cause the application code to call the MPU_ 44 | * version, which wraps the non-MPU version with privilege promoting 45 | * then demoting code, so the kernel code always runs will full 46 | * privileges. 47 | */ 48 | 49 | /* Map standard tasks.h API functions to the MPU equivalents. */ 50 | #define xTaskCreate MPU_xTaskCreate 51 | #define xTaskCreateStatic MPU_xTaskCreateStatic 52 | #define xTaskCreateRestricted MPU_xTaskCreateRestricted 53 | #define vTaskAllocateMPURegions MPU_vTaskAllocateMPURegions 54 | #define vTaskDelete MPU_vTaskDelete 55 | #define vTaskDelay MPU_vTaskDelay 56 | #define vTaskDelayUntil MPU_vTaskDelayUntil 57 | #define xTaskAbortDelay MPU_xTaskAbortDelay 58 | #define uxTaskPriorityGet MPU_uxTaskPriorityGet 59 | #define eTaskGetState MPU_eTaskGetState 60 | #define vTaskGetInfo MPU_vTaskGetInfo 61 | #define vTaskPrioritySet MPU_vTaskPrioritySet 62 | #define vTaskSuspend MPU_vTaskSuspend 63 | #define vTaskResume MPU_vTaskResume 64 | #define vTaskSuspendAll MPU_vTaskSuspendAll 65 | #define xTaskResumeAll MPU_xTaskResumeAll 66 | #define xTaskGetTickCount MPU_xTaskGetTickCount 67 | #define uxTaskGetNumberOfTasks MPU_uxTaskGetNumberOfTasks 68 | #define pcTaskGetName MPU_pcTaskGetName 69 | #define xTaskGetHandle MPU_xTaskGetHandle 70 | #define uxTaskGetStackHighWaterMark MPU_uxTaskGetStackHighWaterMark 71 | #define vTaskSetApplicationTaskTag MPU_vTaskSetApplicationTaskTag 72 | #define xTaskGetApplicationTaskTag MPU_xTaskGetApplicationTaskTag 73 | #define vTaskSetThreadLocalStoragePointer MPU_vTaskSetThreadLocalStoragePointer 74 | #define pvTaskGetThreadLocalStoragePointer MPU_pvTaskGetThreadLocalStoragePointer 75 | #define xTaskCallApplicationTaskHook MPU_xTaskCallApplicationTaskHook 76 | #define xTaskGetIdleTaskHandle MPU_xTaskGetIdleTaskHandle 77 | #define uxTaskGetSystemState MPU_uxTaskGetSystemState 78 | #define vTaskList MPU_vTaskList 79 | #define vTaskGetRunTimeStats MPU_vTaskGetRunTimeStats 80 | #define xTaskGenericNotify MPU_xTaskGenericNotify 81 | #define xTaskNotifyWait MPU_xTaskNotifyWait 82 | #define ulTaskNotifyTake MPU_ulTaskNotifyTake 83 | #define xTaskNotifyStateClear MPU_xTaskNotifyStateClear 84 | 85 | #define xTaskGetCurrentTaskHandle MPU_xTaskGetCurrentTaskHandle 86 | #define vTaskSetTimeOutState MPU_vTaskSetTimeOutState 87 | #define xTaskCheckForTimeOut MPU_xTaskCheckForTimeOut 88 | #define xTaskGetSchedulerState MPU_xTaskGetSchedulerState 89 | 90 | /* Map standard queue.h API functions to the MPU equivalents. */ 91 | #define xQueueGenericSend MPU_xQueueGenericSend 92 | #define xQueueReceive MPU_xQueueReceive 93 | #define xQueuePeek MPU_xQueuePeek 94 | #define xQueueSemaphoreTake MPU_xQueueSemaphoreTake 95 | #define uxQueueMessagesWaiting MPU_uxQueueMessagesWaiting 96 | #define uxQueueSpacesAvailable MPU_uxQueueSpacesAvailable 97 | #define vQueueDelete MPU_vQueueDelete 98 | #define xQueueCreateMutex MPU_xQueueCreateMutex 99 | #define xQueueCreateMutexStatic MPU_xQueueCreateMutexStatic 100 | #define xQueueCreateCountingSemaphore MPU_xQueueCreateCountingSemaphore 101 | #define xQueueCreateCountingSemaphoreStatic MPU_xQueueCreateCountingSemaphoreStatic 102 | #define xQueueGetMutexHolder MPU_xQueueGetMutexHolder 103 | #define xQueueTakeMutexRecursive MPU_xQueueTakeMutexRecursive 104 | #define xQueueGiveMutexRecursive MPU_xQueueGiveMutexRecursive 105 | #define xQueueGenericCreate MPU_xQueueGenericCreate 106 | #define xQueueGenericCreateStatic MPU_xQueueGenericCreateStatic 107 | #define xQueueCreateSet MPU_xQueueCreateSet 108 | #define xQueueAddToSet MPU_xQueueAddToSet 109 | #define xQueueRemoveFromSet MPU_xQueueRemoveFromSet 110 | #define xQueueSelectFromSet MPU_xQueueSelectFromSet 111 | #define xQueueGenericReset MPU_xQueueGenericReset 112 | 113 | #if( configQUEUE_REGISTRY_SIZE > 0 ) 114 | #define vQueueAddToRegistry MPU_vQueueAddToRegistry 115 | #define vQueueUnregisterQueue MPU_vQueueUnregisterQueue 116 | #define pcQueueGetName MPU_pcQueueGetName 117 | #endif 118 | 119 | /* Map standard timer.h API functions to the MPU equivalents. */ 120 | #define xTimerCreate MPU_xTimerCreate 121 | #define xTimerCreateStatic MPU_xTimerCreateStatic 122 | #define pvTimerGetTimerID MPU_pvTimerGetTimerID 123 | #define vTimerSetTimerID MPU_vTimerSetTimerID 124 | #define xTimerIsTimerActive MPU_xTimerIsTimerActive 125 | #define xTimerGetTimerDaemonTaskHandle MPU_xTimerGetTimerDaemonTaskHandle 126 | #define xTimerPendFunctionCall MPU_xTimerPendFunctionCall 127 | #define pcTimerGetName MPU_pcTimerGetName 128 | #define xTimerGetPeriod MPU_xTimerGetPeriod 129 | #define xTimerGetExpiryTime MPU_xTimerGetExpiryTime 130 | #define xTimerGenericCommand MPU_xTimerGenericCommand 131 | 132 | /* Map standard event_group.h API functions to the MPU equivalents. */ 133 | #define xEventGroupCreate MPU_xEventGroupCreate 134 | #define xEventGroupCreateStatic MPU_xEventGroupCreateStatic 135 | #define xEventGroupWaitBits MPU_xEventGroupWaitBits 136 | #define xEventGroupClearBits MPU_xEventGroupClearBits 137 | #define xEventGroupSetBits MPU_xEventGroupSetBits 138 | #define xEventGroupSync MPU_xEventGroupSync 139 | #define vEventGroupDelete MPU_vEventGroupDelete 140 | 141 | /* Map standard message/stream_buffer.h API functions to the MPU 142 | equivalents. */ 143 | #define xStreamBufferSend MPU_xStreamBufferSend 144 | #define xStreamBufferSendFromISR MPU_xStreamBufferSendFromISR 145 | #define xStreamBufferReceive MPU_xStreamBufferReceive 146 | #define xStreamBufferReceiveFromISR MPU_xStreamBufferReceiveFromISR 147 | #define vStreamBufferDelete MPU_vStreamBufferDelete 148 | #define xStreamBufferIsFull MPU_xStreamBufferIsFull 149 | #define xStreamBufferIsEmpty MPU_xStreamBufferIsEmpty 150 | #define xStreamBufferReset MPU_xStreamBufferReset 151 | #define xStreamBufferSpacesAvailable MPU_xStreamBufferSpacesAvailable 152 | #define xStreamBufferBytesAvailable MPU_xStreamBufferBytesAvailable 153 | #define xStreamBufferSetTriggerLevel MPU_xStreamBufferSetTriggerLevel 154 | #define xStreamBufferGenericCreate MPU_xStreamBufferGenericCreate 155 | #define xStreamBufferGenericCreateStatic MPU_xStreamBufferGenericCreateStatic 156 | 157 | 158 | /* Remove the privileged function macro, but keep the PRIVILEGED_DATA 159 | macro so applications can place data in privileged access sections 160 | (useful when using statically allocated objects). */ 161 | #define PRIVILEGED_FUNCTION 162 | #define PRIVILEGED_DATA __attribute__((section("privileged_data"))) 163 | 164 | #else /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */ 165 | 166 | /* Ensure API functions go in the privileged execution section. */ 167 | #define PRIVILEGED_FUNCTION __attribute__((section("privileged_functions"))) 168 | #define PRIVILEGED_DATA __attribute__((section("privileged_data"))) 169 | 170 | #endif /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */ 171 | 172 | #else /* portUSING_MPU_WRAPPERS */ 173 | 174 | #define PRIVILEGED_FUNCTION 175 | #define PRIVILEGED_DATA 176 | #define portUSING_MPU_WRAPPERS 0 177 | 178 | #endif /* portUSING_MPU_WRAPPERS */ 179 | 180 | 181 | #endif /* MPU_WRAPPERS_H */ 182 | 183 | -------------------------------------------------------------------------------- /Simulator_Linux/FreeRTOS_Kernel/include/portable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.0.0 3 | * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. If you wish to use our Amazon 14 | * FreeRTOS name, please do so in a fair use way that does not cause confusion. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | * http://www.FreeRTOS.org 24 | * http://aws.amazon.com/freertos 25 | * 26 | * 1 tab == 4 spaces! 27 | */ 28 | 29 | /*----------------------------------------------------------- 30 | * Portable layer API. Each function must be defined for each port. 31 | *----------------------------------------------------------*/ 32 | 33 | #ifndef PORTABLE_H 34 | #define PORTABLE_H 35 | 36 | /* Each FreeRTOS port has a unique portmacro.h header file. Originally a 37 | pre-processor definition was used to ensure the pre-processor found the correct 38 | portmacro.h file for the port being used. That scheme was deprecated in favour 39 | of setting the compiler's include path such that it found the correct 40 | portmacro.h file - removing the need for the constant and allowing the 41 | portmacro.h file to be located anywhere in relation to the port being used. 42 | Purely for reasons of backward compatibility the old method is still valid, but 43 | to make it clear that new projects should not use it, support for the port 44 | specific constants has been moved into the deprecated_definitions.h header 45 | file. */ 46 | #include "deprecated_definitions.h" 47 | 48 | /* If portENTER_CRITICAL is not defined then including deprecated_definitions.h 49 | did not result in a portmacro.h header file being included - and it should be 50 | included here. In this case the path to the correct portmacro.h header file 51 | must be set in the compiler's include path. */ 52 | #ifndef portENTER_CRITICAL 53 | #include "portmacro.h" 54 | #endif 55 | 56 | #if portBYTE_ALIGNMENT == 32 57 | #define portBYTE_ALIGNMENT_MASK ( 0x001f ) 58 | #endif 59 | 60 | #if portBYTE_ALIGNMENT == 16 61 | #define portBYTE_ALIGNMENT_MASK ( 0x000f ) 62 | #endif 63 | 64 | #if portBYTE_ALIGNMENT == 8 65 | #define portBYTE_ALIGNMENT_MASK ( 0x0007 ) 66 | #endif 67 | 68 | #if portBYTE_ALIGNMENT == 4 69 | #define portBYTE_ALIGNMENT_MASK ( 0x0003 ) 70 | #endif 71 | 72 | #if portBYTE_ALIGNMENT == 2 73 | #define portBYTE_ALIGNMENT_MASK ( 0x0001 ) 74 | #endif 75 | 76 | #if portBYTE_ALIGNMENT == 1 77 | #define portBYTE_ALIGNMENT_MASK ( 0x0000 ) 78 | #endif 79 | 80 | #ifndef portBYTE_ALIGNMENT_MASK 81 | #error "Invalid portBYTE_ALIGNMENT definition" 82 | #endif 83 | 84 | #ifndef portNUM_CONFIGURABLE_REGIONS 85 | #define portNUM_CONFIGURABLE_REGIONS 1 86 | #endif 87 | 88 | #ifdef __cplusplus 89 | extern "C" { 90 | #endif 91 | 92 | #include "mpu_wrappers.h" 93 | 94 | /* 95 | * Setup the stack of a new task so it is ready to be placed under the 96 | * scheduler control. The registers have to be placed on the stack in 97 | * the order that the port expects to find them. 98 | * 99 | */ 100 | #if( portUSING_MPU_WRAPPERS == 1 ) 101 | StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters, BaseType_t xRunPrivileged ) PRIVILEGED_FUNCTION; 102 | #else 103 | StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters ) PRIVILEGED_FUNCTION; 104 | #endif 105 | 106 | /* Used by heap_5.c. */ 107 | typedef struct HeapRegion 108 | { 109 | uint8_t *pucStartAddress; 110 | size_t xSizeInBytes; 111 | } HeapRegion_t; 112 | 113 | /* 114 | * Used to define multiple heap regions for use by heap_5.c. This function 115 | * must be called before any calls to pvPortMalloc() - not creating a task, 116 | * queue, semaphore, mutex, software timer, event group, etc. will result in 117 | * pvPortMalloc being called. 118 | * 119 | * pxHeapRegions passes in an array of HeapRegion_t structures - each of which 120 | * defines a region of memory that can be used as the heap. The array is 121 | * terminated by a HeapRegions_t structure that has a size of 0. The region 122 | * with the lowest start address must appear first in the array. 123 | */ 124 | void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions ) PRIVILEGED_FUNCTION; 125 | 126 | 127 | /* 128 | * Map to the memory management routines required for the port. 129 | */ 130 | void *pvPortMalloc( size_t xSize ) PRIVILEGED_FUNCTION; 131 | void vPortFree( void *pv ) PRIVILEGED_FUNCTION; 132 | void vPortInitialiseBlocks( void ) PRIVILEGED_FUNCTION; 133 | size_t xPortGetFreeHeapSize( void ) PRIVILEGED_FUNCTION; 134 | size_t xPortGetMinimumEverFreeHeapSize( void ) PRIVILEGED_FUNCTION; 135 | 136 | /* 137 | * Setup the hardware ready for the scheduler to take control. This generally 138 | * sets up a tick interrupt and sets timers for the correct tick frequency. 139 | */ 140 | BaseType_t xPortStartScheduler( void ) PRIVILEGED_FUNCTION; 141 | 142 | /* 143 | * Undo any hardware/ISR setup that was performed by xPortStartScheduler() so 144 | * the hardware is left in its original condition after the scheduler stops 145 | * executing. 146 | */ 147 | void vPortEndScheduler( void ) PRIVILEGED_FUNCTION; 148 | 149 | /* 150 | * The structures and methods of manipulating the MPU are contained within the 151 | * port layer. 152 | * 153 | * Fills the xMPUSettings structure with the memory region information 154 | * contained in xRegions. 155 | */ 156 | #if( portUSING_MPU_WRAPPERS == 1 ) 157 | struct xMEMORY_REGION; 158 | void vPortStoreTaskMPUSettings( xMPU_SETTINGS *xMPUSettings, const struct xMEMORY_REGION * const xRegions, StackType_t *pxBottomOfStack, uint32_t ulStackDepth ) PRIVILEGED_FUNCTION; 159 | #endif 160 | 161 | #ifdef __cplusplus 162 | } 163 | #endif 164 | 165 | #endif /* PORTABLE_H */ 166 | 167 | -------------------------------------------------------------------------------- /Simulator_Linux/FreeRTOS_Kernel/include/projdefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.0.0 3 | * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. If you wish to use our Amazon 14 | * FreeRTOS name, please do so in a fair use way that does not cause confusion. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | * http://www.FreeRTOS.org 24 | * http://aws.amazon.com/freertos 25 | * 26 | * 1 tab == 4 spaces! 27 | */ 28 | 29 | #ifndef PROJDEFS_H 30 | #define PROJDEFS_H 31 | 32 | /* 33 | * Defines the prototype to which task functions must conform. Defined in this 34 | * file to ensure the type is known before portable.h is included. 35 | */ 36 | typedef void (*TaskFunction_t)( void * ); 37 | 38 | /* Converts a time in milliseconds to a time in ticks. This macro can be 39 | overridden by a macro of the same name defined in FreeRTOSConfig.h in case the 40 | definition here is not suitable for your application. */ 41 | #ifndef pdMS_TO_TICKS 42 | #define pdMS_TO_TICKS( xTimeInMs ) ( ( TickType_t ) ( ( ( TickType_t ) ( xTimeInMs ) * ( TickType_t ) configTICK_RATE_HZ ) / ( TickType_t ) 1000 ) ) 43 | #endif 44 | 45 | #define pdFALSE ( ( BaseType_t ) 0 ) 46 | #define pdTRUE ( ( BaseType_t ) 1 ) 47 | 48 | #define pdPASS ( pdTRUE ) 49 | #define pdFAIL ( pdFALSE ) 50 | #define errQUEUE_EMPTY ( ( BaseType_t ) 0 ) 51 | #define errQUEUE_FULL ( ( BaseType_t ) 0 ) 52 | 53 | /* FreeRTOS error definitions. */ 54 | #define errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY ( -1 ) 55 | #define errQUEUE_BLOCKED ( -4 ) 56 | #define errQUEUE_YIELD ( -5 ) 57 | 58 | /* Macros used for basic data corruption checks. */ 59 | #ifndef configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES 60 | #define configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES 0 61 | #endif 62 | 63 | #if( configUSE_16_BIT_TICKS == 1 ) 64 | #define pdINTEGRITY_CHECK_VALUE 0x5a5a 65 | #else 66 | #define pdINTEGRITY_CHECK_VALUE 0x5a5a5a5aUL 67 | #endif 68 | 69 | /* The following errno values are used by FreeRTOS+ components, not FreeRTOS 70 | itself. */ 71 | #define pdFREERTOS_ERRNO_NONE 0 /* No errors */ 72 | #define pdFREERTOS_ERRNO_ENOENT 2 /* No such file or directory */ 73 | #define pdFREERTOS_ERRNO_EINTR 4 /* Interrupted system call */ 74 | #define pdFREERTOS_ERRNO_EIO 5 /* I/O error */ 75 | #define pdFREERTOS_ERRNO_ENXIO 6 /* No such device or address */ 76 | #define pdFREERTOS_ERRNO_EBADF 9 /* Bad file number */ 77 | #define pdFREERTOS_ERRNO_EAGAIN 11 /* No more processes */ 78 | #define pdFREERTOS_ERRNO_EWOULDBLOCK 11 /* Operation would block */ 79 | #define pdFREERTOS_ERRNO_ENOMEM 12 /* Not enough memory */ 80 | #define pdFREERTOS_ERRNO_EACCES 13 /* Permission denied */ 81 | #define pdFREERTOS_ERRNO_EFAULT 14 /* Bad address */ 82 | #define pdFREERTOS_ERRNO_EBUSY 16 /* Mount device busy */ 83 | #define pdFREERTOS_ERRNO_EEXIST 17 /* File exists */ 84 | #define pdFREERTOS_ERRNO_EXDEV 18 /* Cross-device link */ 85 | #define pdFREERTOS_ERRNO_ENODEV 19 /* No such device */ 86 | #define pdFREERTOS_ERRNO_ENOTDIR 20 /* Not a directory */ 87 | #define pdFREERTOS_ERRNO_EISDIR 21 /* Is a directory */ 88 | #define pdFREERTOS_ERRNO_EINVAL 22 /* Invalid argument */ 89 | #define pdFREERTOS_ERRNO_ENOSPC 28 /* No space left on device */ 90 | #define pdFREERTOS_ERRNO_ESPIPE 29 /* Illegal seek */ 91 | #define pdFREERTOS_ERRNO_EROFS 30 /* Read only file system */ 92 | #define pdFREERTOS_ERRNO_EUNATCH 42 /* Protocol driver not attached */ 93 | #define pdFREERTOS_ERRNO_EBADE 50 /* Invalid exchange */ 94 | #define pdFREERTOS_ERRNO_EFTYPE 79 /* Inappropriate file type or format */ 95 | #define pdFREERTOS_ERRNO_ENMFILE 89 /* No more files */ 96 | #define pdFREERTOS_ERRNO_ENOTEMPTY 90 /* Directory not empty */ 97 | #define pdFREERTOS_ERRNO_ENAMETOOLONG 91 /* File or path name too long */ 98 | #define pdFREERTOS_ERRNO_EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ 99 | #define pdFREERTOS_ERRNO_ENOBUFS 105 /* No buffer space available */ 100 | #define pdFREERTOS_ERRNO_ENOPROTOOPT 109 /* Protocol not available */ 101 | #define pdFREERTOS_ERRNO_EADDRINUSE 112 /* Address already in use */ 102 | #define pdFREERTOS_ERRNO_ETIMEDOUT 116 /* Connection timed out */ 103 | #define pdFREERTOS_ERRNO_EINPROGRESS 119 /* Connection already in progress */ 104 | #define pdFREERTOS_ERRNO_EALREADY 120 /* Socket already connected */ 105 | #define pdFREERTOS_ERRNO_EADDRNOTAVAIL 125 /* Address not available */ 106 | #define pdFREERTOS_ERRNO_EISCONN 127 /* Socket is already connected */ 107 | #define pdFREERTOS_ERRNO_ENOTCONN 128 /* Socket is not connected */ 108 | #define pdFREERTOS_ERRNO_ENOMEDIUM 135 /* No medium inserted */ 109 | #define pdFREERTOS_ERRNO_EILSEQ 138 /* An invalid UTF-16 sequence was encountered. */ 110 | #define pdFREERTOS_ERRNO_ECANCELED 140 /* Operation canceled. */ 111 | 112 | /* The following endian values are used by FreeRTOS+ components, not FreeRTOS 113 | itself. */ 114 | #define pdFREERTOS_LITTLE_ENDIAN 0 115 | #define pdFREERTOS_BIG_ENDIAN 1 116 | 117 | /* Re-defining endian values for generic naming. */ 118 | #define pdLITTLE_ENDIAN pdFREERTOS_LITTLE_ENDIAN 119 | #define pdBIG_ENDIAN pdFREERTOS_BIG_ENDIAN 120 | 121 | 122 | #endif /* PROJDEFS_H */ 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /Simulator_Linux/FreeRTOS_Kernel/include/stack_macros.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.0.0 3 | * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. If you wish to use our Amazon 14 | * FreeRTOS name, please do so in a fair use way that does not cause confusion. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | * http://www.FreeRTOS.org 24 | * http://aws.amazon.com/freertos 25 | * 26 | * 1 tab == 4 spaces! 27 | */ 28 | 29 | #ifndef STACK_MACROS_H 30 | #define STACK_MACROS_H 31 | 32 | /* 33 | * Call the stack overflow hook function if the stack of the task being swapped 34 | * out is currently overflowed, or looks like it might have overflowed in the 35 | * past. 36 | * 37 | * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check 38 | * the current stack state only - comparing the current top of stack value to 39 | * the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1 40 | * will also cause the last few stack bytes to be checked to ensure the value 41 | * to which the bytes were set when the task was created have not been 42 | * overwritten. Note this second test does not guarantee that an overflowed 43 | * stack will always be recognised. 44 | */ 45 | 46 | /*-----------------------------------------------------------*/ 47 | 48 | #if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) ) 49 | 50 | /* Only the current stack state is to be checked. */ 51 | #define taskCHECK_FOR_STACK_OVERFLOW() \ 52 | { \ 53 | /* Is the currently saved stack pointer within the stack limit? */ \ 54 | if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \ 55 | { \ 56 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 57 | } \ 58 | } 59 | 60 | #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ 61 | /*-----------------------------------------------------------*/ 62 | 63 | #if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) ) 64 | 65 | /* Only the current stack state is to be checked. */ 66 | #define taskCHECK_FOR_STACK_OVERFLOW() \ 67 | { \ 68 | \ 69 | /* Is the currently saved stack pointer within the stack limit? */ \ 70 | if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \ 71 | { \ 72 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 73 | } \ 74 | } 75 | 76 | #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ 77 | /*-----------------------------------------------------------*/ 78 | 79 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) ) 80 | 81 | #define taskCHECK_FOR_STACK_OVERFLOW() \ 82 | { \ 83 | const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \ 84 | const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5; \ 85 | \ 86 | if( ( pulStack[ 0 ] != ulCheckValue ) || \ 87 | ( pulStack[ 1 ] != ulCheckValue ) || \ 88 | ( pulStack[ 2 ] != ulCheckValue ) || \ 89 | ( pulStack[ 3 ] != ulCheckValue ) ) \ 90 | { \ 91 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 92 | } \ 93 | } 94 | 95 | #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ 96 | /*-----------------------------------------------------------*/ 97 | 98 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) ) 99 | 100 | #define taskCHECK_FOR_STACK_OVERFLOW() \ 101 | { \ 102 | int8_t *pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \ 103 | static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 104 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 105 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 106 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 107 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ 108 | \ 109 | \ 110 | pcEndOfStack -= sizeof( ucExpectedStackBytes ); \ 111 | \ 112 | /* Has the extremity of the task stack ever been written over? */ \ 113 | if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \ 114 | { \ 115 | vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 116 | } \ 117 | } 118 | 119 | #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ 120 | /*-----------------------------------------------------------*/ 121 | 122 | /* Remove stack overflow macro if not being used. */ 123 | #ifndef taskCHECK_FOR_STACK_OVERFLOW 124 | #define taskCHECK_FOR_STACK_OVERFLOW() 125 | #endif 126 | 127 | 128 | 129 | #endif /* STACK_MACROS_H */ 130 | 131 | -------------------------------------------------------------------------------- /Simulator_Linux/FreeRTOS_Kernel/include/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /Simulator_Linux/FreeRTOS_Kernel/list.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.0.0 3 | * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. If you wish to use our Amazon 14 | * FreeRTOS name, please do so in a fair use way that does not cause confusion. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | * http://www.FreeRTOS.org 24 | * http://aws.amazon.com/freertos 25 | * 26 | * 1 tab == 4 spaces! 27 | */ 28 | 29 | 30 | #include