├── 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 31 | #include "FreeRTOS.h" 32 | #include "list.h" 33 | 34 | /*----------------------------------------------------------- 35 | * PUBLIC LIST API documented in list.h 36 | *----------------------------------------------------------*/ 37 | 38 | void vListInitialise( List_t * const pxList ) 39 | { 40 | /* The list structure contains a list item which is used to mark the 41 | end of the list. To initialise the list the list end is inserted 42 | as the only list entry. */ 43 | pxList->pxIndex = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */ 44 | 45 | /* The list end value is the highest possible value in the list to 46 | ensure it remains at the end of the list. */ 47 | pxList->xListEnd.xItemValue = portMAX_DELAY; 48 | 49 | /* The list end next and previous pointers point to itself so we know 50 | when the list is empty. */ 51 | pxList->xListEnd.pxNext = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */ 52 | pxList->xListEnd.pxPrevious = ( ListItem_t * ) &( pxList->xListEnd );/*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */ 53 | 54 | pxList->uxNumberOfItems = ( UBaseType_t ) 0U; 55 | 56 | /* Write known values into the list if 57 | configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ 58 | listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList ); 59 | listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList ); 60 | } 61 | /*-----------------------------------------------------------*/ 62 | 63 | void vListInitialiseItem( ListItem_t * const pxItem ) 64 | { 65 | /* Make sure the list item is not recorded as being on a list. */ 66 | pxItem->pvContainer = NULL; 67 | 68 | /* Write known values into the list item if 69 | configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ 70 | listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ); 71 | listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ); 72 | } 73 | /*-----------------------------------------------------------*/ 74 | 75 | void vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem ) 76 | { 77 | ListItem_t * const pxIndex = pxList->pxIndex; 78 | 79 | /* Only effective when configASSERT() is also defined, these tests may catch 80 | the list data structures being overwritten in memory. They will not catch 81 | data errors caused by incorrect configuration or use of FreeRTOS. */ 82 | listTEST_LIST_INTEGRITY( pxList ); 83 | listTEST_LIST_ITEM_INTEGRITY( pxNewListItem ); 84 | 85 | /* Insert a new list item into pxList, but rather than sort the list, 86 | makes the new list item the last item to be removed by a call to 87 | listGET_OWNER_OF_NEXT_ENTRY(). */ 88 | pxNewListItem->pxNext = pxIndex; 89 | pxNewListItem->pxPrevious = pxIndex->pxPrevious; 90 | 91 | /* Only used during decision coverage testing. */ 92 | mtCOVERAGE_TEST_DELAY(); 93 | 94 | pxIndex->pxPrevious->pxNext = pxNewListItem; 95 | pxIndex->pxPrevious = pxNewListItem; 96 | 97 | /* Remember which list the item is in. */ 98 | pxNewListItem->pvContainer = ( void * ) pxList; 99 | 100 | ( pxList->uxNumberOfItems )++; 101 | } 102 | /*-----------------------------------------------------------*/ 103 | 104 | void vListInsert( List_t * const pxList, ListItem_t * const pxNewListItem ) 105 | { 106 | ListItem_t *pxIterator; 107 | const TickType_t xValueOfInsertion = pxNewListItem->xItemValue; 108 | 109 | /* Only effective when configASSERT() is also defined, these tests may catch 110 | the list data structures being overwritten in memory. They will not catch 111 | data errors caused by incorrect configuration or use of FreeRTOS. */ 112 | listTEST_LIST_INTEGRITY( pxList ); 113 | listTEST_LIST_ITEM_INTEGRITY( pxNewListItem ); 114 | 115 | /* Insert the new list item into the list, sorted in xItemValue order. 116 | 117 | If the list already contains a list item with the same item value then the 118 | new list item should be placed after it. This ensures that TCB's which are 119 | stored in ready lists (all of which have the same xItemValue value) get a 120 | share of the CPU. However, if the xItemValue is the same as the back marker 121 | the iteration loop below will not end. Therefore the value is checked 122 | first, and the algorithm slightly modified if necessary. */ 123 | if( xValueOfInsertion == portMAX_DELAY ) 124 | { 125 | pxIterator = pxList->xListEnd.pxPrevious; 126 | } 127 | else 128 | { 129 | /* *** NOTE *********************************************************** 130 | If you find your application is crashing here then likely causes are 131 | listed below. In addition see http://www.freertos.org/FAQHelp.html for 132 | more tips, and ensure configASSERT() is defined! 133 | http://www.freertos.org/a00110.html#configASSERT 134 | 135 | 1) Stack overflow - 136 | see http://www.freertos.org/Stacks-and-stack-overflow-checking.html 137 | 2) Incorrect interrupt priority assignment, especially on Cortex-M 138 | parts where numerically high priority values denote low actual 139 | interrupt priorities, which can seem counter intuitive. See 140 | http://www.freertos.org/RTOS-Cortex-M3-M4.html and the definition 141 | of configMAX_SYSCALL_INTERRUPT_PRIORITY on 142 | http://www.freertos.org/a00110.html 143 | 3) Calling an API function from within a critical section or when 144 | the scheduler is suspended, or calling an API function that does 145 | not end in "FromISR" from an interrupt. 146 | 4) Using a queue or semaphore before it has been initialised or 147 | before the scheduler has been started (are interrupts firing 148 | before vTaskStartScheduler() has been called?). 149 | **********************************************************************/ 150 | 151 | for( pxIterator = ( ListItem_t * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */ 152 | { 153 | /* There is nothing to do here, just iterating to the wanted 154 | insertion position. */ 155 | } 156 | } 157 | 158 | pxNewListItem->pxNext = pxIterator->pxNext; 159 | pxNewListItem->pxNext->pxPrevious = pxNewListItem; 160 | pxNewListItem->pxPrevious = pxIterator; 161 | pxIterator->pxNext = pxNewListItem; 162 | 163 | /* Remember which list the item is in. This allows fast removal of the 164 | item later. */ 165 | pxNewListItem->pvContainer = ( void * ) pxList; 166 | 167 | ( pxList->uxNumberOfItems )++; 168 | } 169 | /*-----------------------------------------------------------*/ 170 | 171 | UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove ) 172 | { 173 | /* The list item knows which list it is in. Obtain the list from the list 174 | item. */ 175 | List_t * const pxList = ( List_t * ) pxItemToRemove->pvContainer; 176 | 177 | pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious; 178 | pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext; 179 | 180 | /* Only used during decision coverage testing. */ 181 | mtCOVERAGE_TEST_DELAY(); 182 | 183 | /* Make sure the index is left pointing to a valid item. */ 184 | if( pxList->pxIndex == pxItemToRemove ) 185 | { 186 | pxList->pxIndex = pxItemToRemove->pxPrevious; 187 | } 188 | else 189 | { 190 | mtCOVERAGE_TEST_MARKER(); 191 | } 192 | 193 | pxItemToRemove->pvContainer = NULL; 194 | ( pxList->uxNumberOfItems )--; 195 | 196 | return pxList->uxNumberOfItems; 197 | } 198 | /*-----------------------------------------------------------*/ 199 | 200 | -------------------------------------------------------------------------------- /Simulator_Linux/FreeRTOS_Kernel/portable/GCC/Posix/port.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 William Davy - william.davy@wittenstein.co.uk 3 | Contributed to FreeRTOS.org V5.3.0. 4 | 5 | This file is part of the FreeRTOS.org distribution. 6 | 7 | FreeRTOS.org is free software; you can redistribute it and/or modify it 8 | under the terms of the GNU General Public License (version 2) as published 9 | by the Free Software Foundation and modified by the FreeRTOS exception. 10 | 11 | FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59 18 | Temple Place, Suite 330, Boston, MA 02111-1307 USA. 19 | 20 | A special exception to the GPL is included to allow you to distribute a 21 | combined work that includes FreeRTOS.org without being obliged to provide 22 | the source code for any proprietary components. See the licensing section 23 | of http://www.FreeRTOS.org for full details. 24 | 25 | 26 | *************************************************************************** 27 | * * 28 | * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation * 29 | * * 30 | * This is a concise, step by step, 'hands on' guide that describes both * 31 | * general multitasking concepts and FreeRTOS specifics. It presents and * 32 | * explains numerous examples that are written using the FreeRTOS API. * 33 | * Full source code for all the examples is provided in an accompanying * 34 | * .zip file. * 35 | * * 36 | *************************************************************************** 37 | 38 | 1 tab == 4 spaces! 39 | 40 | Please ensure to read the configuration and relevant port sections of the 41 | online documentation. 42 | 43 | http://www.FreeRTOS.org - Documentation, latest information, license and 44 | contact details. 45 | 46 | http://www.SafeRTOS.com - A version that is certified for use in safety 47 | critical systems. 48 | 49 | http://www.OpenRTOS.com - Commercial support, development, porting, 50 | licensing and training services. 51 | */ 52 | 53 | /*----------------------------------------------------------- 54 | * Implementation of functions defined in portable.h for the Posix port. 55 | *----------------------------------------------------------*/ 56 | 57 | #include 58 | #include 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | #include 68 | 69 | /* Scheduler includes. */ 70 | #include "FreeRTOS.h" 71 | #include "task.h" 72 | /*-----------------------------------------------------------*/ 73 | 74 | #define MAX_NUMBER_OF_TASKS ( _POSIX_THREAD_THREADS_MAX ) 75 | /*-----------------------------------------------------------*/ 76 | 77 | /* Parameters to pass to the newly created pthread. */ 78 | typedef struct XPARAMS 79 | { 80 | pdTASK_CODE pxCode; 81 | void *pvParams; 82 | } xParams; 83 | 84 | /* Each task maintains its own interrupt status in the critical nesting variable. */ 85 | typedef struct THREAD_SUSPENSIONS 86 | { 87 | pthread_t hThread; 88 | xTaskHandle hTask; 89 | unsigned portBASE_TYPE uxCriticalNesting; 90 | } xThreadState; 91 | /*-----------------------------------------------------------*/ 92 | 93 | static xThreadState *pxThreads; 94 | static pthread_once_t hSigSetupThread = PTHREAD_ONCE_INIT; 95 | static pthread_attr_t xThreadAttributes; 96 | static pthread_mutex_t xSuspendResumeThreadMutex = PTHREAD_MUTEX_INITIALIZER; 97 | static pthread_mutex_t xSingleThreadMutex = PTHREAD_MUTEX_INITIALIZER; 98 | static pthread_t hMainThread = ( pthread_t )NULL; 99 | /*-----------------------------------------------------------*/ 100 | 101 | static volatile portBASE_TYPE xSentinel = 0; 102 | static volatile portBASE_TYPE xSchedulerEnd = pdFALSE; 103 | static volatile portBASE_TYPE xInterruptsEnabled = pdTRUE; 104 | static volatile portBASE_TYPE xServicingTick = pdFALSE; 105 | static volatile portBASE_TYPE xPendYield = pdFALSE; 106 | static volatile portLONG lIndexOfLastAddedTask = 0; 107 | static volatile unsigned portBASE_TYPE uxCriticalNesting; 108 | /*-----------------------------------------------------------*/ 109 | 110 | /* 111 | * Setup the timer to generate the tick interrupts. 112 | */ 113 | static void prvSetupTimerInterrupt( void ); 114 | static void *prvWaitForStart( void * pvParams ); 115 | static void prvSuspendSignalHandler(int sig); 116 | static void prvResumeSignalHandler(int sig); 117 | static void prvSetupSignalsAndSchedulerPolicy( void ); 118 | static void prvSuspendThread( pthread_t xThreadId ); 119 | static void prvResumeThread( pthread_t xThreadId ); 120 | static pthread_t prvGetThreadHandle( xTaskHandle hTask ); 121 | static portLONG prvGetFreeThreadState( void ); 122 | static void prvSetTaskCriticalNesting( pthread_t xThreadId, unsigned portBASE_TYPE uxNesting ); 123 | static unsigned portBASE_TYPE prvGetTaskCriticalNesting( pthread_t xThreadId ); 124 | static void prvDeleteThread( void *xThreadId ); 125 | /*-----------------------------------------------------------*/ 126 | 127 | /* 128 | * Exception handlers. 129 | */ 130 | void vPortYield( void ); 131 | void vPortSystemTickHandler( int sig ); 132 | 133 | /* 134 | * Start first task is a separate function so it can be tested in isolation. 135 | */ 136 | void vPortStartFirstTask( void ); 137 | /*-----------------------------------------------------------*/ 138 | 139 | /* 140 | * See header file for description. 141 | */ 142 | portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) 143 | { 144 | /* Should actually keep this struct on the stack. */ 145 | xParams *pxThisThreadParams = pvPortMalloc( sizeof( xParams ) ); 146 | 147 | (void)pthread_once( &hSigSetupThread, prvSetupSignalsAndSchedulerPolicy ); 148 | 149 | if ( (pthread_t)NULL == hMainThread ) 150 | { 151 | hMainThread = pthread_self(); 152 | } 153 | 154 | /* No need to join the threads. */ 155 | pthread_attr_init( &xThreadAttributes ); 156 | pthread_attr_setdetachstate( &xThreadAttributes, PTHREAD_CREATE_DETACHED ); 157 | 158 | /* Add the task parameters. */ 159 | pxThisThreadParams->pxCode = pxCode; 160 | pxThisThreadParams->pvParams = pvParameters; 161 | 162 | vPortEnterCritical(); 163 | 164 | lIndexOfLastAddedTask = prvGetFreeThreadState(); 165 | 166 | /* Create the new pThread. */ 167 | if ( 0 == pthread_mutex_lock( &xSingleThreadMutex ) ) 168 | { 169 | xSentinel = 0; 170 | if ( 0 != pthread_create( &( pxThreads[ lIndexOfLastAddedTask ].hThread ), &xThreadAttributes, prvWaitForStart, (void *)pxThisThreadParams ) ) 171 | { 172 | /* Thread create failed, signal the failure */ 173 | pxTopOfStack = 0; 174 | } 175 | 176 | /* Wait until the task suspends. */ 177 | (void)pthread_mutex_unlock( &xSingleThreadMutex ); 178 | while ( xSentinel == 0 ); 179 | vPortExitCritical(); 180 | } 181 | 182 | return pxTopOfStack; 183 | } 184 | /*-----------------------------------------------------------*/ 185 | 186 | void vPortStartFirstTask( void ) 187 | { 188 | /* Initialise the critical nesting count ready for the first task. */ 189 | uxCriticalNesting = 0; 190 | 191 | /* Start the first task. */ 192 | vPortEnableInterrupts(); 193 | 194 | /* Start the first task. */ 195 | prvResumeThread( prvGetThreadHandle( xTaskGetCurrentTaskHandle() ) ); 196 | } 197 | /*-----------------------------------------------------------*/ 198 | 199 | /* 200 | * See header file for description. 201 | */ 202 | portBASE_TYPE xPortStartScheduler( void ) 203 | { 204 | portBASE_TYPE xResult; 205 | int iSignal; 206 | sigset_t xSignals; 207 | sigset_t xSignalToBlock; 208 | sigset_t xSignalsBlocked; 209 | portLONG lIndex; 210 | 211 | /* Establish the signals to block before they are needed. */ 212 | sigfillset( &xSignalToBlock ); 213 | 214 | /* Block until the end */ 215 | (void)pthread_sigmask( SIG_SETMASK, &xSignalToBlock, &xSignalsBlocked ); 216 | 217 | for ( lIndex = 0; lIndex < MAX_NUMBER_OF_TASKS; lIndex++ ) 218 | { 219 | pxThreads[ lIndex ].uxCriticalNesting = 0; 220 | } 221 | 222 | /* Start the timer that generates the tick ISR. Interrupts are disabled 223 | here already. */ 224 | prvSetupTimerInterrupt(); 225 | 226 | /* Start the first task. Will not return unless all threads are killed. */ 227 | vPortStartFirstTask(); 228 | 229 | /* This is the end signal we are looking for. */ 230 | sigemptyset( &xSignals ); 231 | sigaddset( &xSignals, SIG_RESUME ); 232 | 233 | while ( pdTRUE != xSchedulerEnd ) 234 | { 235 | if ( 0 != sigwait( &xSignals, &iSignal ) ) 236 | { 237 | printf( "Main thread spurious signal: %d\n", iSignal ); 238 | } 239 | } 240 | 241 | printf( "Cleaning Up, Exiting.\n" ); 242 | /* Cleanup the mutexes */ 243 | xResult = pthread_mutex_destroy( &xSuspendResumeThreadMutex ); 244 | xResult = pthread_mutex_destroy( &xSingleThreadMutex ); 245 | vPortFree( (void *)pxThreads ); 246 | 247 | /* Should not get here! */ 248 | return 0; 249 | } 250 | /*-----------------------------------------------------------*/ 251 | 252 | void vPortEndScheduler( void ) 253 | { 254 | portBASE_TYPE xNumberOfThreads; 255 | portBASE_TYPE xResult; 256 | for ( xNumberOfThreads = 0; xNumberOfThreads < MAX_NUMBER_OF_TASKS; xNumberOfThreads++ ) 257 | { 258 | if ( ( pthread_t )NULL != pxThreads[ xNumberOfThreads ].hThread ) 259 | { 260 | /* Kill all of the threads, they are in the detached state. */ 261 | xResult = pthread_cancel( pxThreads[ xNumberOfThreads ].hThread ); 262 | } 263 | } 264 | 265 | /* Signal the scheduler to exit its loop. */ 266 | xSchedulerEnd = pdTRUE; 267 | (void)pthread_kill( hMainThread, SIG_RESUME ); 268 | } 269 | /*-----------------------------------------------------------*/ 270 | 271 | void vPortYieldFromISR( void ) 272 | { 273 | /* Calling Yield from a Interrupt/Signal handler often doesn't work because the 274 | * xSingleThreadMutex is already owned by an original call to Yield. Therefore, 275 | * simply indicate that a yield is required soon. 276 | */ 277 | xPendYield = pdTRUE; 278 | } 279 | /*-----------------------------------------------------------*/ 280 | 281 | void vPortEnterCritical( void ) 282 | { 283 | vPortDisableInterrupts(); 284 | uxCriticalNesting++; 285 | } 286 | /*-----------------------------------------------------------*/ 287 | 288 | void vPortExitCritical( void ) 289 | { 290 | /* Check for unmatched exits. */ 291 | if ( uxCriticalNesting > 0 ) 292 | { 293 | uxCriticalNesting--; 294 | } 295 | 296 | /* If we have reached 0 then re-enable the interrupts. */ 297 | if( uxCriticalNesting == 0 ) 298 | { 299 | /* Have we missed ticks? This is the equivalent of pending an interrupt. */ 300 | if ( pdTRUE == xPendYield ) 301 | { 302 | xPendYield = pdFALSE; 303 | vPortYield(); 304 | } 305 | vPortEnableInterrupts(); 306 | } 307 | } 308 | /*-----------------------------------------------------------*/ 309 | 310 | void vPortYield( void ) 311 | { 312 | pthread_t xTaskToSuspend; 313 | pthread_t xTaskToResume; 314 | 315 | if ( 0 == pthread_mutex_lock( &xSingleThreadMutex ) ) 316 | { 317 | xTaskToSuspend = prvGetThreadHandle( xTaskGetCurrentTaskHandle() ); 318 | 319 | vTaskSwitchContext(); 320 | 321 | xTaskToResume = prvGetThreadHandle( xTaskGetCurrentTaskHandle() ); 322 | if ( xTaskToSuspend != xTaskToResume ) 323 | { 324 | /* Remember and switch the critical nesting. */ 325 | prvSetTaskCriticalNesting( xTaskToSuspend, uxCriticalNesting ); 326 | uxCriticalNesting = prvGetTaskCriticalNesting( xTaskToResume ); 327 | /* Switch tasks. */ 328 | prvResumeThread( xTaskToResume ); 329 | prvSuspendThread( xTaskToSuspend ); 330 | } 331 | else 332 | { 333 | /* Yielding to self */ 334 | (void)pthread_mutex_unlock( &xSingleThreadMutex ); 335 | } 336 | } 337 | } 338 | /*-----------------------------------------------------------*/ 339 | 340 | void vPortDisableInterrupts( void ) 341 | { 342 | xInterruptsEnabled = pdFALSE; 343 | } 344 | /*-----------------------------------------------------------*/ 345 | 346 | void vPortEnableInterrupts( void ) 347 | { 348 | xInterruptsEnabled = pdTRUE; 349 | } 350 | /*-----------------------------------------------------------*/ 351 | 352 | portBASE_TYPE xPortSetInterruptMask( void ) 353 | { 354 | portBASE_TYPE xReturn = xInterruptsEnabled; 355 | xInterruptsEnabled = pdFALSE; 356 | return xReturn; 357 | } 358 | /*-----------------------------------------------------------*/ 359 | 360 | void vPortClearInterruptMask( portBASE_TYPE xMask ) 361 | { 362 | xInterruptsEnabled = xMask; 363 | } 364 | /*-----------------------------------------------------------*/ 365 | 366 | /* 367 | * Setup the systick timer to generate the tick interrupts at the required 368 | * frequency. 369 | */ 370 | void prvSetupTimerInterrupt( void ) 371 | { 372 | struct itimerval itimer, oitimer; 373 | portTickType xMicroSeconds = portTICK_RATE_MICROSECONDS; 374 | 375 | /* Initialise the structure with the current timer information. */ 376 | if ( 0 == getitimer( TIMER_TYPE, &itimer ) ) 377 | { 378 | /* Set the interval between timer events. */ 379 | itimer.it_interval.tv_sec = 0; 380 | itimer.it_interval.tv_usec = xMicroSeconds; 381 | 382 | /* Set the current count-down. */ 383 | itimer.it_value.tv_sec = 0; 384 | itimer.it_value.tv_usec = xMicroSeconds; 385 | 386 | /* Set-up the timer interrupt. */ 387 | if ( 0 != setitimer( TIMER_TYPE, &itimer, &oitimer ) ) 388 | { 389 | printf( "Set Timer problem.\n" ); 390 | } 391 | } 392 | else 393 | { 394 | printf( "Get Timer problem.\n" ); 395 | } 396 | } 397 | /*-----------------------------------------------------------*/ 398 | 399 | void vPortSystemTickHandler( int sig ) 400 | { 401 | pthread_t xTaskToSuspend; 402 | pthread_t xTaskToResume; 403 | 404 | if ( ( pdTRUE == xInterruptsEnabled ) && ( pdTRUE != xServicingTick ) ) 405 | { 406 | if ( 0 == pthread_mutex_trylock( &xSingleThreadMutex ) ) 407 | { 408 | xServicingTick = pdTRUE; 409 | 410 | xTaskToSuspend = prvGetThreadHandle( xTaskGetCurrentTaskHandle() ); 411 | /* Tick Increment. */ 412 | xTaskIncrementTick(); 413 | 414 | /* Select Next Task. */ 415 | #if ( configUSE_PREEMPTION == 1 ) 416 | vTaskSwitchContext(); 417 | #endif 418 | xTaskToResume = prvGetThreadHandle( xTaskGetCurrentTaskHandle() ); 419 | 420 | /* The only thread that can process this tick is the running thread. */ 421 | if ( xTaskToSuspend != xTaskToResume ) 422 | { 423 | /* Remember and switch the critical nesting. */ 424 | prvSetTaskCriticalNesting( xTaskToSuspend, uxCriticalNesting ); 425 | uxCriticalNesting = prvGetTaskCriticalNesting( xTaskToResume ); 426 | /* Resume next task. */ 427 | prvResumeThread( xTaskToResume ); 428 | /* Suspend the current task. */ 429 | prvSuspendThread( xTaskToSuspend ); 430 | } 431 | else 432 | { 433 | /* Release the lock as we are Resuming. */ 434 | (void)pthread_mutex_unlock( &xSingleThreadMutex ); 435 | } 436 | xServicingTick = pdFALSE; 437 | } 438 | else 439 | { 440 | xPendYield = pdTRUE; 441 | } 442 | } 443 | else 444 | { 445 | xPendYield = pdTRUE; 446 | } 447 | } 448 | /*-----------------------------------------------------------*/ 449 | 450 | void vPortForciblyEndThread( void *pxTaskToDelete ) 451 | { 452 | xTaskHandle hTaskToDelete = ( xTaskHandle )pxTaskToDelete; 453 | pthread_t xTaskToDelete; 454 | pthread_t xTaskToResume; 455 | portBASE_TYPE xResult; 456 | 457 | if ( 0 == pthread_mutex_lock( &xSingleThreadMutex ) ) 458 | { 459 | xTaskToDelete = prvGetThreadHandle( hTaskToDelete ); 460 | xTaskToResume = prvGetThreadHandle( xTaskGetCurrentTaskHandle() ); 461 | 462 | if ( xTaskToResume == xTaskToDelete ) 463 | { 464 | /* This is a suicidal thread, need to select a different task to run. */ 465 | vTaskSwitchContext(); 466 | xTaskToResume = prvGetThreadHandle( xTaskGetCurrentTaskHandle() ); 467 | } 468 | 469 | if ( pthread_self() != xTaskToDelete ) 470 | { 471 | /* Cancelling a thread that is not me. */ 472 | if ( xTaskToDelete != ( pthread_t )NULL ) 473 | { 474 | /* Send a signal to wake the task so that it definitely cancels. */ 475 | pthread_testcancel(); 476 | xResult = pthread_cancel( xTaskToDelete ); 477 | /* Pthread Clean-up function will note the cancellation. */ 478 | } 479 | (void)pthread_mutex_unlock( &xSingleThreadMutex ); 480 | } 481 | else 482 | { 483 | /* Resume the other thread. */ 484 | prvResumeThread( xTaskToResume ); 485 | /* Pthread Clean-up function will note the cancellation. */ 486 | /* Release the execution. */ 487 | uxCriticalNesting = 0; 488 | vPortEnableInterrupts(); 489 | (void)pthread_mutex_unlock( &xSingleThreadMutex ); 490 | /* Commit suicide */ 491 | pthread_exit( (void *)1 ); 492 | } 493 | } 494 | } 495 | /*-----------------------------------------------------------*/ 496 | 497 | void *prvWaitForStart( void * pvParams ) 498 | { 499 | xParams * pxParams = ( xParams * )pvParams; 500 | pdTASK_CODE pvCode = pxParams->pxCode; 501 | void * pParams = pxParams->pvParams; 502 | vPortFree( pvParams ); 503 | 504 | pthread_cleanup_push( prvDeleteThread, (void *)pthread_self() ); 505 | 506 | if ( 0 == pthread_mutex_lock( &xSingleThreadMutex ) ) 507 | { 508 | prvSuspendThread( pthread_self() ); 509 | } 510 | 511 | pvCode( pParams ); 512 | 513 | pthread_cleanup_pop( 1 ); 514 | return (void *)NULL; 515 | } 516 | /*-----------------------------------------------------------*/ 517 | 518 | void prvSuspendSignalHandler(int sig) 519 | { 520 | sigset_t xSignals; 521 | 522 | /* Only interested in the resume signal. */ 523 | sigemptyset( &xSignals ); 524 | sigaddset( &xSignals, SIG_RESUME ); 525 | xSentinel = 1; 526 | 527 | /* Unlock the Single thread mutex to allow the resumed task to continue. */ 528 | if ( 0 != pthread_mutex_unlock( &xSingleThreadMutex ) ) 529 | { 530 | printf( "Releasing someone else's lock.\n" ); 531 | } 532 | 533 | /* Wait on the resume signal. */ 534 | if ( 0 != sigwait( &xSignals, &sig ) ) 535 | { 536 | printf( "SSH: Sw %d\n", sig ); 537 | } 538 | 539 | /* Will resume here when the SIG_RESUME signal is received. */ 540 | /* Need to set the interrupts based on the task's critical nesting. */ 541 | if ( uxCriticalNesting == 0 ) 542 | { 543 | vPortEnableInterrupts(); 544 | } 545 | else 546 | { 547 | vPortDisableInterrupts(); 548 | } 549 | } 550 | /*-----------------------------------------------------------*/ 551 | 552 | void prvSuspendThread( pthread_t xThreadId ) 553 | { 554 | portBASE_TYPE xResult = pthread_mutex_lock( &xSuspendResumeThreadMutex ); 555 | if ( 0 == xResult ) 556 | { 557 | /* Set-up for the Suspend Signal handler? */ 558 | xSentinel = 0; 559 | xResult = pthread_mutex_unlock( &xSuspendResumeThreadMutex ); 560 | xResult = pthread_kill( xThreadId, SIG_SUSPEND ); 561 | while ( ( xSentinel == 0 ) && ( pdTRUE != xServicingTick ) ) 562 | { 563 | sched_yield(); 564 | } 565 | } 566 | } 567 | /*-----------------------------------------------------------*/ 568 | 569 | void prvResumeSignalHandler(int sig) 570 | { 571 | /* Yield the Scheduler to ensure that the yielding thread completes. */ 572 | if ( 0 == pthread_mutex_lock( &xSingleThreadMutex ) ) 573 | { 574 | (void)pthread_mutex_unlock( &xSingleThreadMutex ); 575 | } 576 | } 577 | /*-----------------------------------------------------------*/ 578 | 579 | void prvResumeThread( pthread_t xThreadId ) 580 | { 581 | portBASE_TYPE xResult; 582 | if ( 0 == pthread_mutex_lock( &xSuspendResumeThreadMutex ) ) 583 | { 584 | if ( pthread_self() != xThreadId ) 585 | { 586 | xResult = pthread_kill( xThreadId, SIG_RESUME ); 587 | } 588 | xResult = pthread_mutex_unlock( &xSuspendResumeThreadMutex ); 589 | } 590 | } 591 | /*-----------------------------------------------------------*/ 592 | 593 | void prvSetupSignalsAndSchedulerPolicy( void ) 594 | { 595 | /* The following code would allow for configuring the scheduling of this task as a Real-time task. 596 | * The process would then need to be run with higher privileges for it to take affect. 597 | int iPolicy; 598 | int iResult; 599 | int iSchedulerPriority; 600 | iResult = pthread_getschedparam( pthread_self(), &iPolicy, &iSchedulerPriority ); 601 | iResult = pthread_attr_setschedpolicy( &xThreadAttributes, SCHED_FIFO ); 602 | iPolicy = SCHED_FIFO; 603 | iResult = pthread_setschedparam( pthread_self(), iPolicy, &iSchedulerPriority ); */ 604 | 605 | struct sigaction sigsuspendself, sigresume, sigtick; 606 | portLONG lIndex; 607 | 608 | pxThreads = ( xThreadState *)pvPortMalloc( sizeof( xThreadState ) * MAX_NUMBER_OF_TASKS ); 609 | for ( lIndex = 0; lIndex < MAX_NUMBER_OF_TASKS; lIndex++ ) 610 | { 611 | pxThreads[ lIndex ].hThread = ( pthread_t )NULL; 612 | pxThreads[ lIndex ].hTask = ( xTaskHandle )NULL; 613 | pxThreads[ lIndex ].uxCriticalNesting = 0; 614 | } 615 | 616 | sigsuspendself.sa_flags = 0; 617 | sigsuspendself.sa_handler = prvSuspendSignalHandler; 618 | sigfillset( &sigsuspendself.sa_mask ); 619 | 620 | sigresume.sa_flags = 0; 621 | sigresume.sa_handler = prvResumeSignalHandler; 622 | sigfillset( &sigresume.sa_mask ); 623 | 624 | sigtick.sa_flags = 0; 625 | sigtick.sa_handler = vPortSystemTickHandler; 626 | sigfillset( &sigtick.sa_mask ); 627 | 628 | if ( 0 != sigaction( SIG_SUSPEND, &sigsuspendself, NULL ) ) 629 | { 630 | printf( "Problem installing SIG_SUSPEND_SELF\n" ); 631 | } 632 | if ( 0 != sigaction( SIG_RESUME, &sigresume, NULL ) ) 633 | { 634 | printf( "Problem installing SIG_RESUME\n" ); 635 | } 636 | if ( 0 != sigaction( SIG_TICK, &sigtick, NULL ) ) 637 | { 638 | printf( "Problem installing SIG_TICK\n" ); 639 | } 640 | printf( "Running as PID: %d\n", getpid() ); 641 | } 642 | /*-----------------------------------------------------------*/ 643 | 644 | pthread_t prvGetThreadHandle( xTaskHandle hTask ) 645 | { 646 | pthread_t hThread = ( pthread_t )NULL; 647 | portLONG lIndex; 648 | for ( lIndex = 0; lIndex < MAX_NUMBER_OF_TASKS; lIndex++ ) 649 | { 650 | if ( pxThreads[ lIndex ].hTask == hTask ) 651 | { 652 | hThread = pxThreads[ lIndex ].hThread; 653 | break; 654 | } 655 | } 656 | return hThread; 657 | } 658 | /*-----------------------------------------------------------*/ 659 | 660 | portLONG prvGetFreeThreadState( void ) 661 | { 662 | portLONG lIndex; 663 | for ( lIndex = 0; lIndex < MAX_NUMBER_OF_TASKS; lIndex++ ) 664 | { 665 | if ( pxThreads[ lIndex ].hThread == ( pthread_t )NULL ) 666 | { 667 | break; 668 | } 669 | } 670 | 671 | if ( MAX_NUMBER_OF_TASKS == lIndex ) 672 | { 673 | printf( "No more free threads, please increase the maximum.\n" ); 674 | lIndex = 0; 675 | vPortEndScheduler(); 676 | } 677 | 678 | return lIndex; 679 | } 680 | /*-----------------------------------------------------------*/ 681 | 682 | void prvSetTaskCriticalNesting( pthread_t xThreadId, unsigned portBASE_TYPE uxNesting ) 683 | { 684 | portLONG lIndex; 685 | for ( lIndex = 0; lIndex < MAX_NUMBER_OF_TASKS; lIndex++ ) 686 | { 687 | if ( pxThreads[ lIndex ].hThread == xThreadId ) 688 | { 689 | pxThreads[ lIndex ].uxCriticalNesting = uxNesting; 690 | break; 691 | } 692 | } 693 | } 694 | /*-----------------------------------------------------------*/ 695 | 696 | unsigned portBASE_TYPE prvGetTaskCriticalNesting( pthread_t xThreadId ) 697 | { 698 | unsigned portBASE_TYPE uxNesting = 0; 699 | portLONG lIndex; 700 | for ( lIndex = 0; lIndex < MAX_NUMBER_OF_TASKS; lIndex++ ) 701 | { 702 | if ( pxThreads[ lIndex ].hThread == xThreadId ) 703 | { 704 | uxNesting = pxThreads[ lIndex ].uxCriticalNesting; 705 | break; 706 | } 707 | } 708 | return uxNesting; 709 | } 710 | /*-----------------------------------------------------------*/ 711 | 712 | void prvDeleteThread( void *xThreadId ) 713 | { 714 | portLONG lIndex; 715 | for ( lIndex = 0; lIndex < MAX_NUMBER_OF_TASKS; lIndex++ ) 716 | { 717 | if ( pxThreads[ lIndex ].hThread == ( pthread_t )xThreadId ) 718 | { 719 | pxThreads[ lIndex ].hThread = (pthread_t)NULL; 720 | pxThreads[ lIndex ].hTask = (xTaskHandle)NULL; 721 | if ( pxThreads[ lIndex ].uxCriticalNesting > 0 ) 722 | { 723 | uxCriticalNesting = 0; 724 | vPortEnableInterrupts(); 725 | } 726 | pxThreads[ lIndex ].uxCriticalNesting = 0; 727 | break; 728 | } 729 | } 730 | } 731 | /*-----------------------------------------------------------*/ 732 | 733 | void vPortAddTaskHandle( void *pxTaskHandle ) 734 | { 735 | portLONG lIndex; 736 | 737 | pxThreads[ lIndexOfLastAddedTask ].hTask = ( xTaskHandle )pxTaskHandle; 738 | for ( lIndex = 0; lIndex < MAX_NUMBER_OF_TASKS; lIndex++ ) 739 | { 740 | if ( pxThreads[ lIndex ].hThread == pxThreads[ lIndexOfLastAddedTask ].hThread ) 741 | { 742 | if ( pxThreads[ lIndex ].hTask != pxThreads[ lIndexOfLastAddedTask ].hTask ) 743 | { 744 | pxThreads[ lIndex ].hThread = ( pthread_t )NULL; 745 | pxThreads[ lIndex ].hTask = NULL; 746 | pxThreads[ lIndex ].uxCriticalNesting = 0; 747 | } 748 | } 749 | } 750 | } 751 | /*-----------------------------------------------------------*/ 752 | 753 | void vPortFindTicksPerSecond( void ) 754 | { 755 | /* Needs to be reasonably high for accuracy. */ 756 | unsigned long ulTicksPerSecond = sysconf(_SC_CLK_TCK); 757 | printf( "Timer Resolution for Run TimeStats is %ld ticks per second.\n", ulTicksPerSecond ); 758 | } 759 | /*-----------------------------------------------------------*/ 760 | 761 | unsigned long ulPortGetTimerValue( void ) 762 | { 763 | struct tms xTimes; 764 | unsigned long ulTotalTime = times( &xTimes ); 765 | /* Return the application code times. 766 | * The timer only increases when the application code is actually running 767 | * which means that the total execution times should add up to 100%. 768 | */ 769 | return ( unsigned long ) xTimes.tms_utime; 770 | 771 | /* Should check ulTotalTime for being clock_t max minus 1. */ 772 | (void)ulTotalTime; 773 | } 774 | /*-----------------------------------------------------------*/ 775 | -------------------------------------------------------------------------------- /Simulator_Linux/FreeRTOS_Kernel/portable/GCC/Posix/portmacro.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS.org V5.2.0 - Copyright (C) 2003-2009 Richard Barry. 3 | 4 | This file is part of the FreeRTOS.org distribution. 5 | 6 | FreeRTOS.org is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License (version 2) as published 8 | by the Free Software Foundation and modified by the FreeRTOS exception. 9 | 10 | FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | more details. 14 | 15 | You should have received a copy of the GNU General Public License along 16 | with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59 17 | Temple Place, Suite 330, Boston, MA 02111-1307 USA. 18 | 19 | A special exception to the GPL is included to allow you to distribute a 20 | combined work that includes FreeRTOS.org without being obliged to provide 21 | the source code for any proprietary components. See the licensing section 22 | of http://www.FreeRTOS.org for full details. 23 | 24 | 25 | *************************************************************************** 26 | * * 27 | * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation * 28 | * * 29 | * This is a concise, step by step, 'hands on' guide that describes both * 30 | * general multitasking concepts and FreeRTOS specifics. It presents and * 31 | * explains numerous examples that are written using the FreeRTOS API. * 32 | * Full source code for all the examples is provided in an accompanying * 33 | * .zip file. * 34 | * * 35 | *************************************************************************** 36 | 37 | 1 tab == 4 spaces! 38 | 39 | Please ensure to read the configuration and relevant port sections of the 40 | online documentation. 41 | 42 | http://www.FreeRTOS.org - Documentation, latest information, license and 43 | contact details. 44 | 45 | http://www.SafeRTOS.com - A version that is certified for use in safety 46 | critical systems. 47 | 48 | http://www.OpenRTOS.com - Commercial support, development, porting, 49 | licensing and training services. 50 | */ 51 | 52 | 53 | #ifndef PORTMACRO_H 54 | #define PORTMACRO_H 55 | 56 | #ifdef __cplusplus 57 | extern "C" { 58 | #endif 59 | 60 | /*----------------------------------------------------------- 61 | * Port specific definitions. 62 | * 63 | * The settings in this file configure FreeRTOS correctly for the 64 | * given hardware and compiler. 65 | * 66 | * These settings should not be altered. 67 | *----------------------------------------------------------- 68 | */ 69 | 70 | /* Type definitions. */ 71 | #define portCHAR char 72 | #define portFLOAT float 73 | #define portDOUBLE double 74 | #define portLONG int 75 | #define portSHORT short 76 | #define portSTACK_TYPE unsigned long 77 | #define portPOINTER_SIZE_TYPE unsigned long 78 | #define portBASE_TYPE long 79 | 80 | /*-----------------------------------------------------------*/ 81 | typedef portSTACK_TYPE StackType_t; 82 | typedef portBASE_TYPE BaseType_t; 83 | typedef unsigned long UBaseType_t; 84 | 85 | #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) 86 | #if( configUSE_16_BIT_TICKS == 1 ) 87 | typedef unsigned portSHORT TickType_t; 88 | #define portMAX_DELAY ( TickType_t ) 0xffff 89 | #else 90 | typedef unsigned portLONG TickType_t; 91 | #define portMAX_DELAY ( TickType_t ) 0xffffffff 92 | #endif 93 | 94 | /*-----------------------------------------------------------*/ 95 | /* 96 | #if( configUSE_16_BIT_TICKS == 1 ) 97 | typedef unsigned portSHORT portTickType; 98 | #define portMAX_DELAY ( portTickType ) 0xffff 99 | #else 100 | typedef unsigned portLONG portTickType; 101 | #define portMAX_DELAY ( portTickType ) 0xffffffff 102 | #endif 103 | */ 104 | /*-----------------------------------------------------------*/ 105 | 106 | /* Architecture specifics. */ 107 | #define portSTACK_GROWTH ( -1 ) 108 | //#define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ ) 109 | #define portTICK_RATE_MICROSECONDS ( ( portTickType ) 1000000 / configTICK_RATE_HZ ) 110 | #define portBYTE_ALIGNMENT 4 111 | #define portREMOVE_STATIC_QUALIFIER 112 | /*-----------------------------------------------------------*/ 113 | 114 | 115 | /* Scheduler utilities. */ 116 | extern void vPortYieldFromISR( void ); 117 | extern void vPortYield( void ); 118 | 119 | #define portYIELD() vPortYield() 120 | 121 | #define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired ) vPortYieldFromISR() 122 | /*-----------------------------------------------------------*/ 123 | 124 | 125 | /* Critical section management. */ 126 | extern void vPortDisableInterrupts( void ); 127 | extern void vPortEnableInterrupts( void ); 128 | #define portSET_INTERRUPT_MASK() ( vPortDisableInterrupts() ) 129 | #define portCLEAR_INTERRUPT_MASK() ( vPortEnableInterrupts() ) 130 | 131 | extern portBASE_TYPE xPortSetInterruptMask( void ); 132 | extern void vPortClearInterruptMask( portBASE_TYPE xMask ); 133 | 134 | #define portSET_INTERRUPT_MASK_FROM_ISR() xPortSetInterruptMask() 135 | #define portCLEAR_INTERRUPT_MASK_FROM_ISR(x) vPortClearInterruptMask(x) 136 | 137 | 138 | extern void vPortEnterCritical( void ); 139 | extern void vPortExitCritical( void ); 140 | 141 | #define portDISABLE_INTERRUPTS() portSET_INTERRUPT_MASK() 142 | #define portENABLE_INTERRUPTS() portCLEAR_INTERRUPT_MASK() 143 | #define portENTER_CRITICAL() vPortEnterCritical() 144 | #define portEXIT_CRITICAL() vPortExitCritical() 145 | /*-----------------------------------------------------------*/ 146 | 147 | /* Task function macros as described on the FreeRTOS.org WEB site. */ 148 | #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) 149 | #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) 150 | 151 | #define portNOP() 152 | 153 | #define portOUTPUT_BYTE( a, b ) 154 | 155 | extern void vPortForciblyEndThread( void *pxTaskToDelete ); 156 | #define traceTASK_DELETE( pxTaskToDelete ) vPortForciblyEndThread( pxTaskToDelete ) 157 | 158 | extern void vPortAddTaskHandle( void *pxTaskHandle ); 159 | #define traceTASK_CREATE( pxNewTCB ) vPortAddTaskHandle( pxNewTCB ) 160 | 161 | /* Posix Signal definitions that can be changed or read as appropriate. */ 162 | #define SIG_SUSPEND SIGUSR1 163 | #define SIG_RESUME SIGUSR2 164 | 165 | /* Enable the following hash defines to make use of the real-time tick where time progresses at real-time. */ 166 | #define SIG_TICK SIGALRM 167 | #define TIMER_TYPE ITIMER_REAL 168 | /* Enable the following hash defines to make use of the process tick where time progresses only when the process is executing. 169 | #define SIG_TICK SIGVTALRM 170 | #define TIMER_TYPE ITIMER_VIRTUAL */ 171 | /* Enable the following hash defines to make use of the profile tick where time progresses when the process or system calls are executing. 172 | #define SIG_TICK SIGPROF 173 | #define TIMER_TYPE ITIMER_PROF */ 174 | 175 | /* Make use of times(man 2) to gather run-time statistics on the tasks. */ 176 | extern void vPortFindTicksPerSecond( void ); 177 | #define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vPortFindTicksPerSecond() /* Nothing to do because the timer is already present. */ 178 | extern unsigned long ulPortGetTimerValue( void ); 179 | #define portGET_RUN_TIME_COUNTER_VALUE() ulPortGetTimerValue() /* Query the System time stats for this process. */ 180 | 181 | #ifdef __cplusplus 182 | } 183 | #endif 184 | 185 | #endif /* PORTMACRO_H */ 186 | 187 | -------------------------------------------------------------------------------- /Simulator_Linux/FreeRTOS_Kernel/portable/MemMang/heap_3.c: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V6.0.4 - Copyright (C) 2010 Real Time Engineers Ltd. 3 | 4 | *************************************************************************** 5 | * * 6 | * If you are: * 7 | * * 8 | * + New to FreeRTOS, * 9 | * + Wanting to learn FreeRTOS or multitasking in general quickly * 10 | * + Looking for basic training, * 11 | * + Wanting to improve your FreeRTOS skills and productivity * 12 | * * 13 | * then take a look at the FreeRTOS eBook * 14 | * * 15 | * "Using the FreeRTOS Real Time Kernel - a Practical Guide" * 16 | * http://www.FreeRTOS.org/Documentation * 17 | * * 18 | * A pdf reference manual is also available. Both are usually delivered * 19 | * to your inbox within 20 minutes to two hours when purchased between 8am * 20 | * and 8pm GMT (although please allow up to 24 hours in case of * 21 | * exceptional circumstances). Thank you for your support! * 22 | * * 23 | *************************************************************************** 24 | 25 | This file is part of the FreeRTOS distribution. 26 | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under 28 | the terms of the GNU General Public License (version 2) as published by the 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | ***NOTE*** The exception to the GPL is included to allow you to distribute 31 | a combined work that includes FreeRTOS without being obliged to provide the 32 | source code for proprietary components outside of the FreeRTOS kernel. 33 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT 34 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 35 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | more details. You should have received a copy of the GNU General Public 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | by writing to Richard Barry, contact details for whom are available on the 40 | FreeRTOS WEB site. 41 | 42 | 1 tab == 4 spaces! 43 | 44 | http://www.FreeRTOS.org - Documentation, latest information, license and 45 | contact details. 46 | 47 | http://www.SafeRTOS.com - A version that is certified for use in safety 48 | critical systems. 49 | 50 | http://www.OpenRTOS.com - Commercial support, development, porting, 51 | licensing and training services. 52 | */ 53 | 54 | 55 | /* 56 | * Implementation of pvPortMalloc() and vPortFree() that relies on the 57 | * compilers own malloc() and free() implementations. 58 | * 59 | * This file can only be used if the linker is configured to to generate 60 | * a heap memory area. 61 | * 62 | * See heap_2.c and heap_1.c for alternative implementations, and the memory 63 | * management pages of http://www.FreeRTOS.org for more information. 64 | */ 65 | 66 | #include 67 | 68 | /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining 69 | all the API functions to use the MPU wrappers. That should only be done when 70 | task.h is included from an application file. */ 71 | #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE 72 | 73 | #include "FreeRTOS.h" 74 | #include "task.h" 75 | 76 | #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE 77 | 78 | /*-----------------------------------------------------------*/ 79 | 80 | void *pvPortMalloc( size_t xWantedSize ) 81 | { 82 | void *pvReturn; 83 | 84 | vTaskSuspendAll(); 85 | { 86 | pvReturn = malloc( xWantedSize ); 87 | } 88 | xTaskResumeAll(); 89 | 90 | #if( configUSE_MALLOC_FAILED_HOOK == 1 ) 91 | { 92 | if( pvReturn == NULL ) 93 | { 94 | extern void vApplicationMallocFailedHook( void ); 95 | vApplicationMallocFailedHook(); 96 | } 97 | } 98 | #endif 99 | 100 | return pvReturn; 101 | } 102 | /*-----------------------------------------------------------*/ 103 | 104 | void vPortFree( void *pv ) 105 | { 106 | if( pv ) 107 | { 108 | vTaskSuspendAll(); 109 | { 110 | free( pv ); 111 | } 112 | xTaskResumeAll(); 113 | } 114 | } 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /Simulator_Linux/FreeRTOS_Kernel/portable/readme.txt: -------------------------------------------------------------------------------- 1 | Each real time kernel port consists of three files that contain the core kernel 2 | components and are common to every port, and one or more files that are 3 | specific to a particular microcontroller and/or compiler. 4 | 5 | 6 | + The FreeRTOS/Source/Portable/MemMang directory contains the three sample 7 | memory allocators as described on the http://www.FreeRTOS.org WEB site. 8 | 9 | + The other directories each contain files specific to a particular 10 | microcontroller or compiler. 11 | 12 | 13 | 14 | For example, if you are interested in the GCC port for the ATMega323 15 | microcontroller then the port specific files are contained in 16 | FreeRTOS/Source/Portable/GCC/ATMega323 directory. If this is the only 17 | port you are interested in then all the other directories can be 18 | ignored. 19 | 20 | -------------------------------------------------------------------------------- /Simulator_Linux/FreeRTOS_Kernel/subdir.mk: -------------------------------------------------------------------------------- 1 | C_SRCS += \ 2 | $(PROJ_ROOT)/FreeRTOS_Kernel/croutine.c \ 3 | $(PROJ_ROOT)/FreeRTOS_Kernel/list.c \ 4 | $(PROJ_ROOT)/FreeRTOS_Kernel/queue.c \ 5 | $(PROJ_ROOT)/FreeRTOS_Kernel/tasks.c \ 6 | $(PROJ_ROOT)/FreeRTOS_Kernel/portable/GCC/Posix/port.c \ 7 | $(PROJ_ROOT)/FreeRTOS_Kernel/portable/MemMang/heap_3.c 8 | 9 | OBJS += \ 10 | $(BUILD_TMP)/croutine.o \ 11 | $(BUILD_TMP)/list.o \ 12 | $(BUILD_TMP)/queue.o \ 13 | $(BUILD_TMP)/tasks.o \ 14 | $(BUILD_TMP)/port.o \ 15 | $(BUILD_TMP)/heap_3.o 16 | 17 | C_DEPS += \ 18 | $(BUILD_TMP)/croutine.d \ 19 | $(BUILD_TMP)/list.d \ 20 | $(BUILD_TMP)/queue.d \ 21 | $(BUILD_TMP)/tasks.d \ 22 | $(BUILD_TMP)/port.d \ 23 | $(BUILD_TMP)/heap_3.d 24 | 25 | $(BUILD_TMP)/%.o: $(PROJ_ROOT)/FreeRTOS_Kernel/%.c 26 | @echo 'Building file: $<' 27 | gcc -DUSE_STDIO=1 -D__GCC_POSIX__=1 $(TARGET_INC) -O2 -Wall -c -fmessage-length=0 -pthread -lrt -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<" 28 | @echo 'Finished building: $<' 29 | @echo ' ' 30 | 31 | $(BUILD_TMP)/%.o: $(PROJ_ROOT)/FreeRTOS_Kernel/portable/GCC/Posix/%.c 32 | @echo 'Building file: $<' 33 | gcc -DUSE_STDIO=1 -D__GCC_POSIX__=1 $(TARGET_INC) -O2 -Wall -c -fmessage-length=0 -pthread -lrt -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<" 34 | @echo 'Finished building: $<' 35 | @echo ' ' 36 | 37 | $(BUILD_TMP)/%.o: $(PROJ_ROOT)/FreeRTOS_Kernel/portable/MemMang/%.c 38 | @echo 'Building file: $<' 39 | gcc -DUSE_STDIO=1 -D__GCC_POSIX__=1 $(TARGET_INC) -O2 -Wall -c -fmessage-length=0 -pthread -lrt -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<" 40 | @echo 'Finished building: $<' 41 | @echo ' ' -------------------------------------------------------------------------------- /Simulator_Linux/Makefile: -------------------------------------------------------------------------------- 1 | RM := rm -rf 2 | 3 | PROJ_ROOT :=. 4 | BUILD_TMP :=$(PROJ_ROOT)/tmp 5 | TARGET_INC := -I$(PROJ_ROOT)/inc \ 6 | -I$(PROJ_ROOT)/FreeRTOS_Kernel/include \ 7 | -I$(PROJ_ROOT)/FreeRTOS_Kernel/portable/GCC/Posix 8 | 9 | -include subdir.mk 10 | -include FreeRTOS_Kernel/subdir.mk 11 | 12 | ifneq ($(MAKECMDGOALS),clean) 13 | ifneq ($(strip $(C_DEPS)),) 14 | -include $(C_DEPS) 15 | endif 16 | endif 17 | 18 | all:simulator_linux.bin 19 | 20 | simulator_linux.bin: $(OBJS) 21 | @echo 'Building target: $@' 22 | gcc -pthread -lrt -o"simulator_linux.bin" $(OBJS) $(LIBS) 23 | @echo 'Finished building target: $@' 24 | @echo ' ' 25 | 26 | clean: 27 | -$(RM) $(OBJS)$(C_DEPS)$(EXECUTABLES) simulator_linux.bin 28 | -@echo ' ' 29 | 30 | .PHONY: all clean dependents 31 | .SECONDARY: -------------------------------------------------------------------------------- /Simulator_Linux/SConstruct: -------------------------------------------------------------------------------- 1 | 2 | obj = Object([ 3 | './FreeRTOS_Kernel/croutine.c', 4 | './FreeRTOS_Kernel/list.c', 5 | './FreeRTOS_Kernel/queue.c', 6 | './FreeRTOS_Kernel/tasks.c', 7 | './FreeRTOS_Kernel/portable/GCC/Posix/port.c', 8 | './FreeRTOS_Kernel/portable/MemMang/heap_3.c', 9 | './src/main.c' 10 | ], 11 | CCFLAGS= '-DUSE_STDIO=1 -D__GCC_POSIX__=1', 12 | CPPPATH = 13 | ['./inc', './FreeRTOS_Kernel/include', './FreeRTOS_Kernel/portable/GCC/Posix'] 14 | ) 15 | 16 | Program('simulator_linux.bin', obj, LIBS=['pthread']) 17 | 18 | -------------------------------------------------------------------------------- /Simulator_Linux/inc/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS.org V5.4.2 - Copyright (C) 2003-2009 Richard Barry. 3 | 4 | This file is part of the FreeRTOS.org distribution. 5 | 6 | FreeRTOS.org is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License (version 2) as published 8 | by the Free Software Foundation and modified by the FreeRTOS exception. 9 | 10 | FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | more details. 14 | 15 | You should have received a copy of the GNU General Public License along 16 | with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59 17 | Temple Place, Suite 330, Boston, MA 02111-1307 USA. 18 | 19 | A special exception to the GPL is included to allow you to distribute a 20 | combined work that includes FreeRTOS.org without being obliged to provide 21 | the source code for any proprietary components. See the licensing section 22 | of http://www.FreeRTOS.org for full details. 23 | 24 | 25 | *************************************************************************** 26 | * * 27 | * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation * 28 | * * 29 | * This is a concise, step by step, 'hands on' guide that describes both * 30 | * general multitasking concepts and FreeRTOS specifics. It presents and * 31 | * explains numerous examples that are written using the FreeRTOS API. * 32 | * Full source code for all the examples is provided in an accompanying * 33 | * .zip file. * 34 | * * 35 | *************************************************************************** 36 | 37 | 1 tab == 4 spaces! 38 | 39 | Please ensure to read the configuration and relevant port sections of the 40 | online documentation. 41 | 42 | http://www.FreeRTOS.org - Documentation, latest information, license and 43 | contact details. 44 | 45 | http://www.SafeRTOS.com - A version that is certified for use in safety 46 | critical systems. 47 | 48 | http://www.OpenRTOS.com - Commercial support, development, porting, 49 | licensing and training services. 50 | */ 51 | 52 | #ifndef FREERTOS_CONFIG_H 53 | #define FREERTOS_CONFIG_H 54 | 55 | /*----------------------------------------------------------- 56 | * Application specific definitions. 57 | * 58 | * These definitions should be adjusted for your particular hardware and 59 | * application requirements. 60 | * 61 | * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE 62 | * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. 63 | * 64 | * See http://www.freertos.org/a00110.html. 65 | *----------------------------------------------------------*/ 66 | 67 | #define configUSE_PREEMPTION 1 68 | #define configUSE_IDLE_HOOK 1 69 | #define configUSE_TICK_HOOK 0 70 | #define configTICK_RATE_HZ ( ( portTickType ) 1000 ) 71 | #define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 4 ) /* This can be made smaller if required. */ 72 | #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 32 * 1024 ) ) 73 | #define configMAX_TASK_NAME_LEN ( 16 ) 74 | #define configUSE_TRACE_FACILITY 1 75 | #define configUSE_16_BIT_TICKS 0 76 | #define configIDLE_SHOULD_YIELD 1 77 | #define configUSE_CO_ROUTINES 1 78 | #define configUSE_MUTEXES 1 79 | #define configUSE_COUNTING_SEMAPHORES 1 80 | #define configUSE_ALTERNATIVE_API 0 81 | #define configUSE_RECURSIVE_MUTEXES 1 82 | #define configCHECK_FOR_STACK_OVERFLOW 0 /* Do not use this option on the PC port. */ 83 | #define configUSE_APPLICATION_TASK_TAG 1 84 | #define configQUEUE_REGISTRY_SIZE 0 85 | #define configMAX_SYSCALL_INTERRUPT_PRIORITY 1 86 | 87 | #define configMAX_PRIORITIES ( 10 ) 88 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 89 | 90 | /* Set the following definitions to 1 to include the API function, or zero 91 | to exclude the API function. */ 92 | 93 | #define INCLUDE_vTaskPrioritySet 1 94 | #define INCLUDE_uxTaskPriorityGet 1 95 | #define INCLUDE_vTaskDelete 1 96 | #define INCLUDE_vTaskCleanUpResources 1 97 | #define INCLUDE_vTaskSuspend 1 98 | #define INCLUDE_vTaskDelayUntil 1 99 | #define INCLUDE_vTaskDelay 1 100 | #define INCLUDE_uxTaskGetStackHighWaterMark 0 /* Do not use this option on the PC port. */ 101 | #define INCLUDE_xTaskGetSchedulerState 1 102 | 103 | extern void vMainQueueSendPassed( void ); 104 | #define traceQUEUE_SEND( pxQueue ) vMainQueueSendPassed() 105 | 106 | #define configGENERATE_RUN_TIME_STATS 1 107 | 108 | #endif /* FREERTOS_CONFIG_H */ 109 | -------------------------------------------------------------------------------- /Simulator_Linux/inc/main.h: -------------------------------------------------------------------------------- 1 | #define MAIN_VAL 5 -------------------------------------------------------------------------------- /Simulator_Linux/src/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "main.h" 4 | 5 | #include "FreeRTOS.h" 6 | #include "task.h" 7 | #include "queue.h" 8 | 9 | static void vTask1( void *pvParameters ); 10 | static void vTask2( void *pvParameters ); 11 | static volatile unsigned short usTaskCheck[ 2 ] = { ( unsigned short ) 0 }; 12 | 13 | int main() 14 | { 15 | static xQueueHandle xTestQueue; 16 | xTestQueue = xQueueCreate( 10, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) ); 17 | xTaskCreate( vTask1, "vTask1", configMINIMAL_STACK_SIZE, ( void * ) &xTestQueue, tskIDLE_PRIORITY, NULL ); 18 | xTaskCreate( vTask2, "vTask2", configMINIMAL_STACK_SIZE, ( void * ) &xTestQueue, tskIDLE_PRIORITY, NULL ); 19 | 20 | vTaskStartScheduler(); 21 | return 1; 22 | } 23 | 24 | static void vTask1( void *pvParameters ) 25 | { 26 | unsigned short usValue = 0, usLoop; 27 | xQueueHandle *pxQueue; 28 | const unsigned short usNumToProduce = 3; 29 | short sError = pdFALSE; 30 | 31 | pxQueue = ( xQueueHandle * ) pvParameters; 32 | 33 | for( ;; ) 34 | { 35 | for( usLoop = 0; usLoop < usNumToProduce; ++usLoop ) 36 | { 37 | /* Send an incrementing number on the queue without blocking. */ 38 | printf("Task1 will send: %d\r\n", usValue); 39 | if( xQueueSendToBack( *pxQueue, ( void * ) &usValue, ( portTickType ) 0 ) != pdPASS ) 40 | { 41 | sError = pdTRUE; 42 | } 43 | else 44 | { 45 | ++usValue; 46 | } 47 | } 48 | vTaskDelay( 2000 ); 49 | } 50 | } 51 | static void vTask2( void *pvParameters ) 52 | { 53 | unsigned short usData = 0; 54 | xQueueHandle *pxQueue; 55 | 56 | pxQueue = ( xQueueHandle * ) pvParameters; 57 | 58 | for( ;; ) 59 | { 60 | while( uxQueueMessagesWaiting( *pxQueue ) ) 61 | { 62 | if( xQueueReceive( *pxQueue, &usData, ( portTickType ) 0 ) == pdPASS ) 63 | { 64 | printf("Task2 received:%d\r\n", usData); 65 | } 66 | } 67 | vTaskDelay( 5000 ); 68 | } 69 | } 70 | 71 | /********************************************************/ 72 | /* This is a stub function for FreeRTOS_Kernel */ 73 | void vMainQueueSendPassed( void ) 74 | { 75 | return; 76 | } 77 | 78 | /* This is a stub function for FreeRTOS_Kernel */ 79 | void vApplicationIdleHook( void ) 80 | { 81 | return; 82 | } -------------------------------------------------------------------------------- /Simulator_Linux/subdir.mk: -------------------------------------------------------------------------------- 1 | C_SRCS += \ 2 | $(PROJ_ROOT)/src/main.c 3 | 4 | OBJS += \ 5 | $(BUILD_TMP)/main.o 6 | 7 | C_DEPS += \ 8 | $(BUILD_TMP)/main.d 9 | 10 | # Each subdirectory must supply rules for building sources it contributes 11 | $(BUILD_TMP)/%.o: $(PROJ_ROOT)/src/%.c 12 | @echo 'Building file: $<' 13 | gcc -DUSE_STDIO=1 -D__GCC_POSIX__=1 $(TARGET_INC) -O2 -Wall -c -fmessage-length=0 -pthread -lrt -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<" 14 | @echo 'Finished building: $<' 15 | @echo ' ' --------------------------------------------------------------------------------