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