task.h
1 /* 2 * FreeRTOS Kernel V10.2.1 3 * Copyright (C) 2019 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. 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, FITNESS 17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * http://www.FreeRTOS.org 23 * http://aws.amazon.com/freertos 24 * 25 * 1 tab == 4 spaces! 26 */ 27 28 29 #ifndef INC_TASK_H 30 #define INC_TASK_H 31 32 #ifndef INC_FREERTOS_H 33 #error "include FreeRTOS.h must appear in source files before include task.h" 34 #endif 35 36 #include "list.h" 37 #include "freertos/portmacro.h" 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 /*----------------------------------------------------------- 44 * MACROS AND DEFINITIONS 45 *----------------------------------------------------------*/ 46 47 #define tskKERNEL_VERSION_NUMBER "V10.2.1" 48 #define tskKERNEL_VERSION_MAJOR 10 49 #define tskKERNEL_VERSION_MINOR 2 50 #define tskKERNEL_VERSION_BUILD 1 51 52 /* MPU region parameters passed in ulParameters 53 * of MemoryRegion_t struct. */ 54 #define tskMPU_REGION_READ_ONLY ( 1UL << 0UL ) 55 #define tskMPU_REGION_READ_WRITE ( 1UL << 1UL ) 56 #define tskMPU_REGION_EXECUTE_NEVER ( 1UL << 2UL ) 57 #define tskMPU_REGION_NORMAL_MEMORY ( 1UL << 3UL ) 58 #define tskMPU_REGION_DEVICE_MEMORY ( 1UL << 4UL ) 59 60 #define tskNO_AFFINITY ( 0x7FFFFFFF ) 61 /** 62 * Type by which tasks are referenced. For example, a call to xTaskCreate 63 * returns (via a pointer parameter) an TaskHandle_t variable that can then 64 * be used as a parameter to vTaskDelete to delete the task. 65 * 66 * \ingroup Tasks 67 */ 68 struct tskTaskControlBlock; /* The old naming convention is used to prevent breaking kernel aware debuggers. */ 69 //typedef struct tskTaskControlBlock* TaskHandle_t; 70 typedef void* TaskHandle_t; 71 /** 72 * Defines the prototype to which the application task hook function must 73 * conform. 74 */ 75 typedef BaseType_t (*TaskHookFunction_t)( void * ); 76 77 /** Task states returned by eTaskGetState. */ 78 typedef enum 79 { 80 eRunning = 0, /* A task is querying the state of itself, so must be running. */ 81 eReady, /* The task being queried is in a read or pending ready list. */ 82 eBlocked, /* The task being queried is in the Blocked state. */ 83 eSuspended, /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */ 84 eDeleted, /* The task being queried has been deleted, but its TCB has not yet been freed. */ 85 eInvalid /* Used as an 'invalid state' value. */ 86 } eTaskState; 87 88 /* Actions that can be performed when vTaskNotify() is called. */ 89 typedef enum 90 { 91 eNoAction = 0, /* Notify the task without updating its notify value. */ 92 eSetBits, /* Set bits in the task's notification value. */ 93 eIncrement, /* Increment the task's notification value. */ 94 eSetValueWithOverwrite, /* Set the task's notification value to a specific value even if the previous value has not yet been read by the task. */ 95 eSetValueWithoutOverwrite /* Set the task's notification value if the previous value has been read by the task. */ 96 } eNotifyAction; 97 98 /** @cond */ 99 /** 100 * Used internally only. 101 */ 102 typedef struct xTIME_OUT 103 { 104 BaseType_t xOverflowCount; 105 TickType_t xTimeOnEntering; 106 } TimeOut_t; 107 108 /** 109 * Defines the memory ranges allocated to the task when an MPU is used. 110 */ 111 typedef struct xMEMORY_REGION 112 { 113 void *pvBaseAddress; 114 uint32_t ulLengthInBytes; 115 uint32_t ulParameters; 116 } MemoryRegion_t; 117 118 /* 119 * Parameters required to create an MPU protected task. 120 */ 121 typedef struct xTASK_PARAMETERS 122 { 123 TaskFunction_t pvTaskCode; 124 const char * const pcName; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ 125 configSTACK_DEPTH_TYPE usStackDepth; 126 void *pvParameters; 127 UBaseType_t uxPriority; 128 StackType_t *puxStackBuffer; 129 MemoryRegion_t xRegions[ portNUM_CONFIGURABLE_REGIONS ]; 130 #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) 131 StaticTask_t * const pxTaskBuffer; 132 #endif 133 } TaskParameters_t; 134 135 136 /* 137 * Used with the uxTaskGetSystemState() function to return the state of each task in the system. 138 */ 139 typedef struct xTASK_STATUS 140 { 141 TaskHandle_t xHandle; /* The handle of the task to which the rest of the information in the structure relates. */ 142 const char *pcTaskName; /* A pointer to the task's name. This value will be invalid if the task was deleted since the structure was populated! */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ 143 UBaseType_t xTaskNumber; /* A number unique to the task. */ 144 eTaskState eCurrentState; /* The state in which the task existed when the structure was populated. */ 145 UBaseType_t uxCurrentPriority; /* The priority at which the task was running (may be inherited) when the structure was populated. */ 146 UBaseType_t uxBasePriority; /* The priority to which the task will return if the task's current priority has been inherited to avoid unbounded priority inversion when obtaining a mutex. Only valid if configUSE_MUTEXES is defined as 1 in FreeRTOSConfig.h. */ 147 uint32_t ulRunTimeCounter; /* The total run time allocated to the task so far, as defined by the run time stats clock. See http://www.freertos.org/rtos-run-time-stats.html. Only valid when configGENERATE_RUN_TIME_STATS is defined as 1 in FreeRTOSConfig.h. */ 148 StackType_t *pxStackBase; /* Points to the lowest address of the task's stack area. */ 149 configSTACK_DEPTH_TYPE usStackHighWaterMark; /* The minimum amount of stack space that has remained for the task since the task was created. The closer this value is to zero the closer the task has come to overflowing its stack. */ 150 #if configTASKLIST_INCLUDE_COREID 151 BaseType_t xCoreID; /*!< Core this task is pinned to (0, 1, or -1 for tskNO_AFFINITY). This field is present if CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID is set. */ 152 #endif 153 } TaskStatus_t; 154 155 /** 156 * Used with the uxTaskGetSnapshotAll() function to save memory snapshot of each task in the system. 157 * We need this struct because TCB_t is defined (hidden) in tasks.c. 158 */ 159 typedef struct xTASK_SNAPSHOT 160 { 161 void *pxTCB; /*!< Address of task control block. */ 162 StackType_t *pxTopOfStack; /*!< Points to the location of the last item placed on the tasks stack. */ 163 StackType_t *pxEndOfStack; /*!< Points to the end of the stack. pxTopOfStack < pxEndOfStack, stack grows hi2lo 164 pxTopOfStack > pxEndOfStack, stack grows lo2hi*/ 165 } TaskSnapshot_t; 166 167 /** @endcond */ 168 169 /** 170 * Possible return values for eTaskConfirmSleepModeStatus(). 171 */ 172 typedef enum 173 { 174 eAbortSleep = 0, /* A task has been made ready or a context switch pended since portSUPPORESS_TICKS_AND_SLEEP() was called - abort entering a sleep mode. */ 175 eStandardSleep, /* Enter a sleep mode that will not last any longer than the expected idle time. */ 176 eNoTasksWaitingTimeout /* No tasks are waiting for a timeout so it is safe to enter a sleep mode that can only be exited by an external interrupt. */ 177 } eSleepModeStatus; 178 179 /** 180 * Defines the priority used by the idle task. This must not be modified. 181 * 182 * \ingroup TaskUtils 183 */ 184 #define tskIDLE_PRIORITY ( ( UBaseType_t ) 0U ) 185 186 /** 187 * Macro for forcing a context switch. 188 * 189 * \ingroup SchedulerControl 190 */ 191 #define taskYIELD() portYIELD() 192 193 /** 194 * Macro to mark the start of a critical code region. Preemptive context 195 * switches cannot occur when in a critical region. 196 * 197 * @note This may alter the stack (depending on the portable implementation) 198 * so must be used with care! 199 * 200 * \ingroup SchedulerControl 201 */ 202 #define taskENTER_CRITICAL( x ) portENTER_CRITICAL( x ) 203 #define taskENTER_CRITICAL_FROM_ISR( ) portSET_INTERRUPT_MASK_FROM_ISR() 204 #define taskENTER_CRITICAL_ISR(mux) portENTER_CRITICAL_ISR(mux) 205 206 /** 207 * Macro to mark the end of a critical code region. Preemptive context 208 * switches cannot occur when in a critical region. 209 * 210 * @note This may alter the stack (depending on the portable implementation) 211 * so must be used with care! 212 * 213 * \ingroup SchedulerControl 214 */ 215 #define taskEXIT_CRITICAL( x ) portEXIT_CRITICAL( x ) 216 #define taskEXIT_CRITICAL_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( x ) 217 #define taskEXIT_CRITICAL_ISR(mux) portEXIT_CRITICAL_ISR(mux) 218 219 /** 220 * Macro to disable all maskable interrupts. 221 * 222 * \ingroup SchedulerControl 223 */ 224 #define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS() 225 226 /** 227 * Macro to enable microcontroller interrupts. 228 * 229 * \ingroup SchedulerControl 230 */ 231 #define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS() 232 233 /* Definitions returned by xTaskGetSchedulerState(). taskSCHEDULER_SUSPENDED is 234 0 to generate more optimal code when configASSERT() is defined as the constant 235 is used in assert() statements. */ 236 #define taskSCHEDULER_SUSPENDED ( ( BaseType_t ) 0 ) 237 #define taskSCHEDULER_NOT_STARTED ( ( BaseType_t ) 1 ) 238 #define taskSCHEDULER_RUNNING ( ( BaseType_t ) 2 ) 239 240 241 /*----------------------------------------------------------- 242 * TASK CREATION API 243 *----------------------------------------------------------*/ 244 245 /** 246 * Create a new task with a specified affinity. 247 * 248 * This function is similar to xTaskCreate, but allows setting task affinity 249 * in SMP system. 250 * 251 * @param pvTaskCode Pointer to the task entry function. Tasks 252 * must be implemented to never return (i.e. continuous loop). 253 * 254 * @param pcName A descriptive name for the task. This is mainly used to 255 * facilitate debugging. Max length defined by configMAX_TASK_NAME_LEN - default 256 * is 16. 257 * 258 * @param usStackDepth The size of the task stack specified as the number of 259 * bytes. Note that this differs from vanilla FreeRTOS. 260 * 261 * @param pvParameters Pointer that will be used as the parameter for the task 262 * being created. 263 * 264 * @param uxPriority The priority at which the task should run. Systems that 265 * include MPU support can optionally create tasks in a privileged (system) 266 * mode by setting bit portPRIVILEGE_BIT of the priority parameter. For 267 * example, to create a privileged task at priority 2 the uxPriority parameter 268 * should be set to ( 2 | portPRIVILEGE_BIT ). 269 * 270 * @param pvCreatedTask Used to pass back a handle by which the created task 271 * can be referenced. 272 * 273 * @param xCoreID If the value is tskNO_AFFINITY, the created task is not 274 * pinned to any CPU, and the scheduler can run it on any core available. 275 * Values 0 or 1 indicate the index number of the CPU which the task should 276 * be pinned to. Specifying values larger than (portNUM_PROCESSORS - 1) will 277 * cause the function to fail. 278 * 279 * @return pdPASS if the task was successfully created and added to a ready 280 * list, otherwise an error code defined in the file projdefs.h 281 * 282 * \ingroup Tasks 283 */ 284 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) 285 BaseType_t xTaskCreatePinnedToCore( TaskFunction_t pvTaskCode, 286 const char * const pcName, 287 const uint32_t usStackDepth, 288 void * const pvParameters, 289 UBaseType_t uxPriority, 290 TaskHandle_t * const pvCreatedTask, 291 const BaseType_t xCoreID); 292 293 #endif 294 295 /** 296 * Create a new task and add it to the list of tasks that are ready to run. 297 * 298 * Internally, within the FreeRTOS implementation, tasks use two blocks of 299 * memory. The first block is used to hold the task's data structures. The 300 * second block is used by the task as its stack. If a task is created using 301 * xTaskCreate() then both blocks of memory are automatically dynamically 302 * allocated inside the xTaskCreate() function. (see 303 * http://www.freertos.org/a00111.html). If a task is created using 304 * xTaskCreateStatic() then the application writer must provide the required 305 * memory. xTaskCreateStatic() therefore allows a task to be created without 306 * using any dynamic memory allocation. 307 * 308 * See xTaskCreateStatic() for a version that does not use any dynamic memory 309 * allocation. 310 * 311 * xTaskCreate() can only be used to create a task that has unrestricted 312 * access to the entire microcontroller memory map. Systems that include MPU 313 * support can alternatively create an MPU constrained task using 314 * xTaskCreateRestricted(). 315 * 316 * @param pvTaskCode Pointer to the task entry function. Tasks 317 * must be implemented to never return (i.e. continuous loop). 318 * 319 * @param pcName A descriptive name for the task. This is mainly used to 320 * facilitate debugging. Max length defined by configMAX_TASK_NAME_LEN - default 321 * is 16. 322 * 323 * @param usStackDepth The size of the task stack specified as the number of 324 * bytes. Note that this differs from vanilla FreeRTOS. 325 * 326 * @param pvParameters Pointer that will be used as the parameter for the task 327 * being created. 328 * 329 * @param uxPriority The priority at which the task should run. Systems that 330 * include MPU support can optionally create tasks in a privileged (system) 331 * mode by setting bit portPRIVILEGE_BIT of the priority parameter. For 332 * example, to create a privileged task at priority 2 the uxPriority parameter 333 * should be set to ( 2 | portPRIVILEGE_BIT ). 334 * 335 * @param pvCreatedTask Used to pass back a handle by which the created task 336 * can be referenced. 337 * 338 * @return pdPASS if the task was successfully created and added to a ready 339 * list, otherwise an error code defined in the file projdefs.h 340 * 341 * @note If program uses thread local variables (ones specified with "__thread" keyword) 342 * then storage for them will be allocated on the task's stack. 343 * 344 * Example usage: 345 * @code{c} 346 * // Task to be created. 347 * void vTaskCode( void * pvParameters ) 348 * { 349 * for( ;; ) 350 * { 351 * // Task code goes here. 352 * } 353 * } 354 * 355 * // Function that creates a task. 356 * void vOtherFunction( void ) 357 * { 358 * static uint8_t ucParameterToPass; 359 * TaskHandle_t xHandle = NULL; 360 * 361 * // Create the task, storing the handle. Note that the passed parameter ucParameterToPass 362 * // must exist for the lifetime of the task, so in this case is declared static. If it was just an 363 * // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time 364 * // the new task attempts to access it. 365 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle ); 366 * configASSERT( xHandle ); 367 * 368 * // Use the handle to delete the task. 369 * if( xHandle != NULL ) 370 * { 371 * vTaskDelete( xHandle ); 372 * } 373 * } 374 * @endcode 375 * \ingroup Tasks 376 */ 377 378 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) 379 380 static inline IRAM_ATTR BaseType_t xTaskCreate( 381 TaskFunction_t pvTaskCode, 382 const char * const pcName, 383 const uint32_t usStackDepth, 384 void * const pvParameters, 385 UBaseType_t uxPriority, 386 TaskHandle_t * const pvCreatedTask) 387 { 388 return xTaskCreatePinnedToCore( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pvCreatedTask, tskNO_AFFINITY ); 389 } 390 391 #endif 392 393 394 395 396 /** 397 * Create a new task with a specified affinity. 398 * 399 * This function is similar to xTaskCreateStatic, but allows specifying 400 * task affinity in an SMP system. 401 * 402 * @param pvTaskCode Pointer to the task entry function. Tasks 403 * must be implemented to never return (i.e. continuous loop). 404 * 405 * @param pcName A descriptive name for the task. This is mainly used to 406 * facilitate debugging. The maximum length of the string is defined by 407 * configMAX_TASK_NAME_LEN in FreeRTOSConfig.h. 408 * 409 * @param ulStackDepth The size of the task stack specified as the number of 410 * bytes. Note that this differs from vanilla FreeRTOS. 411 * 412 * @param pvParameters Pointer that will be used as the parameter for the task 413 * being created. 414 * 415 * @param uxPriority The priority at which the task will run. 416 * 417 * @param pxStackBuffer Must point to a StackType_t array that has at least 418 * ulStackDepth indexes - the array will then be used as the task's stack, 419 * removing the need for the stack to be allocated dynamically. 420 * 421 * @param pxTaskBuffer Must point to a variable of type StaticTask_t, which will 422 * then be used to hold the task's data structures, removing the need for the 423 * memory to be allocated dynamically. 424 * 425 * @param xCoreID If the value is tskNO_AFFINITY, the created task is not 426 * pinned to any CPU, and the scheduler can run it on any core available. 427 * Values 0 or 1 indicate the index number of the CPU which the task should 428 * be pinned to. Specifying values larger than (portNUM_PROCESSORS - 1) will 429 * cause the function to fail. 430 * 431 * @return If neither pxStackBuffer or pxTaskBuffer are NULL, then the task will 432 * be created and pdPASS is returned. If either pxStackBuffer or pxTaskBuffer 433 * are NULL then the task will not be created and 434 * errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY is returned. 435 * 436 * \ingroup Tasks 437 */ 438 #if( configSUPPORT_STATIC_ALLOCATION == 1 ) 439 TaskHandle_t xTaskCreateStaticPinnedToCore( TaskFunction_t pvTaskCode, 440 const char * const pcName, 441 const uint32_t ulStackDepth, 442 void * const pvParameters, 443 UBaseType_t uxPriority, 444 StackType_t * const pxStackBuffer, 445 StaticTask_t * const pxTaskBuffer, 446 const BaseType_t xCoreID ); 447 #endif /* configSUPPORT_STATIC_ALLOCATION */ 448 449 /** 450 * Create a new task and add it to the list of tasks that are ready to run. 451 * 452 * Internally, within the FreeRTOS implementation, tasks use two blocks of 453 * memory. The first block is used to hold the task's data structures. The 454 * second block is used by the task as its stack. If a task is created using 455 * xTaskCreate() then both blocks of memory are automatically dynamically 456 * allocated inside the xTaskCreate() function. (see 457 * http://www.freertos.org/a00111.html). If a task is created using 458 * xTaskCreateStatic() then the application writer must provide the required 459 * memory. xTaskCreateStatic() therefore allows a task to be created without 460 * using any dynamic memory allocation. 461 * 462 * @param pvTaskCode Pointer to the task entry function. Tasks 463 * must be implemented to never return (i.e. continuous loop). 464 * 465 * @param pcName A descriptive name for the task. This is mainly used to 466 * facilitate debugging. The maximum length of the string is defined by 467 * configMAX_TASK_NAME_LEN in FreeRTOSConfig.h. 468 * 469 * @param ulStackDepth The size of the task stack specified as the number of 470 * bytes. Note that this differs from vanilla FreeRTOS. 471 * 472 * @param pvParameters Pointer that will be used as the parameter for the task 473 * being created. 474 * 475 * @param uxPriority The priority at which the task will run. 476 * 477 * @param pxStackBuffer Must point to a StackType_t array that has at least 478 * ulStackDepth indexes - the array will then be used as the task's stack, 479 * removing the need for the stack to be allocated dynamically. 480 * 481 * @param pxTaskBuffer Must point to a variable of type StaticTask_t, which will 482 * then be used to hold the task's data structures, removing the need for the 483 * memory to be allocated dynamically. 484 * 485 * @return If neither pxStackBuffer or pxTaskBuffer are NULL, then the task will 486 * be created and pdPASS is returned. If either pxStackBuffer or pxTaskBuffer 487 * are NULL then the task will not be created and 488 * errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY is returned. 489 * 490 * @note If program uses thread local variables (ones specified with "__thread" keyword) 491 * then storage for them will be allocated on the task's stack. 492 * 493 * Example usage: 494 * @code{c} 495 * 496 * // Dimensions the buffer that the task being created will use as its stack. 497 * // NOTE: This is the number of bytes the stack will hold, not the number of 498 * // words as found in vanilla FreeRTOS. 499 * #define STACK_SIZE 200 500 * 501 * // Structure that will hold the TCB of the task being created. 502 * StaticTask_t xTaskBuffer; 503 * 504 * // Buffer that the task being created will use as its stack. Note this is 505 * // an array of StackType_t variables. The size of StackType_t is dependent on 506 * // the RTOS port. 507 * StackType_t xStack[ STACK_SIZE ]; 508 * 509 * // Function that implements the task being created. 510 * void vTaskCode( void * pvParameters ) 511 * { 512 * // The parameter value is expected to be 1 as 1 is passed in the 513 * // pvParameters value in the call to xTaskCreateStatic(). 514 * configASSERT( ( uint32_t ) pvParameters == 1UL ); 515 * 516 * for( ;; ) 517 * { 518 * // Task code goes here. 519 * } 520 * } 521 * 522 * // Function that creates a task. 523 * void vOtherFunction( void ) 524 * { 525 * TaskHandle_t xHandle = NULL; 526 * 527 * // Create the task without using any dynamic memory allocation. 528 * xHandle = xTaskCreateStatic( 529 * vTaskCode, // Function that implements the task. 530 * "NAME", // Text name for the task. 531 * STACK_SIZE, // Stack size in bytes, not words. 532 * ( void * ) 1, // Parameter passed into the task. 533 * tskIDLE_PRIORITY,// Priority at which the task is created. 534 * xStack, // Array to use as the task's stack. 535 * &xTaskBuffer ); // Variable to hold the task's data structure. 536 * 537 * // puxStackBuffer and pxTaskBuffer were not NULL, so the task will have 538 * // been created, and xHandle will be the task's handle. Use the handle 539 * // to suspend the task. 540 * vTaskSuspend( xHandle ); 541 * } 542 * @endcode 543 * \ingroup Tasks 544 */ 545 546 #if( configSUPPORT_STATIC_ALLOCATION == 1 ) 547 static inline IRAM_ATTR TaskHandle_t xTaskCreateStatic( 548 TaskFunction_t pvTaskCode, 549 const char * const pcName, 550 const uint32_t ulStackDepth, 551 void * const pvParameters, 552 UBaseType_t uxPriority, 553 StackType_t * const pxStackBuffer, 554 StaticTask_t * const pxTaskBuffer) 555 { 556 return xTaskCreateStaticPinnedToCore( pvTaskCode, pcName, ulStackDepth, pvParameters, uxPriority, pxStackBuffer, pxTaskBuffer, tskNO_AFFINITY ); 557 } 558 #endif /* configSUPPORT_STATIC_ALLOCATION */ 559 560 /* 561 * xTaskCreateRestricted() should only be used in systems that include an MPU 562 * implementation. 563 * 564 * Create a new task and add it to the list of tasks that are ready to run. 565 * The function parameters define the memory regions and associated access 566 * permissions allocated to the task. 567 * 568 * See xTaskCreateRestrictedStatic() for a version that does not use any 569 * dynamic memory allocation. 570 * 571 * param pxTaskDefinition Pointer to a structure that contains a member 572 * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API 573 * documentation) plus an optional stack buffer and the memory region 574 * definitions. 575 * 576 * param pxCreatedTask Used to pass back a handle by which the created task 577 * can be referenced. 578 * 579 * return pdPASS if the task was successfully created and added to a ready 580 * list, otherwise an error code defined in the file projdefs.h 581 * 582 * Example usage: 583 * @code{c} 584 * // Create an TaskParameters_t structure that defines the task to be created. 585 * static const TaskParameters_t xCheckTaskParameters = 586 * { 587 * vATask, // pvTaskCode - the function that implements the task. 588 * "ATask", // pcName - just a text name for the task to assist debugging. 589 * 100, // usStackDepth - the stack size DEFINED IN WORDS. 590 * NULL, // pvParameters - passed into the task function as the function parameters. 591 * ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state. 592 * cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack. 593 * 594 * // xRegions - Allocate up to three separate memory regions for access by 595 * // the task, with appropriate access permissions. Different processors have 596 * // different memory alignment requirements - refer to the FreeRTOS documentation 597 * // for full information. 598 * { 599 * // Base address Length Parameters 600 * { cReadWriteArray, 32, portMPU_REGION_READ_WRITE }, 601 * { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY }, 602 * { cPrivilegedOnlyAccessArray, 128, portMPU_REGION_PRIVILEGED_READ_WRITE } 603 * } 604 * }; 605 * 606 * int main( void ) 607 * { 608 * TaskHandle_t xHandle; 609 * 610 * // Create a task from the const structure defined above. The task handle 611 * // is requested (the second parameter is not NULL) but in this case just for 612 * // demonstration purposes as its not actually used. 613 * xTaskCreateRestricted( &xRegTest1Parameters, &xHandle ); 614 * 615 * // Start the scheduler. 616 * vTaskStartScheduler(); 617 * 618 * // Will only get here if there was insufficient memory to create the idle 619 * // and/or timer task. 620 * for( ;; ); 621 * } 622 * @endcode 623 * \ingroup Tasks 624 */ 625 #if( portUSING_MPU_WRAPPERS == 1 ) 626 BaseType_t xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ); 627 #endif 628 629 /* 630 * xTaskCreateRestrictedStatic() should only be used in systems that include an 631 * MPU implementation. 632 * 633 * Only available when configSUPPORT_STATIC_ALLOCATION is set to 1. 634 * 635 * Internally, within the FreeRTOS implementation, tasks use two blocks of 636 * memory. The first block is used to hold the task's data structures. The 637 * second block is used by the task as its stack. If a task is created using 638 * xTaskCreateRestricted() then the stack is provided by the application writer, 639 * and the memory used to hold the task's data structure is automatically 640 * dynamically allocated inside the xTaskCreateRestricted() function. If a task 641 * is created using xTaskCreateRestrictedStatic() then the application writer 642 * must provide the memory used to hold the task's data structures too. 643 * xTaskCreateRestrictedStatic() therefore allows a memory protected task to be 644 * created without using any dynamic memory allocation. 645 * 646 * param pxTaskDefinition Pointer to a structure that contains a member 647 * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API 648 * documentation) plus an optional stack buffer and the memory region 649 * definitions. If configSUPPORT_STATIC_ALLOCATION is set to 1 the structure 650 * contains an additional member, which is used to point to a variable of type 651 * StaticTask_t - which is then used to hold the task's data structure. 652 * 653 * param pxCreatedTask Used to pass back a handle by which the created task 654 * can be referenced. 655 * 656 * return pdPASS if the task was successfully created and added to a ready 657 * list, otherwise an error code defined in the file projdefs.h 658 * 659 * Example usage: 660 * @code{c} 661 * // Create an TaskParameters_t structure that defines the task to be created. 662 * // The StaticTask_t variable is only included in the structure when 663 * // configSUPPORT_STATIC_ALLOCATION is set to 1. The PRIVILEGED_DATA macro can 664 * // be used to force the variable into the RTOS kernel's privileged data area. 665 * static PRIVILEGED_DATA StaticTask_t xTaskBuffer; 666 * static const TaskParameters_t xCheckTaskParameters = 667 * { 668 * vATask, // pvTaskCode - the function that implements the task. 669 * "ATask", // pcName - just a text name for the task to assist debugging. 670 * 100, // usStackDepth - the stack size DEFINED IN BYTES. 671 * NULL, // pvParameters - passed into the task function as the function parameters. 672 * ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state. 673 * cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack. 674 * 675 * // xRegions - Allocate up to three separate memory regions for access by 676 * // the task, with appropriate access permissions. Different processors have 677 * // different memory alignment requirements - refer to the FreeRTOS documentation 678 * // for full information. 679 * { 680 * // Base address Length Parameters 681 * { cReadWriteArray, 32, portMPU_REGION_READ_WRITE }, 682 * { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY }, 683 * { cPrivilegedOnlyAccessArray, 128, portMPU_REGION_PRIVILEGED_READ_WRITE } 684 * } 685 * 686 * &xTaskBuffer; // Holds the task's data structure. 687 * }; 688 * 689 * int main( void ) 690 * { 691 * TaskHandle_t xHandle; 692 * 693 * // Create a task from the const structure defined above. The task handle 694 * // is requested (the second parameter is not NULL) but in this case just for 695 * // demonstration purposes as its not actually used. 696 * xTaskCreateRestricted( &xRegTest1Parameters, &xHandle ); 697 * 698 * // Start the scheduler. 699 * vTaskStartScheduler(); 700 * 701 * // Will only get here if there was insufficient memory to create the idle 702 * // and/or timer task. 703 * for( ;; ); 704 * } 705 * @endcode 706 * \ingroup Tasks 707 */ 708 #if( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) 709 BaseType_t xTaskCreateRestrictedStatic( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ); 710 #endif 711 712 /* 713 * Memory regions are assigned to a restricted task when the task is created by 714 * a call to xTaskCreateRestricted(). These regions can be redefined using 715 * vTaskAllocateMPURegions(). 716 * 717 * param xTask The handle of the task being updated. 718 * 719 * param pxRegions A pointer to an MemoryRegion_t structure that contains the 720 * new memory region definitions. 721 * 722 * Example usage: 723 * 724 * @code{c} 725 * // Define an array of MemoryRegion_t structures that configures an MPU region 726 * // allowing read/write access for 1024 bytes starting at the beginning of the 727 * // ucOneKByte array. The other two of the maximum 3 definable regions are 728 * // unused so set to zero. 729 * static const MemoryRegion_t xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] = 730 * { 731 * // Base address Length Parameters 732 * { ucOneKByte, 1024, portMPU_REGION_READ_WRITE }, 733 * { 0, 0, 0 }, 734 * { 0, 0, 0 } 735 * }; 736 * 737 * void vATask( void *pvParameters ) 738 * { 739 * // This task was created such that it has access to certain regions of 740 * // memory as defined by the MPU configuration. At some point it is 741 * // desired that these MPU regions are replaced with that defined in the 742 * // xAltRegions const struct above. Use a call to vTaskAllocateMPURegions() 743 * // for this purpose. NULL is used as the task handle to indicate that this 744 * // function should modify the MPU regions of the calling task. 745 * vTaskAllocateMPURegions( NULL, xAltRegions ); 746 * 747 * // Now the task can continue its function, but from this point on can only 748 * // access its stack and the ucOneKByte array (unless any other statically 749 * // defined or shared regions have been declared elsewhere). 750 * } 751 * @endcode 752 * \ingroup Tasks 753 */ 754 void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions ) PRIVILEGED_FUNCTION; 755 756 /** 757 * Remove a task from the RTOS real time kernel's management. The task being 758 * deleted will be removed from all ready, blocked, suspended and event lists. 759 * 760 * INCLUDE_vTaskDelete must be defined as 1 for this function to be available. 761 * See the configuration section for more information. 762 * 763 * NOTE: The idle task is responsible for freeing the kernel allocated 764 * memory from tasks that have been deleted. It is therefore important that 765 * the idle task is not starved of microcontroller processing time if your 766 * application makes any calls to vTaskDelete (). Memory allocated by the 767 * task code is not automatically freed, and should be freed before the task 768 * is deleted. 769 * 770 * See the demo application file death.c for sample code that utilises 771 * vTaskDelete (). 772 * 773 * @param xTaskToDelete The handle of the task to be deleted. Passing NULL will 774 * cause the calling task to be deleted. 775 * 776 * Example usage: 777 * @code{c} 778 * void vOtherFunction( void ) 779 * { 780 * TaskHandle_t xHandle; 781 * 782 * // Create the task, storing the handle. 783 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle ); 784 * 785 * // Use the handle to delete the task. 786 * vTaskDelete( xHandle ); 787 * } 788 * @endcode 789 * \ingroup Tasks 790 */ 791 void vTaskDelete( TaskHandle_t xTaskToDelete ) PRIVILEGED_FUNCTION; 792 793 /*----------------------------------------------------------- 794 * TASK CONTROL API 795 *----------------------------------------------------------*/ 796 797 /** 798 * Delay a task for a given number of ticks. 799 * 800 * Delay a task for a given number of ticks. The actual time that the 801 * task remains blocked depends on the tick rate. The constant 802 * portTICK_PERIOD_MS can be used to calculate real time from the tick 803 * rate - with the resolution of one tick period. 804 * 805 * INCLUDE_vTaskDelay must be defined as 1 for this function to be available. 806 * See the configuration section for more information. 807 * 808 * vTaskDelay() specifies a time at which the task wishes to unblock relative to 809 * the time at which vTaskDelay() is called. For example, specifying a block 810 * period of 100 ticks will cause the task to unblock 100 ticks after 811 * vTaskDelay() is called. vTaskDelay() does not therefore provide a good method 812 * of controlling the frequency of a periodic task as the path taken through the 813 * code, as well as other task and interrupt activity, will effect the frequency 814 * at which vTaskDelay() gets called and therefore the time at which the task 815 * next executes. See vTaskDelayUntil() for an alternative API function designed 816 * to facilitate fixed frequency execution. It does this by specifying an 817 * absolute time (rather than a relative time) at which the calling task should 818 * unblock. 819 * 820 * @param xTicksToDelay The amount of time, in tick periods, that 821 * the calling task should block. 822 * 823 * Example usage: 824 * @code{c} 825 * void vTaskFunction( void * pvParameters ) 826 * { 827 * // Block for 500ms. 828 * const TickType_t xDelay = 500 / portTICK_PERIOD_MS; 829 * 830 * for( ;; ) 831 * { 832 * // Simply toggle the LED every 500ms, blocking between each toggle. 833 * vToggleLED(); 834 * vTaskDelay( xDelay ); 835 * } 836 * } 837 * @endcode 838 * \ingroup TaskCtrl 839 */ 840 void vTaskDelay( const TickType_t xTicksToDelay ) PRIVILEGED_FUNCTION; 841 842 /** 843 * Delay a task until a specified time. 844 * 845 * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available. 846 * See the configuration section for more information. 847 * 848 * Delay a task until a specified time. This function can be used by periodic 849 * tasks to ensure a constant execution frequency. 850 * 851 * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will 852 * cause a task to block for the specified number of ticks from the time vTaskDelay () is 853 * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed 854 * execution frequency as the time between a task starting to execute and that task 855 * calling vTaskDelay () may not be fixed [the task may take a different path though the 856 * code between calls, or may get interrupted or preempted a different number of times 857 * each time it executes]. 858 * 859 * Whereas vTaskDelay () specifies a wake time relative to the time at which the function 860 * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to 861 * unblock. 862 * 863 * The constant portTICK_PERIOD_MS can be used to calculate real time from the tick 864 * rate - with the resolution of one tick period. 865 * 866 * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the 867 * task was last unblocked. The variable must be initialised with the current time 868 * prior to its first use (see the example below). Following this the variable is 869 * automatically updated within vTaskDelayUntil (). 870 * 871 * @param xTimeIncrement The cycle time period. The task will be unblocked at 872 * time *pxPreviousWakeTime + xTimeIncrement. Calling vTaskDelayUntil with the 873 * same xTimeIncrement parameter value will cause the task to execute with 874 * a fixed interface period. 875 * 876 * Example usage: 877 * @code{c} 878 * // Perform an action every 10 ticks. 879 * void vTaskFunction( void * pvParameters ) 880 * { 881 * TickType_t xLastWakeTime; 882 * const TickType_t xFrequency = 10; 883 * 884 * // Initialise the xLastWakeTime variable with the current time. 885 * xLastWakeTime = xTaskGetTickCount (); 886 * for( ;; ) 887 * { 888 * // Wait for the next cycle. 889 * vTaskDelayUntil( &xLastWakeTime, xFrequency ); 890 * 891 * // Perform action here. 892 * } 893 * } 894 * @endcode 895 * \ingroup TaskCtrl 896 */ 897 void vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, const TickType_t xTimeIncrement ) PRIVILEGED_FUNCTION; 898 899 /** 900 * INCLUDE_xTaskAbortDelay must be defined as 1 in FreeRTOSConfig.h for this 901 * function to be available. 902 * 903 * A task will enter the Blocked state when it is waiting for an event. The 904 * event it is waiting for can be a temporal event (waiting for a time), such 905 * as when vTaskDelay() is called, or an event on an object, such as when 906 * xQueueReceive() or ulTaskNotifyTake() is called. If the handle of a task 907 * that is in the Blocked state is used in a call to xTaskAbortDelay() then the 908 * task will leave the Blocked state, and return from whichever function call 909 * placed the task into the Blocked state. 910 * 911 * @param xTask The handle of the task to remove from the Blocked state. 912 * 913 * @return If the task referenced by xTask was not in the Blocked state then 914 * pdFAIL is returned. Otherwise pdPASS is returned. 915 * 916 * \defgroup xTaskAbortDelay xTaskAbortDelay 917 * \ingroup TaskCtrl 918 */ 919 BaseType_t xTaskAbortDelay( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; 920 921 /** 922 * Obtain the priority of any task. 923 * 924 * INCLUDE_uxTaskPriorityGet must be defined as 1 for this function to be available. 925 * See the configuration section for more information. 926 * 927 * @param xTask Handle of the task to be queried. Passing a NULL 928 * handle results in the priority of the calling task being returned. 929 * 930 * @return The priority of xTask. 931 * 932 * Example usage: 933 * @code{c} 934 * void vAFunction( void ) 935 * { 936 * TaskHandle_t xHandle; 937 * 938 * // Create a task, storing the handle. 939 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle ); 940 * 941 * // ... 942 * 943 * // Use the handle to obtain the priority of the created task. 944 * // It was created with tskIDLE_PRIORITY, but may have changed 945 * // it itself. 946 * if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY ) 947 * { 948 * // The task has changed it's priority. 949 * } 950 * 951 * // ... 952 * 953 * // Is our priority higher than the created task? 954 * if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) ) 955 * { 956 * // Our priority (obtained using NULL handle) is higher. 957 * } 958 * } 959 * @endcode 960 * \ingroup TaskCtrl 961 */ 962 UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION; 963 964 /** 965 * A version of uxTaskPriorityGet() that can be used from an ISR. 966 */ 967 UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION; 968 969 /** 970 * Obtain the state of any task. 971 * 972 * States are encoded by the eTaskState enumerated type. 973 * 974 * INCLUDE_eTaskGetState must be defined as 1 for this function to be available. 975 * See the configuration section for more information. 976 * 977 * @param xTask Handle of the task to be queried. 978 * 979 * @return The state of xTask at the time the function was called. Note the 980 * state of the task might change between the function being called, and the 981 * functions return value being tested by the calling task. 982 */ 983 eTaskState eTaskGetState( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; 984 985 /** 986 * Populates a TaskStatus_t structure with information about a task. 987 * 988 * configUSE_TRACE_FACILITY must be defined as 1 for this function to be 989 * available. See the configuration section for more information. 990 * 991 * 992 * @param xTask Handle of the task being queried. If xTask is NULL then 993 * information will be returned about the calling task. 994 * 995 * @param pxTaskStatus A pointer to the TaskStatus_t structure that will be 996 * filled with information about the task referenced by the handle passed using 997 * the xTask parameter. 998 * 999 * @param xGetFreeStackSpace The TaskStatus_t structure contains a member to report 1000 * the stack high water mark of the task being queried. Calculating the stack 1001 * high water mark takes a relatively long time, and can make the system 1002 * temporarily unresponsive - so the xGetFreeStackSpace parameter is provided to 1003 * allow the high water mark checking to be skipped. The high watermark value 1004 * will only be written to the TaskStatus_t structure if xGetFreeStackSpace is 1005 * not set to pdFALSE; 1006 * 1007 * @param eState The TaskStatus_t structure contains a member to report the 1008 * state of the task being queried. Obtaining the task state is not as fast as 1009 * a simple assignment - so the eState parameter is provided to allow the state 1010 * information to be omitted from the TaskStatus_t structure. To obtain state 1011 * information then set eState to eInvalid - otherwise the value passed in 1012 * eState will be reported as the task state in the TaskStatus_t structure. 1013 * 1014 * Example usage: 1015 * @code{c} 1016 * void vAFunction( void ) 1017 * { 1018 * TaskHandle_t xHandle; 1019 * TaskStatus_t xTaskDetails; 1020 * 1021 * // Obtain the handle of a task from its name. 1022 * xHandle = xTaskGetHandle( "Task_Name" ); 1023 * 1024 * // Check the handle is not NULL. 1025 * configASSERT( xHandle ); 1026 * 1027 * // Use the handle to obtain further information about the task. 1028 * vTaskGetInfo( xHandle, 1029 * &xTaskDetails, 1030 * pdTRUE, // Include the high water mark in xTaskDetails. 1031 * eInvalid ); // Include the task state in xTaskDetails. 1032 * } 1033 * @endcode 1034 * \ingroup TaskCtrl 1035 */ 1036 void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState ) PRIVILEGED_FUNCTION; 1037 1038 /** 1039 * Set the priority of any task. 1040 * 1041 * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available. 1042 * See the configuration section for more information. 1043 * 1044 * A context switch will occur before the function returns if the priority 1045 * being set is higher than the currently executing task. 1046 * 1047 * @param xTask Handle to the task for which the priority is being set. 1048 * Passing a NULL handle results in the priority of the calling task being set. 1049 * 1050 * @param uxNewPriority The priority to which the task will be set. 1051 * 1052 * Example usage: 1053 * @code{c} 1054 * void vAFunction( void ) 1055 * { 1056 * TaskHandle_t xHandle; 1057 * 1058 * // Create a task, storing the handle. 1059 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle ); 1060 * 1061 * // ... 1062 * 1063 * // Use the handle to raise the priority of the created task. 1064 * vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 ); 1065 * 1066 * // ... 1067 * 1068 * // Use a NULL handle to raise our priority to the same value. 1069 * vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 ); 1070 * } 1071 * @endcode 1072 * \ingroup TaskCtrl 1073 */ 1074 void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority ) PRIVILEGED_FUNCTION; 1075 1076 /** 1077 * Suspend a task. 1078 * 1079 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available. 1080 * See the configuration section for more information. 1081 * 1082 * Suspend any task. When suspended a task will never get any microcontroller 1083 * processing time, no matter what its priority. 1084 * 1085 * Calls to vTaskSuspend are not accumulative - 1086 * i.e. calling vTaskSuspend () twice on the same task still only requires one 1087 * call to vTaskResume () to ready the suspended task. 1088 * 1089 * @param xTaskToSuspend Handle to the task being suspended. Passing a NULL 1090 * handle will cause the calling task to be suspended. 1091 * 1092 * Example usage: 1093 * @code{c} 1094 * void vAFunction( void ) 1095 * { 1096 * TaskHandle_t xHandle; 1097 * 1098 * // Create a task, storing the handle. 1099 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle ); 1100 * 1101 * // ... 1102 * 1103 * // Use the handle to suspend the created task. 1104 * vTaskSuspend( xHandle ); 1105 * 1106 * // ... 1107 * 1108 * // The created task will not run during this period, unless 1109 * // another task calls vTaskResume( xHandle ). 1110 * 1111 * //... 1112 * 1113 * 1114 * // Suspend ourselves. 1115 * vTaskSuspend( NULL ); 1116 * 1117 * // We cannot get here unless another task calls vTaskResume 1118 * // with our handle as the parameter. 1119 * } 1120 * @endcode 1121 * \ingroup TaskCtrl 1122 */ 1123 void vTaskSuspend( TaskHandle_t xTaskToSuspend ) PRIVILEGED_FUNCTION; 1124 1125 /** 1126 * Resumes a suspended task. 1127 * 1128 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available. 1129 * See the configuration section for more information. 1130 * 1131 * A task that has been suspended by one or more calls to vTaskSuspend () 1132 * will be made available for running again by a single call to 1133 * vTaskResume (). 1134 * 1135 * @param xTaskToResume Handle to the task being readied. 1136 * 1137 * Example usage: 1138 * @code{c} 1139 * void vAFunction( void ) 1140 * { 1141 * TaskHandle_t xHandle; 1142 * 1143 * // Create a task, storing the handle. 1144 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle ); 1145 * 1146 * // ... 1147 * 1148 * // Use the handle to suspend the created task. 1149 * vTaskSuspend( xHandle ); 1150 * 1151 * // ... 1152 * 1153 * // The created task will not run during this period, unless 1154 * // another task calls vTaskResume( xHandle ). 1155 * 1156 * //... 1157 * 1158 * 1159 * // Resume the suspended task ourselves. 1160 * vTaskResume( xHandle ); 1161 * 1162 * // The created task will once again get microcontroller processing 1163 * // time in accordance with its priority within the system. 1164 * } 1165 * @endcode 1166 * \ingroup TaskCtrl 1167 */ 1168 void vTaskResume( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION; 1169 1170 /** 1171 * An implementation of vTaskResume() that can be called from within an ISR. 1172 * 1173 * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be 1174 * available. See the configuration section for more information. 1175 * 1176 * A task that has been suspended by one or more calls to vTaskSuspend () 1177 * will be made available for running again by a single call to 1178 * xTaskResumeFromISR (). 1179 * 1180 * xTaskResumeFromISR() should not be used to synchronise a task with an 1181 * interrupt if there is a chance that the interrupt could arrive prior to the 1182 * task being suspended - as this can lead to interrupts being missed. Use of a 1183 * semaphore as a synchronisation mechanism would avoid this eventuality. 1184 * 1185 * @param xTaskToResume Handle to the task being readied. 1186 * 1187 * @return pdTRUE if resuming the task should result in a context switch, 1188 * otherwise pdFALSE. This is used by the ISR to determine if a context switch 1189 * may be required following the ISR. 1190 * 1191 * \ingroup TaskCtrl 1192 */ 1193 BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION; 1194 1195 /*----------------------------------------------------------- 1196 * SCHEDULER CONTROL 1197 *----------------------------------------------------------*/ 1198 /** @cond */ 1199 /** 1200 * Starts the real time kernel tick processing. 1201 * 1202 * After calling the kernel has control over which tasks are executed and when. 1203 * 1204 * See the demo application file main.c for an example of creating 1205 * tasks and starting the kernel. 1206 * 1207 * Example usage: 1208 * @code{c} 1209 * void vAFunction( void ) 1210 * { 1211 * // Create at least one task before starting the kernel. 1212 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); 1213 * 1214 * // Start the real time kernel with preemption. 1215 * vTaskStartScheduler (); 1216 * 1217 * // Will not get here unless a task calls vTaskEndScheduler () 1218 * } 1219 * @endcode 1220 * 1221 * \ingroup SchedulerControl 1222 */ 1223 void vTaskStartScheduler( void ) PRIVILEGED_FUNCTION; 1224 1225 /** 1226 * Stops the real time kernel tick. 1227 * 1228 * NOTE: At the time of writing only the x86 real mode port, which runs on a PC 1229 * in place of DOS, implements this function. 1230 * 1231 * Stops the real time kernel tick. All created tasks will be automatically 1232 * deleted and multitasking (either preemptive or cooperative) will 1233 * stop. Execution then resumes from the point where vTaskStartScheduler () 1234 * was called, as if vTaskStartScheduler () had just returned. 1235 * 1236 * See the demo application file main. c in the demo/PC directory for an 1237 * example that uses vTaskEndScheduler (). 1238 * 1239 * vTaskEndScheduler () requires an exit function to be defined within the 1240 * portable layer (see vPortEndScheduler () in port. c for the PC port). This 1241 * performs hardware specific operations such as stopping the kernel tick. 1242 * 1243 * vTaskEndScheduler () will cause all of the resources allocated by the 1244 * kernel to be freed - but will not free resources allocated by application 1245 * tasks. 1246 * 1247 * Example usage: 1248 * @code{c} 1249 * void vTaskCode( void * pvParameters ) 1250 * { 1251 * for( ;; ) 1252 * { 1253 * // Task code goes here. 1254 * 1255 * // At some point we want to end the real time kernel processing 1256 * // so call ... 1257 * vTaskEndScheduler (); 1258 * } 1259 * } 1260 * 1261 * void vAFunction( void ) 1262 * { 1263 * // Create at least one task before starting the kernel. 1264 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); 1265 * 1266 * // Start the real time kernel with preemption. 1267 * vTaskStartScheduler (); 1268 * 1269 * // Will only get here when the vTaskCode () task has called 1270 * // vTaskEndScheduler (). When we get here we are back to single task 1271 * // execution. 1272 * } 1273 * @endcode 1274 * \ingroup SchedulerControl 1275 */ 1276 void vTaskEndScheduler( void ) PRIVILEGED_FUNCTION; 1277 1278 /** @endcond */ 1279 1280 /** 1281 * Suspends the scheduler without disabling interrupts. 1282 * 1283 * Context switches will not occur while the scheduler is suspended. 1284 * 1285 * After calling vTaskSuspendAll () the calling task will continue to execute 1286 * without risk of being swapped out until a call to xTaskResumeAll () has been 1287 * made. 1288 * 1289 * API functions that have the potential to cause a context switch (for example, 1290 * vTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler 1291 * is suspended. 1292 * 1293 * Example usage: 1294 * @code{c} 1295 * void vTask1( void * pvParameters ) 1296 * { 1297 * for( ;; ) 1298 * { 1299 * // Task code goes here. 1300 * 1301 * // ... 1302 * 1303 * // At some point the task wants to perform a long operation during 1304 * // which it does not want to get swapped out. It cannot use 1305 * // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the 1306 * // operation may cause interrupts to be missed - including the 1307 * // ticks. 1308 * 1309 * // Prevent the real time kernel swapping out the task. 1310 * vTaskSuspendAll (); 1311 * 1312 * // Perform the operation here. There is no need to use critical 1313 * // sections as we have all the microcontroller processing time. 1314 * // During this time interrupts will still operate and the kernel 1315 * // tick count will be maintained. 1316 * 1317 * // ... 1318 * 1319 * // The operation is complete. Restart the kernel. 1320 * xTaskResumeAll (); 1321 * } 1322 * } 1323 * @endcode 1324 * \ingroup SchedulerControl 1325 */ 1326 void vTaskSuspendAll( void ) PRIVILEGED_FUNCTION; 1327 1328 /** 1329 * Resumes scheduler activity after it was suspended by a call to 1330 * vTaskSuspendAll(). 1331 * 1332 * xTaskResumeAll() only resumes the scheduler. It does not unsuspend tasks 1333 * that were previously suspended by a call to vTaskSuspend(). 1334 * 1335 * @return If resuming the scheduler caused a context switch then pdTRUE is 1336 * returned, otherwise pdFALSE is returned. 1337 * 1338 * Example usage: 1339 * @code{c} 1340 * void vTask1( void * pvParameters ) 1341 * { 1342 * for( ;; ) 1343 * { 1344 * // Task code goes here. 1345 * 1346 * // ... 1347 * 1348 * // At some point the task wants to perform a long operation during 1349 * // which it does not want to get swapped out. It cannot use 1350 * // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the 1351 * // operation may cause interrupts to be missed - including the 1352 * // ticks. 1353 * 1354 * // Prevent the real time kernel swapping out the task. 1355 * vTaskSuspendAll (); 1356 * 1357 * // Perform the operation here. There is no need to use critical 1358 * // sections as we have all the microcontroller processing time. 1359 * // During this time interrupts will still operate and the real 1360 * // time kernel tick count will be maintained. 1361 * 1362 * // ... 1363 * 1364 * // The operation is complete. Restart the kernel. We want to force 1365 * // a context switch - but there is no point if resuming the scheduler 1366 * // caused a context switch already. 1367 * if( !xTaskResumeAll () ) 1368 * { 1369 * taskYIELD (); 1370 * } 1371 * } 1372 * } 1373 * @endcode 1374 * \ingroup SchedulerControl 1375 */ 1376 BaseType_t xTaskResumeAll( void ) PRIVILEGED_FUNCTION; 1377 1378 /*----------------------------------------------------------- 1379 * TASK UTILITIES 1380 *----------------------------------------------------------*/ 1381 1382 /** 1383 * Get tick count 1384 * 1385 * @return The count of ticks since vTaskStartScheduler was called. 1386 * 1387 * \ingroup TaskUtils 1388 */ 1389 TickType_t xTaskGetTickCount( void ) PRIVILEGED_FUNCTION; 1390 1391 /** 1392 * Get tick count from ISR 1393 * 1394 * @return The count of ticks since vTaskStartScheduler was called. 1395 * 1396 * This is a version of xTaskGetTickCount() that is safe to be called from an 1397 * ISR - provided that TickType_t is the natural word size of the 1398 * microcontroller being used or interrupt nesting is either not supported or 1399 * not being used. 1400 * 1401 * \ingroup TaskUtils 1402 */ 1403 TickType_t xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION; 1404 1405 /** 1406 * Get current number of tasks 1407 * 1408 * @return The number of tasks that the real time kernel is currently managing. 1409 * This includes all ready, blocked and suspended tasks. A task that 1410 * has been deleted but not yet freed by the idle task will also be 1411 * included in the count. 1412 * 1413 * \ingroup TaskUtils 1414 */ 1415 UBaseType_t uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION; 1416 1417 /** 1418 * Get task name 1419 * 1420 * @return The text (human readable) name of the task referenced by the handle 1421 * xTaskToQuery. A task can query its own name by either passing in its own 1422 * handle, or by setting xTaskToQuery to NULL. 1423 * 1424 * \ingroup TaskUtils 1425 */ 1426 char *pcTaskGetName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ 1427 1428 /** 1429 * @note This function takes a relatively long time to complete and should be 1430 * used sparingly. 1431 * 1432 * @return The handle of the task that has the human readable name pcNameToQuery. 1433 * NULL is returned if no matching name is found. INCLUDE_xTaskGetHandle 1434 * must be set to 1 in FreeRTOSConfig.h for pcTaskGetHandle() to be available. 1435 * 1436 * \ingroup TaskUtils 1437 */ 1438 TaskHandle_t xTaskGetHandle( const char *pcNameToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ 1439 1440 /** 1441 * Returns the high water mark of the stack associated with xTask. 1442 * 1443 * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for 1444 * this function to be available. 1445 * 1446 * Returns the high water mark of the stack associated with xTask. That is, 1447 * the minimum free stack space there has been (in words, so on a 32 bit machine 1448 * a value of 1 means 4 bytes) since the task started. The smaller the returned 1449 * number the closer the task has come to overflowing its stack. 1450 * 1451 * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the 1452 * same except for their return type. Using configSTACK_DEPTH_TYPE allows the 1453 * user to determine the return type. It gets around the problem of the value 1454 * overflowing on 8-bit types without breaking backward compatibility for 1455 * applications that expect an 8-bit return type. 1456 * 1457 * @param xTask Handle of the task associated with the stack to be checked. 1458 * Set xTask to NULL to check the stack of the calling task. 1459 * 1460 * @return The smallest amount of free stack space there has been (in words, so 1461 * actual spaces on the stack rather than bytes) since the task referenced by 1462 * xTask was created. 1463 */ 1464 UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; 1465 1466 /** 1467 * Returns the start of the stack associated with xTask. 1468 * 1469 * INCLUDE_uxTaskGetStackHighWaterMark2 must be set to 1 in FreeRTOSConfig.h for 1470 * this function to be available. 1471 * 1472 * Returns the high water mark of the stack associated with xTask. That is, 1473 * the minimum free stack space there has been (in words, so on a 32 bit machine 1474 * a value of 1 means 4 bytes) since the task started. The smaller the returned 1475 * number the closer the task has come to overflowing its stack. 1476 * 1477 * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the 1478 * same except for their return type. Using configSTACK_DEPTH_TYPE allows the 1479 * user to determine the return type. It gets around the problem of the value 1480 * overflowing on 8-bit types without breaking backward compatibility for 1481 * applications that expect an 8-bit return type. 1482 * 1483 * @param xTask Handle of the task associated with the stack to be checked. 1484 * Set xTask to NULL to check the stack of the calling task. 1485 * 1486 * @return The smallest amount of free stack space there has been (in words, so 1487 * actual spaces on the stack rather than bytes) since the task referenced by 1488 * xTask was created. 1489 */ 1490 configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; 1491 1492 /** 1493 * Returns the start of the stack associated with xTask. 1494 * 1495 * INCLUDE_pxTaskGetStackStart must be set to 1 in FreeRTOSConfig.h for 1496 * this function to be available. 1497 * 1498 * Returns the highest stack memory address on architectures where the stack grows down 1499 * from high memory, and the lowest memory address on architectures where the 1500 * stack grows up from low memory. 1501 * 1502 * @param xTask Handle of the task associated with the stack returned. 1503 * Set xTask to NULL to return the stack of the calling task. 1504 * 1505 * @return A pointer to the start of the stack. 1506 */ 1507 uint8_t* pxTaskGetStackStart( TaskHandle_t xTask) PRIVILEGED_FUNCTION; 1508 1509 /* When using trace macros it is sometimes necessary to include task.h before 1510 FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined, 1511 so the following two prototypes will cause a compilation error. This can be 1512 fixed by simply guarding against the inclusion of these two prototypes unless 1513 they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration 1514 constant. */ 1515 #ifdef configUSE_APPLICATION_TASK_TAG 1516 #if configUSE_APPLICATION_TASK_TAG == 1 1517 /** 1518 * Sets pxHookFunction to be the task hook function used by the task xTask. 1519 * @param xTask Handle of the task to set the hook function for 1520 * Passing xTask as NULL has the effect of setting the calling 1521 * tasks hook function. 1522 * @param pxHookFunction Pointer to the hook function. 1523 */ 1524 void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction ) PRIVILEGED_FUNCTION; 1525 1526 /** 1527 * 1528 * Returns the pxHookFunction value assigned to the task xTask. Do not 1529 * call from an interrupt service routine - call 1530 * xTaskGetApplicationTaskTagFromISR() instead. 1531 */ 1532 TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; 1533 1534 /** 1535 * 1536 * Returns the pxHookFunction value assigned to the task xTask. Can 1537 * be called from an interrupt service routine. 1538 */ 1539 TaskHookFunction_t xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; 1540 #endif /* configUSE_APPLICATION_TASK_TAG ==1 */ 1541 #endif /* ifdef configUSE_APPLICATION_TASK_TAG */ 1542 1543 #if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 ) 1544 1545 /** 1546 * Set local storage pointer specific to the given task. 1547 * 1548 * Each task contains an array of pointers that is dimensioned by the 1549 * configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h. 1550 * The kernel does not use the pointers itself, so the application writer 1551 * can use the pointers for any purpose they wish. 1552 * 1553 * @param xTaskToSet Task to set thread local storage pointer for 1554 * @param xIndex The index of the pointer to set, from 0 to 1555 * configNUM_THREAD_LOCAL_STORAGE_POINTERS - 1. 1556 * @param pvValue Pointer value to set. 1557 */ 1558 void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue ) PRIVILEGED_FUNCTION; 1559 1560 1561 /** 1562 * Get local storage pointer specific to the given task. 1563 * 1564 * Each task contains an array of pointers that is dimensioned by the 1565 * configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h. 1566 * The kernel does not use the pointers itself, so the application writer 1567 * can use the pointers for any purpose they wish. 1568 * 1569 * @param xTaskToQuery Task to get thread local storage pointer for 1570 * @param xIndex The index of the pointer to get, from 0 to 1571 * configNUM_THREAD_LOCAL_STORAGE_POINTERS - 1. 1572 * @return Pointer value 1573 */ 1574 void *pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, BaseType_t xIndex ) PRIVILEGED_FUNCTION; 1575 1576 #if ( configTHREAD_LOCAL_STORAGE_DELETE_CALLBACKS ) 1577 1578 /** 1579 * Prototype of local storage pointer deletion callback. 1580 */ 1581 typedef void (*TlsDeleteCallbackFunction_t)( int, void * ); 1582 1583 /** 1584 * Set local storage pointer and deletion callback. 1585 * 1586 * Each task contains an array of pointers that is dimensioned by the 1587 * configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h. 1588 * The kernel does not use the pointers itself, so the application writer 1589 * can use the pointers for any purpose they wish. 1590 * 1591 * Local storage pointers set for a task can reference dynamically 1592 * allocated resources. This function is similar to 1593 * vTaskSetThreadLocalStoragePointer, but provides a way to release 1594 * these resources when the task gets deleted. For each pointer, 1595 * a callback function can be set. This function will be called 1596 * when task is deleted, with the local storage pointer index 1597 * and value as arguments. 1598 * 1599 * @param xTaskToSet Task to set thread local storage pointer for 1600 * @param xIndex The index of the pointer to set, from 0 to 1601 * configNUM_THREAD_LOCAL_STORAGE_POINTERS - 1. 1602 * @param pvValue Pointer value to set. 1603 * @param pvDelCallback Function to call to dispose of the local 1604 * storage pointer when the task is deleted. 1605 */ 1606 void vTaskSetThreadLocalStoragePointerAndDelCallback( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue, TlsDeleteCallbackFunction_t pvDelCallback); 1607 #endif 1608 1609 #endif 1610 1611 /** 1612 * Calls the hook function associated with xTask. Passing xTask as NULL has 1613 * the effect of calling the Running tasks (the calling task) hook function. 1614 * 1615 * @param xTask Handle of the task to call the hook for. 1616 * @param pvParameter Parameter passed to the hook function for the task to interpret as it 1617 * wants. The return value is the value returned by the task hook function 1618 * registered by the user. 1619 */ 1620 BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter ) PRIVILEGED_FUNCTION; 1621 1622 /** 1623 * xTaskGetIdleTaskHandle() is only available if 1624 * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h. 1625 * 1626 * Simply returns the handle of the idle task. It is not valid to call 1627 * xTaskGetIdleTaskHandle() before the scheduler has been started. 1628 */ 1629 TaskHandle_t xTaskGetIdleTaskHandle( void ) PRIVILEGED_FUNCTION; 1630 1631 /** 1632 * configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for 1633 * uxTaskGetSystemState() to be available. 1634 * 1635 * uxTaskGetSystemState() populates an TaskStatus_t structure for each task in 1636 * the system. TaskStatus_t structures contain, among other things, members 1637 * for the task handle, task name, task priority, task state, and total amount 1638 * of run time consumed by the task. See the TaskStatus_t structure 1639 * definition in this file for the full member list. 1640 * 1641 * @note This function is intended for debugging use only as its use results in 1642 * the scheduler remaining suspended for an extended period. 1643 * 1644 * @param pxTaskStatusArray A pointer to an array of TaskStatus_t structures. 1645 * The array must contain at least one TaskStatus_t structure for each task 1646 * that is under the control of the RTOS. The number of tasks under the control 1647 * of the RTOS can be determined using the uxTaskGetNumberOfTasks() API function. 1648 * 1649 * @param uxArraySize The size of the array pointed to by the pxTaskStatusArray 1650 * parameter. The size is specified as the number of indexes in the array, or 1651 * the number of TaskStatus_t structures contained in the array, not by the 1652 * number of bytes in the array. 1653 * 1654 * @param pulTotalRunTime If configGENERATE_RUN_TIME_STATS is set to 1 in 1655 * FreeRTOSConfig.h then *pulTotalRunTime is set by uxTaskGetSystemState() to the 1656 * total run time (as defined by the run time stats clock, see 1657 * http://www.freertos.org/rtos-run-time-stats.html) since the target booted. 1658 * pulTotalRunTime can be set to NULL to omit the total run time information. 1659 * 1660 * @return The number of TaskStatus_t structures that were populated by 1661 * uxTaskGetSystemState(). This should equal the number returned by the 1662 * uxTaskGetNumberOfTasks() API function, but will be zero if the value passed 1663 * in the uxArraySize parameter was too small. 1664 * 1665 * Example usage: 1666 * @code{c} 1667 * // This example demonstrates how a human readable table of run time stats 1668 * // information is generated from raw data provided by uxTaskGetSystemState(). 1669 * // The human readable table is written to pcWriteBuffer 1670 * void vTaskGetRunTimeStats( char *pcWriteBuffer ) 1671 * { 1672 * TaskStatus_t *pxTaskStatusArray; 1673 * volatile UBaseType_t uxArraySize, x; 1674 * uint32_t ulTotalRunTime, ulStatsAsPercentage; 1675 * 1676 * // Make sure the write buffer does not contain a string. 1677 * *pcWriteBuffer = 0x00; 1678 * 1679 * // Take a snapshot of the number of tasks in case it changes while this 1680 * // function is executing. 1681 * uxArraySize = uxTaskGetNumberOfTasks(); 1682 * 1683 * // Allocate a TaskStatus_t structure for each task. An array could be 1684 * // allocated statically at compile time. 1685 * pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) ); 1686 * 1687 * if( pxTaskStatusArray != NULL ) 1688 * { 1689 * // Generate raw status information about each task. 1690 * uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime ); 1691 * 1692 * // For percentage calculations. 1693 * ulTotalRunTime /= 100UL; 1694 * 1695 * // Avoid divide by zero errors. 1696 * if( ulTotalRunTime > 0 ) 1697 * { 1698 * // For each populated position in the pxTaskStatusArray array, 1699 * // format the raw data as human readable ASCII data 1700 * for( x = 0; x < uxArraySize; x++ ) 1701 * { 1702 * // What percentage of the total run time has the task used? 1703 * // This will always be rounded down to the nearest integer. 1704 * // ulTotalRunTimeDiv100 has already been divided by 100. 1705 * ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime; 1706 * 1707 * if( ulStatsAsPercentage > 0UL ) 1708 * { 1709 * sprintf( pcWriteBuffer, "%s\t\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage ); 1710 * } 1711 * else 1712 * { 1713 * // If the percentage is zero here then the task has 1714 * // consumed less than 1% of the total run time. 1715 * sprintf( pcWriteBuffer, "%s\t\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter ); 1716 * } 1717 * 1718 * pcWriteBuffer += strlen( ( char * ) pcWriteBuffer ); 1719 * } 1720 * } 1721 * 1722 * // The array is no longer needed, free the memory it consumes. 1723 * vPortFree( pxTaskStatusArray ); 1724 * } 1725 * } 1726 * @endcode 1727 */ 1728 UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime ) PRIVILEGED_FUNCTION; 1729 1730 /** 1731 * List all the current tasks. 1732 * 1733 * configUSE_TRACE_FACILITY and configUSE_STATS_FORMATTING_FUNCTIONS must 1734 * both be defined as 1 for this function to be available. See the 1735 * configuration section of the FreeRTOS.org website for more information. 1736 * 1737 * @note This function will disable interrupts for its duration. It is 1738 * not intended for normal application runtime use but as a debug aid. 1739 * 1740 * Lists all the current tasks, along with their current state and stack 1741 * usage high water mark. 1742 * 1743 * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or 1744 * suspended ('S'). 1745 * 1746 * @note This function is provided for convenience only, and is used by many of the 1747 * demo applications. Do not consider it to be part of the scheduler. 1748 * 1749 * vTaskList() calls uxTaskGetSystemState(), then formats part of the 1750 * uxTaskGetSystemState() output into a human readable table that displays task 1751 * names, states and stack usage. 1752 * 1753 * vTaskList() has a dependency on the sprintf() C library function that might 1754 * bloat the code size, use a lot of stack, and provide different results on 1755 * different platforms. An alternative, tiny, third party, and limited 1756 * functionality implementation of sprintf() is provided in many of the 1757 * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note 1758 * printf-stdarg.c does not provide a full snprintf() implementation!). 1759 * 1760 * It is recommended that production systems call uxTaskGetSystemState() 1761 * directly to get access to raw stats data, rather than indirectly through a 1762 * call to vTaskList(). 1763 * 1764 * @param pcWriteBuffer A buffer into which the above mentioned details 1765 * will be written, in ASCII form. This buffer is assumed to be large 1766 * enough to contain the generated report. Approximately 40 bytes per 1767 * task should be sufficient. 1768 * 1769 * \ingroup TaskUtils 1770 */ 1771 void vTaskList( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ 1772 1773 /** 1774 * Get the state of running tasks as a string 1775 * 1776 * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS 1777 * must both be defined as 1 for this function to be available. The application 1778 * must also then provide definitions for 1779 * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE() 1780 * to configure a peripheral timer/counter and return the timers current count 1781 * value respectively. The counter should be at least 10 times the frequency of 1782 * the tick count. 1783 * 1784 * @note This function will disable interrupts for its duration. It is 1785 * not intended for normal application runtime use but as a debug aid. 1786 * 1787 * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total 1788 * accumulated execution time being stored for each task. The resolution 1789 * of the accumulated time value depends on the frequency of the timer 1790 * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro. 1791 * Calling vTaskGetRunTimeStats() writes the total execution time of each 1792 * task into a buffer, both as an absolute count value and as a percentage 1793 * of the total system execution time. 1794 * 1795 * @note This function is provided for convenience only, and is used by many of the 1796 * demo applications. Do not consider it to be part of the scheduler. 1797 * 1798 * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part of the 1799 * uxTaskGetSystemState() output into a human readable table that displays the 1800 * amount of time each task has spent in the Running state in both absolute and 1801 * percentage terms. 1802 * 1803 * vTaskGetRunTimeStats() has a dependency on the sprintf() C library function 1804 * that might bloat the code size, use a lot of stack, and provide different 1805 * results on different platforms. An alternative, tiny, third party, and 1806 * limited functionality implementation of sprintf() is provided in many of the 1807 * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note 1808 * printf-stdarg.c does not provide a full snprintf() implementation!). 1809 * 1810 * It is recommended that production systems call uxTaskGetSystemState() directly 1811 * to get access to raw stats data, rather than indirectly through a call to 1812 * vTaskGetRunTimeStats(). 1813 * 1814 * @param pcWriteBuffer A buffer into which the execution times will be 1815 * written, in ASCII form. This buffer is assumed to be large enough to 1816 * contain the generated report. Approximately 40 bytes per task should 1817 * be sufficient. 1818 * 1819 * \ingroup TaskUtils 1820 */ 1821 void vTaskGetRunTimeStats( char *pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ 1822 1823 /** 1824 * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS 1825 * must both be defined as 1 for this function to be available. The application 1826 * must also then provide definitions for 1827 * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE() 1828 * to configure a peripheral timer/counter and return the timers current count 1829 * value respectively. The counter should be at least 10 times the frequency of 1830 * the tick count. 1831 * 1832 * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total 1833 * accumulated execution time being stored for each task. The resolution 1834 * of the accumulated time value depends on the frequency of the timer 1835 * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro. 1836 * While uxTaskGetSystemState() and vTaskGetRunTimeStats() writes the total 1837 * execution time of each task into a buffer, ulTaskGetIdleRunTimeCounter() 1838 * returns the total execution time of just the idle task. 1839 * 1840 * @return The total run time of the idle task. This is the amount of time the 1841 * idle task has actually been executing. The unit of time is dependent on the 1842 * frequency configured using the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and 1843 * portGET_RUN_TIME_COUNTER_VALUE() macros. 1844 * 1845 * \ingroup TaskUtils 1846 */ 1847 uint32_t ulTaskGetIdleRunTimeCounter( void ) PRIVILEGED_FUNCTION; 1848 1849 /** 1850 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this 1851 * function to be available. 1852 * 1853 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private 1854 * "notification value", which is a 32-bit unsigned integer (uint32_t). 1855 * 1856 * Events can be sent to a task using an intermediary object. Examples of such 1857 * objects are queues, semaphores, mutexes and event groups. Task notifications 1858 * are a method of sending an event directly to a task without the need for such 1859 * an intermediary object. 1860 * 1861 * A notification sent to a task can optionally perform an action, such as 1862 * update, overwrite or increment the task's notification value. In that way 1863 * task notifications can be used to send data to a task, or be used as light 1864 * weight and fast binary or counting semaphores. 1865 * 1866 * A notification sent to a task will remain pending until it is cleared by the 1867 * task calling xTaskNotifyWait() or ulTaskNotifyTake(). If the task was 1868 * already in the Blocked state to wait for a notification when the notification 1869 * arrives then the task will automatically be removed from the Blocked state 1870 * (unblocked) and the notification cleared. 1871 * 1872 * A task can use xTaskNotifyWait() to [optionally] block to wait for a 1873 * notification to be pending, or ulTaskNotifyTake() to [optionally] block 1874 * to wait for its notification value to have a non-zero value. The task does 1875 * not consume any CPU time while it is in the Blocked state. 1876 * 1877 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details. 1878 * 1879 * @param xTaskToNotify The handle of the task being notified. The handle to a 1880 * task can be returned from the xTaskCreate() API function used to create the 1881 * task, and the handle of the currently running task can be obtained by calling 1882 * xTaskGetCurrentTaskHandle(). 1883 * 1884 * @param ulValue Data that can be sent with the notification. How the data is 1885 * used depends on the value of the eAction parameter. 1886 * 1887 * @param eAction Specifies how the notification updates the task's notification 1888 * value, if at all. Valid values for eAction are as follows: 1889 * 1890 * eSetBits - 1891 * The task's notification value is bitwise ORed with ulValue. xTaskNofify() 1892 * always returns pdPASS in this case. 1893 * 1894 * eIncrement - 1895 * The task's notification value is incremented. ulValue is not used and 1896 * xTaskNotify() always returns pdPASS in this case. 1897 * 1898 * eSetValueWithOverwrite - 1899 * The task's notification value is set to the value of ulValue, even if the 1900 * task being notified had not yet processed the previous notification (the 1901 * task already had a notification pending). xTaskNotify() always returns 1902 * pdPASS in this case. 1903 * 1904 * eSetValueWithoutOverwrite - 1905 * If the task being notified did not already have a notification pending then 1906 * the task's notification value is set to ulValue and xTaskNotify() will 1907 * return pdPASS. If the task being notified already had a notification 1908 * pending then no action is performed and pdFAIL is returned. 1909 * 1910 * eNoAction - 1911 * The task receives a notification without its notification value being 1912 * updated. ulValue is not used and xTaskNotify() always returns pdPASS in 1913 * this case. 1914 * 1915 * @param pulPreviousNotificationValue Can be used to pass out the subject 1916 * task's notification value before any bits are modified by the notify 1917 * function. 1918 * 1919 * @return Dependent on the value of eAction. See the description of the 1920 * eAction parameter. 1921 * 1922 * \ingroup TaskNotifications 1923 */ 1924 BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue ) PRIVILEGED_FUNCTION; 1925 #define xTaskNotify( xTaskToNotify, ulValue, eAction ) xTaskGenericNotify( ( xTaskToNotify ), ( ulValue ), ( eAction ), NULL ) 1926 #define xTaskNotifyAndQuery( xTaskToNotify, ulValue, eAction, pulPreviousNotifyValue ) xTaskGenericNotify( ( xTaskToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) ) 1927 1928 /** 1929 * Send task notification from an ISR. 1930 * 1931 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this 1932 * function to be available. 1933 * 1934 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private 1935 * "notification value", which is a 32-bit unsigned integer (uint32_t). 1936 * 1937 * A version of xTaskNotify() that can be used from an interrupt service routine 1938 * (ISR). 1939 * 1940 * Events can be sent to a task using an intermediary object. Examples of such 1941 * objects are queues, semaphores, mutexes and event groups. Task notifications 1942 * are a method of sending an event directly to a task without the need for such 1943 * an intermediary object. 1944 * 1945 * A notification sent to a task can optionally perform an action, such as 1946 * update, overwrite or increment the task's notification value. In that way 1947 * task notifications can be used to send data to a task, or be used as light 1948 * weight and fast binary or counting semaphores. 1949 * 1950 * A notification sent to a task will remain pending until it is cleared by the 1951 * task calling xTaskNotifyWait() or ulTaskNotifyTake(). If the task was 1952 * already in the Blocked state to wait for a notification when the notification 1953 * arrives then the task will automatically be removed from the Blocked state 1954 * (unblocked) and the notification cleared. 1955 * 1956 * A task can use xTaskNotifyWait() to [optionally] block to wait for a 1957 * notification to be pending, or ulTaskNotifyTake() to [optionally] block 1958 * to wait for its notification value to have a non-zero value. The task does 1959 * not consume any CPU time while it is in the Blocked state. 1960 * 1961 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details. 1962 * 1963 * @param xTaskToNotify The handle of the task being notified. The handle to a 1964 * task can be returned from the xTaskCreate() API function used to create the 1965 * task, and the handle of the currently running task can be obtained by calling 1966 * xTaskGetCurrentTaskHandle(). 1967 * 1968 * @param ulValue Data that can be sent with the notification. How the data is 1969 * used depends on the value of the eAction parameter. 1970 * 1971 * @param eAction Specifies how the notification updates the task's notification 1972 * value, if at all. Valid values for eAction are as follows: 1973 * 1974 * eSetBits - 1975 * The task's notification value is bitwise ORed with ulValue. xTaskNofify() 1976 * always returns pdPASS in this case. 1977 * 1978 * eIncrement - 1979 * The task's notification value is incremented. ulValue is not used and 1980 * xTaskNotify() always returns pdPASS in this case. 1981 * 1982 * eSetValueWithOverwrite - 1983 * The task's notification value is set to the value of ulValue, even if the 1984 * task being notified had not yet processed the previous notification (the 1985 * task already had a notification pending). xTaskNotify() always returns 1986 * pdPASS in this case. 1987 * 1988 * eSetValueWithoutOverwrite - 1989 * If the task being notified did not already have a notification pending then 1990 * the task's notification value is set to ulValue and xTaskNotify() will 1991 * return pdPASS. If the task being notified already had a notification 1992 * pending then no action is performed and pdFAIL is returned. 1993 * 1994 * eNoAction - 1995 * The task receives a notification without its notification value being 1996 * updated. ulValue is not used and xTaskNotify() always returns pdPASS in 1997 * this case. 1998 * 1999 * @param pulPreviousNotificationValue Can be used to pass out the subject task's 2000 * notification value before any bits are modified by the notify function. 2001 * 2002 * @param pxHigherPriorityTaskWoken xTaskNotifyFromISR() will set 2003 * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the 2004 * task to which the notification was sent to leave the Blocked state, and the 2005 * unblocked task has a priority higher than the currently running task. If 2006 * xTaskNotifyFromISR() sets this value to pdTRUE then a context switch should 2007 * be requested before the interrupt is exited. How a context switch is 2008 * requested from an ISR is dependent on the port - see the documentation page 2009 * for the port in use. 2010 * 2011 * @return Dependent on the value of eAction. See the description of the 2012 * eAction parameter. 2013 * 2014 * \ingroup TaskNotifications 2015 */ 2016 BaseType_t xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; 2017 #define xTaskNotifyFromISR( xTaskToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) ) 2018 #define xTaskNotifyAndQueryFromISR( xTaskToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) ) 2019 2020 /** 2021 * Wait for task notification 2022 * 2023 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this 2024 * function to be available. 2025 * 2026 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private 2027 * "notification value", which is a 32-bit unsigned integer (uint32_t). 2028 * 2029 * Events can be sent to a task using an intermediary object. Examples of such 2030 * objects are queues, semaphores, mutexes and event groups. Task notifications 2031 * are a method of sending an event directly to a task without the need for such 2032 * an intermediary object. 2033 * 2034 * A notification sent to a task can optionally perform an action, such as 2035 * update, overwrite or increment the task's notification value. In that way 2036 * task notifications can be used to send data to a task, or be used as light 2037 * weight and fast binary or counting semaphores. 2038 * 2039 * A notification sent to a task will remain pending until it is cleared by the 2040 * task calling xTaskNotifyWait() or ulTaskNotifyTake(). If the task was 2041 * already in the Blocked state to wait for a notification when the notification 2042 * arrives then the task will automatically be removed from the Blocked state 2043 * (unblocked) and the notification cleared. 2044 * 2045 * A task can use xTaskNotifyWait() to [optionally] block to wait for a 2046 * notification to be pending, or ulTaskNotifyTake() to [optionally] block 2047 * to wait for its notification value to have a non-zero value. The task does 2048 * not consume any CPU time while it is in the Blocked state. 2049 * 2050 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details. 2051 * 2052 * @param ulBitsToClearOnEntry Bits that are set in ulBitsToClearOnEntry value 2053 * will be cleared in the calling task's notification value before the task 2054 * checks to see if any notifications are pending, and optionally blocks if no 2055 * notifications are pending. Setting ulBitsToClearOnEntry to ULONG_MAX (if 2056 * limits.h is included) or 0xffffffffUL (if limits.h is not included) will have 2057 * the effect of resetting the task's notification value to 0. Setting 2058 * ulBitsToClearOnEntry to 0 will leave the task's notification value unchanged. 2059 * 2060 * @param ulBitsToClearOnExit If a notification is pending or received before 2061 * the calling task exits the xTaskNotifyWait() function then the task's 2062 * notification value (see the xTaskNotify() API function) is passed out using 2063 * the pulNotificationValue parameter. Then any bits that are set in 2064 * ulBitsToClearOnExit will be cleared in the task's notification value (note 2065 * *pulNotificationValue is set before any bits are cleared). Setting 2066 * ulBitsToClearOnExit to ULONG_MAX (if limits.h is included) or 0xffffffffUL 2067 * (if limits.h is not included) will have the effect of resetting the task's 2068 * notification value to 0 before the function exits. Setting 2069 * ulBitsToClearOnExit to 0 will leave the task's notification value unchanged 2070 * when the function exits (in which case the value passed out in 2071 * pulNotificationValue will match the task's notification value). 2072 * 2073 * @param pulNotificationValue Used to pass the task's notification value out 2074 * of the function. Note the value passed out will not be effected by the 2075 * clearing of any bits caused by ulBitsToClearOnExit being non-zero. 2076 * 2077 * @param xTicksToWait The maximum amount of time that the task should wait in 2078 * the Blocked state for a notification to be received, should a notification 2079 * not already be pending when xTaskNotifyWait() was called. The task 2080 * will not consume any processing time while it is in the Blocked state. This 2081 * is specified in kernel ticks, the macro pdMS_TO_TICSK( value_in_ms ) can be 2082 * used to convert a time specified in milliseconds to a time specified in 2083 * ticks. 2084 * 2085 * @return If a notification was received (including notifications that were 2086 * already pending when xTaskNotifyWait was called) then pdPASS is 2087 * returned. Otherwise pdFAIL is returned. 2088 * 2089 * \ingroup TaskNotifications 2090 */ 2091 BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; 2092 2093 /** 2094 * Simplified macro for sending task notification. 2095 * 2096 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro 2097 * to be available. 2098 * 2099 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private 2100 * "notification value", which is a 32-bit unsigned integer (uint32_t). 2101 * 2102 * Events can be sent to a task using an intermediary object. Examples of such 2103 * objects are queues, semaphores, mutexes and event groups. Task notifications 2104 * are a method of sending an event directly to a task without the need for such 2105 * an intermediary object. 2106 * 2107 * A notification sent to a task can optionally perform an action, such as 2108 * update, overwrite or increment the task's notification value. In that way 2109 * task notifications can be used to send data to a task, or be used as light 2110 * weight and fast binary or counting semaphores. 2111 * 2112 * xTaskNotifyGive() is a helper macro intended for use when task notifications 2113 * are used as light weight and faster binary or counting semaphore equivalents. 2114 * Actual FreeRTOS semaphores are given using the xSemaphoreGive() API function, 2115 * the equivalent action that instead uses a task notification is 2116 * xTaskNotifyGive(). 2117 * 2118 * When task notifications are being used as a binary or counting semaphore 2119 * equivalent then the task being notified should wait for the notification 2120 * using the ulTaskNotificationTake() API function rather than the 2121 * xTaskNotifyWait() API function. 2122 * 2123 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for more details. 2124 * 2125 * @param xTaskToNotify The handle of the task being notified. The handle to a 2126 * task can be returned from the xTaskCreate() API function used to create the 2127 * task, and the handle of the currently running task can be obtained by calling 2128 * xTaskGetCurrentTaskHandle(). 2129 * 2130 * @return xTaskNotifyGive() is a macro that calls xTaskNotify() with the 2131 * eAction parameter set to eIncrement - so pdPASS is always returned. 2132 * 2133 * \ingroup TaskNotifications 2134 */ 2135 #define xTaskNotifyGive( xTaskToNotify ) xTaskGenericNotify( ( xTaskToNotify ), ( 0 ), eIncrement, NULL ) 2136 2137 /** 2138 * Simplified macro for sending task notification from ISR. 2139 * 2140 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro 2141 * to be available. 2142 * 2143 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private 2144 * "notification value", which is a 32-bit unsigned integer (uint32_t). 2145 * 2146 * A version of xTaskNotifyGive() that can be called from an interrupt service 2147 * routine (ISR). 2148 * 2149 * Events can be sent to a task using an intermediary object. Examples of such 2150 * objects are queues, semaphores, mutexes and event groups. Task notifications 2151 * are a method of sending an event directly to a task without the need for such 2152 * an intermediary object. 2153 * 2154 * A notification sent to a task can optionally perform an action, such as 2155 * update, overwrite or increment the task's notification value. In that way 2156 * task notifications can be used to send data to a task, or be used as light 2157 * weight and fast binary or counting semaphores. 2158 * 2159 * vTaskNotifyGiveFromISR() is intended for use when task notifications are 2160 * used as light weight and faster binary or counting semaphore equivalents. 2161 * Actual FreeRTOS semaphores are given from an ISR using the 2162 * xSemaphoreGiveFromISR() API function, the equivalent action that instead uses 2163 * a task notification is vTaskNotifyGiveFromISR(). 2164 * 2165 * When task notifications are being used as a binary or counting semaphore 2166 * equivalent then the task being notified should wait for the notification 2167 * using the ulTaskNotificationTake() API function rather than the 2168 * xTaskNotifyWait() API function. 2169 * 2170 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for more details. 2171 * 2172 * @param xTaskToNotify The handle of the task being notified. The handle to a 2173 * task can be returned from the xTaskCreate() API function used to create the 2174 * task, and the handle of the currently running task can be obtained by calling 2175 * xTaskGetCurrentTaskHandle(). 2176 * 2177 * @param pxHigherPriorityTaskWoken vTaskNotifyGiveFromISR() will set 2178 * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the 2179 * task to which the notification was sent to leave the Blocked state, and the 2180 * unblocked task has a priority higher than the currently running task. If 2181 * vTaskNotifyGiveFromISR() sets this value to pdTRUE then a context switch 2182 * should be requested before the interrupt is exited. How a context switch is 2183 * requested from an ISR is dependent on the port - see the documentation page 2184 * for the port in use. 2185 * 2186 * \ingroup TaskNotifications 2187 */ 2188 void vTaskNotifyGiveFromISR( TaskHandle_t xTaskToNotify, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; 2189 2190 /** 2191 * Simplified macro for receiving task notification. 2192 * 2193 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this 2194 * function to be available. 2195 * 2196 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private 2197 * "notification value", which is a 32-bit unsigned integer (uint32_t). 2198 * 2199 * Events can be sent to a task using an intermediary object. Examples of such 2200 * objects are queues, semaphores, mutexes and event groups. Task notifications 2201 * are a method of sending an event directly to a task without the need for such 2202 * an intermediary object. 2203 * 2204 * A notification sent to a task can optionally perform an action, such as 2205 * update, overwrite or increment the task's notification value. In that way 2206 * task notifications can be used to send data to a task, or be used as light 2207 * weight and fast binary or counting semaphores. 2208 * 2209 * ulTaskNotifyTake() is intended for use when a task notification is used as a 2210 * faster and lighter weight binary or counting semaphore alternative. Actual 2211 * FreeRTOS semaphores are taken using the xSemaphoreTake() API function, the 2212 * equivalent action that instead uses a task notification is 2213 * ulTaskNotifyTake(). 2214 * 2215 * When a task is using its notification value as a binary or counting semaphore 2216 * other tasks should send notifications to it using the xTaskNotifyGive() 2217 * macro, or xTaskNotify() function with the eAction parameter set to 2218 * eIncrement. 2219 * 2220 * ulTaskNotifyTake() can either clear the task's notification value to 2221 * zero on exit, in which case the notification value acts like a binary 2222 * semaphore, or decrement the task's notification value on exit, in which case 2223 * the notification value acts like a counting semaphore. 2224 * 2225 * A task can use ulTaskNotifyTake() to [optionally] block to wait for a 2226 * the task's notification value to be non-zero. The task does not consume any 2227 * CPU time while it is in the Blocked state. 2228 * 2229 * Where as xTaskNotifyWait() will return when a notification is pending, 2230 * ulTaskNotifyTake() will return when the task's notification value is 2231 * not zero. 2232 * 2233 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details. 2234 * 2235 * @param xClearCountOnExit if xClearCountOnExit is pdFALSE then the task's 2236 * notification value is decremented when the function exits. In this way the 2237 * notification value acts like a counting semaphore. If xClearCountOnExit is 2238 * not pdFALSE then the task's notification value is cleared to zero when the 2239 * function exits. In this way the notification value acts like a binary 2240 * semaphore. 2241 * 2242 * @param xTicksToWait The maximum amount of time that the task should wait in 2243 * the Blocked state for the task's notification value to be greater than zero, 2244 * should the count not already be greater than zero when 2245 * ulTaskNotifyTake() was called. The task will not consume any processing 2246 * time while it is in the Blocked state. This is specified in kernel ticks, 2247 * the macro pdMS_TO_TICSK( value_in_ms ) can be used to convert a time 2248 * specified in milliseconds to a time specified in ticks. 2249 * 2250 * @return The task's notification count before it is either cleared to zero or 2251 * decremented (see the xClearCountOnExit parameter). 2252 * 2253 * \ingroup TaskNotifications 2254 */ 2255 uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; 2256 2257 /** 2258 * 2259 * If the notification state of the task referenced by the handle xTask is 2260 * eNotified, then set the task's notification state to eNotWaitingNotification. 2261 * The task's notification value is not altered. Set xTask to NULL to clear the 2262 * notification state of the calling task. 2263 * 2264 * @return pdTRUE if the task's notification state was set to 2265 * eNotWaitingNotification, otherwise pdFALSE. 2266 * 2267 * \ingroup TaskNotifications 2268 */ 2269 BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask ); 2270 2271 /*----------------------------------------------------------- 2272 * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES 2273 *----------------------------------------------------------*/ 2274 /** @cond */ 2275 /* 2276 * Return the handle of the task running on a certain CPU. Because of 2277 * the nature of SMP processing, there is no guarantee that this 2278 * value will still be valid on return and should only be used for 2279 * debugging purposes. 2280 */ 2281 TaskHandle_t xTaskGetCurrentTaskHandleForCPU( BaseType_t cpuid ); 2282 2283 /** 2284 * Get the handle of idle task for the given CPU. 2285 * 2286 * xTaskGetIdleTaskHandleForCPU() is only available if 2287 * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h. 2288 * 2289 * @param cpuid The CPU to get the handle for 2290 * 2291 * @return Idle task handle of a given cpu. It is not valid to call 2292 * xTaskGetIdleTaskHandleForCPU() before the scheduler has been started. 2293 */ 2294 TaskHandle_t xTaskGetIdleTaskHandleForCPU( UBaseType_t cpuid ); 2295 2296 2297 /* 2298 * Get the current core affinity of a task 2299 */ 2300 BaseType_t xTaskGetAffinity( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; 2301 2302 /* 2303 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY 2304 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS 2305 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. 2306 * 2307 * Called from the real time kernel tick (either preemptive or cooperative), 2308 * this increments the tick count and checks if any tasks that are blocked 2309 * for a finite period required removing from a blocked list and placing on 2310 * a ready list. If a non-zero value is returned then a context switch is 2311 * required because either: 2312 * + A task was removed from a blocked list because its timeout had expired, 2313 * or 2314 * + Time slicing is in use and there is a task of equal priority to the 2315 * currently running task. 2316 */ 2317 BaseType_t xTaskIncrementTick( void ) PRIVILEGED_FUNCTION; 2318 2319 /* 2320 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN 2321 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. 2322 * 2323 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED. 2324 * 2325 * Removes the calling task from the ready list and places it both 2326 * on the list of tasks waiting for a particular event, and the 2327 * list of delayed tasks. The task will be removed from both lists 2328 * and replaced on the ready list should either the event occur (and 2329 * there be no higher priority tasks waiting on the same event) or 2330 * the delay period expires. 2331 * 2332 * The 'unordered' version replaces the event list item value with the 2333 * xItemValue value, and inserts the list item at the end of the list. 2334 * 2335 * The 'ordered' version uses the existing event list item value (which is the 2336 * owning tasks priority) to insert the list item into the event list is task 2337 * priority order. 2338 * 2339 * @param pxEventList The list containing tasks that are blocked waiting 2340 * for the event to occur. 2341 * 2342 * @param xItemValue The item value to use for the event list item when the 2343 * event list is not ordered by task priority. 2344 * 2345 * @param xTicksToWait The maximum amount of time that the task should wait 2346 * for the event to occur. This is specified in kernel ticks,the constant 2347 * portTICK_PERIOD_MS can be used to convert kernel ticks into a real time 2348 * period. 2349 */ 2350 void vTaskPlaceOnEventList( List_t * const pxEventList, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; 2351 void vTaskPlaceOnUnorderedEventList( List_t * pxEventList, const TickType_t xItemValue, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; 2352 2353 /* 2354 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN 2355 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. 2356 * 2357 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED. 2358 * 2359 * This function performs nearly the same function as vTaskPlaceOnEventList(). 2360 * The difference being that this function does not permit tasks to block 2361 * indefinitely, whereas vTaskPlaceOnEventList() does. 2362 * 2363 */ 2364 void vTaskPlaceOnEventListRestricted( List_t * const pxEventList, TickType_t xTicksToWait, const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION; 2365 2366 /* 2367 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN 2368 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. 2369 * 2370 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED. 2371 * 2372 * Removes a task from both the specified event list and the list of blocked 2373 * tasks, and places it on a ready queue. 2374 * 2375 * xTaskRemoveFromEventList()/vTaskRemoveFromUnorderedEventList() will be called 2376 * if either an event occurs to unblock a task, or the block timeout period 2377 * expires. 2378 * 2379 * xTaskRemoveFromEventList() is used when the event list is in task priority 2380 * order. It removes the list item from the head of the event list as that will 2381 * have the highest priority owning task of all the tasks on the event list. 2382 * vTaskRemoveFromUnorderedEventList() is used when the event list is not 2383 * ordered and the event list items hold something other than the owning tasks 2384 * priority. In this case the event list item value is updated to the value 2385 * passed in the xItemValue parameter. 2386 * 2387 * @return pdTRUE if the task being removed has a higher priority than the task 2388 * making the call, otherwise pdFALSE. 2389 */ 2390 BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList ) PRIVILEGED_FUNCTION; 2391 BaseType_t xTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem, const TickType_t xItemValue ) PRIVILEGED_FUNCTION; 2392 2393 /* 2394 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY 2395 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS 2396 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. 2397 * 2398 * Sets the pointer to the current TCB to the TCB of the highest priority task 2399 * that is ready to run. 2400 */ 2401 void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION; 2402 2403 /* 2404 * THESE FUNCTIONS MUST NOT BE USED FROM APPLICATION CODE. THEY ARE USED BY 2405 * THE EVENT BITS MODULE. 2406 */ 2407 TickType_t uxTaskResetEventItemValue( void ) PRIVILEGED_FUNCTION; 2408 2409 /* 2410 * Return the handle of the calling task. 2411 */ 2412 TaskHandle_t xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION; 2413 2414 /* 2415 * Capture the current time status for future reference. 2416 */ 2417 void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION; 2418 2419 /* 2420 * Compare the time status now with that previously captured to see if the 2421 * timeout has expired. 2422 */ 2423 BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait ) PRIVILEGED_FUNCTION; 2424 2425 /* 2426 * Shortcut used by the queue implementation to prevent unnecessary call to 2427 * taskYIELD(); 2428 */ 2429 void vTaskMissedYield( void ) PRIVILEGED_FUNCTION; 2430 2431 /* 2432 * Returns the scheduler state as taskSCHEDULER_RUNNING, 2433 * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED. 2434 */ 2435 BaseType_t xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION; 2436 2437 /* 2438 * Raises the priority of the mutex holder to that of the calling task should 2439 * the mutex holder have a priority less than the calling task. 2440 */ 2441 BaseType_t xTaskPriorityInherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION; 2442 2443 /* 2444 * Set the priority of a task back to its proper priority in the case that it 2445 * inherited a higher priority while it was holding a semaphore. 2446 */ 2447 BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION; 2448 2449 /* 2450 * If a higher priority task attempting to obtain a mutex caused a lower 2451 * priority task to inherit the higher priority task's priority - but the higher 2452 * priority task then timed out without obtaining the mutex, then the lower 2453 * priority task will disinherit the priority again - but only down as far as 2454 * the highest priority task that is still waiting for the mutex (if there were 2455 * more than one task waiting for the mutex). 2456 */ 2457 void vTaskPriorityDisinheritAfterTimeout( TaskHandle_t const pxMutexHolder, UBaseType_t uxHighestPriorityWaitingTask ) PRIVILEGED_FUNCTION; 2458 2459 /* 2460 * Get the uxTCBNumber assigned to the task referenced by the xTask parameter. 2461 */ 2462 UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; 2463 2464 /* 2465 * Get the current core affinity of a task 2466 */ 2467 BaseType_t xTaskGetAffinity( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; 2468 2469 /* 2470 * Set the uxTaskNumber of the task referenced by the xTask parameter to 2471 * uxHandle. 2472 */ 2473 void vTaskSetTaskNumber( TaskHandle_t xTask, const UBaseType_t uxHandle ) PRIVILEGED_FUNCTION; 2474 2475 /* 2476 * Only available when configUSE_TICKLESS_IDLE is set to 1. 2477 * If tickless mode is being used, or a low power mode is implemented, then 2478 * the tick interrupt will not execute during idle periods. When this is the 2479 * case, the tick count value maintained by the scheduler needs to be kept up 2480 * to date with the actual execution time by being skipped forward by a time 2481 * equal to the idle period. 2482 */ 2483 void vTaskStepTick( const TickType_t xTicksToJump ) PRIVILEGED_FUNCTION; 2484 2485 /* Correct the tick count value after the application code has held 2486 interrupts disabled for an extended period. xTicksToCatchUp is the number 2487 of tick interrupts that have been missed due to interrupts being disabled. 2488 Its value is not computed automatically, so must be computed by the 2489 application writer. 2490 2491 This function is similar to vTaskStepTick(), however, unlike 2492 vTaskStepTick(), xTaskCatchUpTicks() may move the tick count forward past a 2493 time at which a task should be removed from the blocked state. That means 2494 tasks may have to be removed from the blocked state as the tick count is 2495 moved. */ 2496 BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp ) PRIVILEGED_FUNCTION; 2497 2498 /* 2499 * Only available when configUSE_TICKLESS_IDLE is set to 1. 2500 * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port 2501 * specific sleep function to determine if it is ok to proceed with the sleep, 2502 * and if it is ok to proceed, if it is ok to sleep indefinitely. 2503 * 2504 * This function is necessary because portSUPPRESS_TICKS_AND_SLEEP() is only 2505 * called with the scheduler suspended, not from within a critical section. It 2506 * is therefore possible for an interrupt to request a context switch between 2507 * portSUPPRESS_TICKS_AND_SLEEP() and the low power mode actually being 2508 * entered. eTaskConfirmSleepModeStatus() should be called from a short 2509 * critical section between the timer being stopped and the sleep mode being 2510 * entered to ensure it is ok to proceed into the sleep mode. 2511 */ 2512 eSleepModeStatus eTaskConfirmSleepModeStatus( void ) PRIVILEGED_FUNCTION; 2513 2514 /* 2515 * For internal use only. Increment the mutex held count when a mutex is 2516 * taken and return the handle of the task that has taken the mutex. 2517 */ 2518 TaskHandle_t pvTaskIncrementMutexHeldCount( void ) PRIVILEGED_FUNCTION; 2519 2520 /* 2521 * For internal use only. Same as vTaskSetTimeOutState(), but without a critial 2522 * section. 2523 */ 2524 void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION; 2525 2526 /* 2527 * This function fills array with TaskSnapshot_t structures for every task in the system. 2528 * Used by core dump facility to get snapshots of all tasks in the system. 2529 * Only available when configENABLE_TASK_SNAPSHOT is set to 1. 2530 * @param pxTaskSnapshotArray Pointer to array of TaskSnapshot_t structures to store tasks snapshot data. 2531 * @param uxArraySize Size of tasks snapshots array. 2532 * @param pxTcbSz Pointer to store size of TCB. 2533 * @return Number of elements stored in array. 2534 */ 2535 UBaseType_t uxTaskGetSnapshotAll( TaskSnapshot_t * const pxTaskSnapshotArray, const UBaseType_t uxArraySize, UBaseType_t * const pxTcbSz ); 2536 2537 /** @endcond */ 2538 #ifdef __cplusplus 2539 } 2540 #endif 2541 #endif /* INC_TASK_H */ 2542 2543 2544