2 * FreeRTOS Kernel V10.0.1
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * http://www.FreeRTOS.org
23 * http://aws.amazon.com/freertos
32 #ifndef INC_FREERTOS_H
33 #error "include FreeRTOS.h must appear in source files before include task.h"
42 /*-----------------------------------------------------------
43 * MACROS AND DEFINITIONS
44 *----------------------------------------------------------*/
46 #define tskKERNEL_VERSION_NUMBER "V10.0.1"
47 #define tskKERNEL_VERSION_MAJOR 10
48 #define tskKERNEL_VERSION_MINOR 0
49 #define tskKERNEL_VERSION_BUILD 1
54 * Type by which tasks are referenced. For example, a call to xTaskCreate
55 * returns (via a pointer parameter) an TaskHandle_t variable that can then
56 * be used as a parameter to vTaskDelete to delete the task.
58 * \defgroup TaskHandle_t TaskHandle_t
61 typedef void * TaskHandle_t;
64 * Defines the prototype to which the application task hook function must
67 typedef BaseType_t (*TaskHookFunction_t)( void * );
69 /* Task states returned by eTaskGetState. */
72 eRunning = 0, /* A task is querying the state of itself, so must be running. */
73 eReady, /* The task being queried is in a read or pending ready list. */
74 eBlocked, /* The task being queried is in the Blocked state. */
75 eSuspended, /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */
76 eDeleted, /* The task being queried has been deleted, but its TCB has not yet been freed. */
77 eInvalid /* Used as an 'invalid state' value. */
80 /* Actions that can be performed when vTaskNotify() is called. */
83 eNoAction = 0, /* Notify the task without updating its notify value. */
84 eSetBits, /* Set bits in the task's notification value. */
85 eIncrement, /* Increment the task's notification value. */
86 eSetValueWithOverwrite, /* Set the task's notification value to a specific value even if the previous value has not yet been read by the task. */
87 eSetValueWithoutOverwrite /* Set the task's notification value if the previous value has been read by the task. */
91 * Used internally only.
93 typedef struct xTIME_OUT
95 BaseType_t xOverflowCount;
96 TickType_t xTimeOnEntering;
100 * Defines the memory ranges allocated to the task when an MPU is used.
102 typedef struct xMEMORY_REGION
105 uint32_t ulLengthInBytes;
106 uint32_t ulParameters;
110 * Parameters required to create an MPU protected task.
112 typedef struct xTASK_PARAMETERS
114 TaskFunction_t pvTaskCode;
115 const char * const pcName; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
116 uint16_t usStackDepth;
118 UBaseType_t uxPriority;
119 StackType_t *puxStackBuffer;
120 MemoryRegion_t xRegions[ portNUM_CONFIGURABLE_REGIONS ];
121 #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
122 StaticTask_t * const pxTaskBuffer;
126 /* Used with the uxTaskGetSystemState() function to return the state of each task
128 typedef struct xTASK_STATUS
130 TaskHandle_t xHandle; /* The handle of the task to which the rest of the information in the structure relates. */
131 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. */
132 UBaseType_t xTaskNumber; /* A number unique to the task. */
133 eTaskState eCurrentState; /* The state in which the task existed when the structure was populated. */
134 UBaseType_t uxCurrentPriority; /* The priority at which the task was running (may be inherited) when the structure was populated. */
135 UBaseType_t uxBasePriority; /* The priority to which the task will return if the task's current priority has been inherited to avoid unbounded priority inversion when obtaining a mutex. Only valid if configUSE_MUTEXES is defined as 1 in FreeRTOSConfig.h. */
136 uint32_t ulRunTimeCounter; /* The total run time allocated to the task so far, as defined by the run time stats clock. See http://www.freertos.org/rtos-run-time-stats.html. Only valid when configGENERATE_RUN_TIME_STATS is defined as 1 in FreeRTOSConfig.h. */
137 StackType_t *pxStackBase; /* Points to the lowest address of the task's stack area. */
138 uint16_t usStackHighWaterMark; /* The minimum amount of stack space that has remained for the task since the task was created. The closer this value is to zero the closer the task has come to overflowing its stack. */
141 /* Possible return values for eTaskConfirmSleepModeStatus(). */
144 eAbortSleep = 0, /* A task has been made ready or a context switch pended since portSUPPORESS_TICKS_AND_SLEEP() was called - abort entering a sleep mode. */
145 eStandardSleep, /* Enter a sleep mode that will not last any longer than the expected idle time. */
146 eNoTasksWaitingTimeout /* No tasks are waiting for a timeout so it is safe to enter a sleep mode that can only be exited by an external interrupt. */
150 * Defines the priority used by the idle task. This must not be modified.
154 #define tskIDLE_PRIORITY ( ( UBaseType_t ) 0U )
159 * Macro for forcing a context switch.
161 * \defgroup taskYIELD taskYIELD
162 * \ingroup SchedulerControl
164 #define taskYIELD() portYIELD()
169 * Macro to mark the start of a critical code region. Preemptive context
170 * switches cannot occur when in a critical region.
172 * NOTE: This may alter the stack (depending on the portable implementation)
173 * so must be used with care!
175 * \defgroup taskENTER_CRITICAL taskENTER_CRITICAL
176 * \ingroup SchedulerControl
178 #define taskENTER_CRITICAL() portENTER_CRITICAL()
179 #define taskENTER_CRITICAL_FROM_ISR() portSET_INTERRUPT_MASK_FROM_ISR()
184 * Macro to mark the end of a critical code region. Preemptive context
185 * switches cannot occur when in a critical region.
187 * NOTE: This may alter the stack (depending on the portable implementation)
188 * so must be used with care!
190 * \defgroup taskEXIT_CRITICAL taskEXIT_CRITICAL
191 * \ingroup SchedulerControl
193 #define taskEXIT_CRITICAL() portEXIT_CRITICAL()
194 #define taskEXIT_CRITICAL_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( x )
198 * Macro to disable all maskable interrupts.
200 * \defgroup taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS
201 * \ingroup SchedulerControl
203 #define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS()
208 * Macro to enable microcontroller interrupts.
210 * \defgroup taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS
211 * \ingroup SchedulerControl
213 #define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS()
215 /* Definitions returned by xTaskGetSchedulerState(). taskSCHEDULER_SUSPENDED is
216 0 to generate more optimal code when configASSERT() is defined as the constant
217 is used in assert() statements. */
218 #define taskSCHEDULER_SUSPENDED ( ( BaseType_t ) 0 )
219 #define taskSCHEDULER_NOT_STARTED ( ( BaseType_t ) 1 )
220 #define taskSCHEDULER_RUNNING ( ( BaseType_t ) 2 )
223 /*-----------------------------------------------------------
225 *----------------------------------------------------------*/
230 BaseType_t xTaskCreate(
231 TaskFunction_t pvTaskCode,
232 const char * const pcName,
233 configSTACK_DEPTH_TYPE usStackDepth,
235 UBaseType_t uxPriority,
236 TaskHandle_t *pvCreatedTask
239 * Create a new task and add it to the list of tasks that are ready to run.
241 * Internally, within the FreeRTOS implementation, tasks use two blocks of
242 * memory. The first block is used to hold the task's data structures. The
243 * second block is used by the task as its stack. If a task is created using
244 * xTaskCreate() then both blocks of memory are automatically dynamically
245 * allocated inside the xTaskCreate() function. (see
246 * http://www.freertos.org/a00111.html). If a task is created using
247 * xTaskCreateStatic() then the application writer must provide the required
248 * memory. xTaskCreateStatic() therefore allows a task to be created without
249 * using any dynamic memory allocation.
251 * See xTaskCreateStatic() for a version that does not use any dynamic memory
254 * xTaskCreate() can only be used to create a task that has unrestricted
255 * access to the entire microcontroller memory map. Systems that include MPU
256 * support can alternatively create an MPU constrained task using
257 * xTaskCreateRestricted().
259 * @param pvTaskCode Pointer to the task entry function. Tasks
260 * must be implemented to never return (i.e. continuous loop).
262 * @param pcName A descriptive name for the task. This is mainly used to
263 * facilitate debugging. Max length defined by configMAX_TASK_NAME_LEN - default
266 * @param usStackDepth The size of the task stack specified as the number of
267 * variables the stack can hold - not the number of bytes. For example, if
268 * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
269 * will be allocated for stack storage.
271 * @param pvParameters Pointer that will be used as the parameter for the task
274 * @param uxPriority The priority at which the task should run. Systems that
275 * include MPU support can optionally create tasks in a privileged (system)
276 * mode by setting bit portPRIVILEGE_BIT of the priority parameter. For
277 * example, to create a privileged task at priority 2 the uxPriority parameter
278 * should be set to ( 2 | portPRIVILEGE_BIT ).
280 * @param pvCreatedTask Used to pass back a handle by which the created task
283 * @return pdPASS if the task was successfully created and added to a ready
284 * list, otherwise an error code defined in the file projdefs.h
288 // Task to be created.
289 void vTaskCode( void * pvParameters )
293 // Task code goes here.
297 // Function that creates a task.
298 void vOtherFunction( void )
300 static uint8_t ucParameterToPass;
301 TaskHandle_t xHandle = NULL;
303 // Create the task, storing the handle. Note that the passed parameter ucParameterToPass
304 // must exist for the lifetime of the task, so in this case is declared static. If it was just an
305 // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
306 // the new task attempts to access it.
307 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
308 configASSERT( xHandle );
310 // Use the handle to delete the task.
311 if( xHandle != NULL )
313 vTaskDelete( xHandle );
317 * \defgroup xTaskCreate xTaskCreate
320 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
321 BaseType_t xTaskCreate( TaskFunction_t pxTaskCode,
322 const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
323 const configSTACK_DEPTH_TYPE usStackDepth,
324 void * const pvParameters,
325 UBaseType_t uxPriority,
326 TaskHandle_t * const pxCreatedTask ) PRIVILEGED_FUNCTION;
332 TaskHandle_t xTaskCreateStatic( TaskFunction_t pvTaskCode,
333 const char * const pcName,
334 uint32_t ulStackDepth,
336 UBaseType_t uxPriority,
337 StackType_t *pxStackBuffer,
338 StaticTask_t *pxTaskBuffer );</pre>
340 * Create a new task and add it to the list of tasks that are ready to run.
342 * Internally, within the FreeRTOS implementation, tasks use two blocks of
343 * memory. The first block is used to hold the task's data structures. The
344 * second block is used by the task as its stack. If a task is created using
345 * xTaskCreate() then both blocks of memory are automatically dynamically
346 * allocated inside the xTaskCreate() function. (see
347 * http://www.freertos.org/a00111.html). If a task is created using
348 * xTaskCreateStatic() then the application writer must provide the required
349 * memory. xTaskCreateStatic() therefore allows a task to be created without
350 * using any dynamic memory allocation.
352 * @param pvTaskCode Pointer to the task entry function. Tasks
353 * must be implemented to never return (i.e. continuous loop).
355 * @param pcName A descriptive name for the task. This is mainly used to
356 * facilitate debugging. The maximum length of the string is defined by
357 * configMAX_TASK_NAME_LEN in FreeRTOSConfig.h.
359 * @param ulStackDepth The size of the task stack specified as the number of
360 * variables the stack can hold - not the number of bytes. For example, if
361 * the stack is 32-bits wide and ulStackDepth is defined as 100 then 400 bytes
362 * will be allocated for stack storage.
364 * @param pvParameters Pointer that will be used as the parameter for the task
367 * @param uxPriority The priority at which the task will run.
369 * @param pxStackBuffer Must point to a StackType_t array that has at least
370 * ulStackDepth indexes - the array will then be used as the task's stack,
371 * removing the need for the stack to be allocated dynamically.
373 * @param pxTaskBuffer Must point to a variable of type StaticTask_t, which will
374 * then be used to hold the task's data structures, removing the need for the
375 * memory to be allocated dynamically.
377 * @return If neither pxStackBuffer or pxTaskBuffer are NULL, then the task will
378 * be created and pdPASS is returned. If either pxStackBuffer or pxTaskBuffer
379 * are NULL then the task will not be created and
380 * errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY is returned.
385 // Dimensions the buffer that the task being created will use as its stack.
386 // NOTE: This is the number of words the stack will hold, not the number of
387 // bytes. For example, if each stack item is 32-bits, and this is set to 100,
388 // then 400 bytes (100 * 32-bits) will be allocated.
389 #define STACK_SIZE 200
391 // Structure that will hold the TCB of the task being created.
392 StaticTask_t xTaskBuffer;
394 // Buffer that the task being created will use as its stack. Note this is
395 // an array of StackType_t variables. The size of StackType_t is dependent on
397 StackType_t xStack[ STACK_SIZE ];
399 // Function that implements the task being created.
400 void vTaskCode( void * pvParameters )
402 // The parameter value is expected to be 1 as 1 is passed in the
403 // pvParameters value in the call to xTaskCreateStatic().
404 configASSERT( ( uint32_t ) pvParameters == 1UL );
408 // Task code goes here.
412 // Function that creates a task.
413 void vOtherFunction( void )
415 TaskHandle_t xHandle = NULL;
417 // Create the task without using any dynamic memory allocation.
418 xHandle = xTaskCreateStatic(
419 vTaskCode, // Function that implements the task.
420 "NAME", // Text name for the task.
421 STACK_SIZE, // Stack size in words, not bytes.
422 ( void * ) 1, // Parameter passed into the task.
423 tskIDLE_PRIORITY,// Priority at which the task is created.
424 xStack, // Array to use as the task's stack.
425 &xTaskBuffer ); // Variable to hold the task's data structure.
427 // puxStackBuffer and pxTaskBuffer were not NULL, so the task will have
428 // been created, and xHandle will be the task's handle. Use the handle
429 // to suspend the task.
430 vTaskSuspend( xHandle );
433 * \defgroup xTaskCreateStatic xTaskCreateStatic
436 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
437 TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,
438 const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
439 const uint32_t ulStackDepth,
440 void * const pvParameters,
441 UBaseType_t uxPriority,
442 StackType_t * const puxStackBuffer,
443 StaticTask_t * const pxTaskBuffer ) PRIVILEGED_FUNCTION;
444 #endif /* configSUPPORT_STATIC_ALLOCATION */
449 BaseType_t xTaskCreateRestricted( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );</pre>
451 * Only available when configSUPPORT_DYNAMIC_ALLOCATION is set to 1.
453 * xTaskCreateRestricted() should only be used in systems that include an MPU
456 * Create a new task and add it to the list of tasks that are ready to run.
457 * The function parameters define the memory regions and associated access
458 * permissions allocated to the task.
460 * See xTaskCreateRestrictedStatic() for a version that does not use any
461 * dynamic memory allocation.
463 * @param pxTaskDefinition Pointer to a structure that contains a member
464 * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API
465 * documentation) plus an optional stack buffer and the memory region
468 * @param pxCreatedTask Used to pass back a handle by which the created task
471 * @return pdPASS if the task was successfully created and added to a ready
472 * list, otherwise an error code defined in the file projdefs.h
476 // Create an TaskParameters_t structure that defines the task to be created.
477 static const TaskParameters_t xCheckTaskParameters =
479 vATask, // pvTaskCode - the function that implements the task.
480 "ATask", // pcName - just a text name for the task to assist debugging.
481 100, // usStackDepth - the stack size DEFINED IN WORDS.
482 NULL, // pvParameters - passed into the task function as the function parameters.
483 ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
484 cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
486 // xRegions - Allocate up to three separate memory regions for access by
487 // the task, with appropriate access permissions. Different processors have
488 // different memory alignment requirements - refer to the FreeRTOS documentation
489 // for full information.
491 // Base address Length Parameters
492 { cReadWriteArray, 32, portMPU_REGION_READ_WRITE },
493 { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY },
494 { cPrivilegedOnlyAccessArray, 128, portMPU_REGION_PRIVILEGED_READ_WRITE }
500 TaskHandle_t xHandle;
502 // Create a task from the const structure defined above. The task handle
503 // is requested (the second parameter is not NULL) but in this case just for
504 // demonstration purposes as its not actually used.
505 xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
507 // Start the scheduler.
508 vTaskStartScheduler();
510 // Will only get here if there was insufficient memory to create the idle
511 // and/or timer task.
515 * \defgroup xTaskCreateRestricted xTaskCreateRestricted
518 #if( portUSING_MPU_WRAPPERS == 1 )
519 BaseType_t xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ) PRIVILEGED_FUNCTION;
525 BaseType_t xTaskCreateRestrictedStatic( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );</pre>
527 * Only available when configSUPPORT_STATIC_ALLOCATION is set to 1.
529 * xTaskCreateRestrictedStatic() should only be used in systems that include an
530 * MPU implementation.
532 * Internally, within the FreeRTOS implementation, tasks use two blocks of
533 * memory. The first block is used to hold the task's data structures. The
534 * second block is used by the task as its stack. If a task is created using
535 * xTaskCreateRestricted() then the stack is provided by the application writer,
536 * and the memory used to hold the task's data structure is automatically
537 * dynamically allocated inside the xTaskCreateRestricted() function. If a task
538 * is created using xTaskCreateRestrictedStatic() then the application writer
539 * must provide the memory used to hold the task's data structures too.
540 * xTaskCreateRestrictedStatic() therefore allows a memory protected task to be
541 * created without using any dynamic memory allocation.
543 * @param pxTaskDefinition Pointer to a structure that contains a member
544 * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API
545 * documentation) plus an optional stack buffer and the memory region
546 * definitions. If configSUPPORT_STATIC_ALLOCATION is set to 1 the structure
547 * contains an additional member, which is used to point to a variable of type
548 * StaticTask_t - which is then used to hold the task's data structure.
550 * @param pxCreatedTask Used to pass back a handle by which the created task
553 * @return pdPASS if the task was successfully created and added to a ready
554 * list, otherwise an error code defined in the file projdefs.h
558 // Create an TaskParameters_t structure that defines the task to be created.
559 // The StaticTask_t variable is only included in the structure when
560 // configSUPPORT_STATIC_ALLOCATION is set to 1. The PRIVILEGED_DATA macro can
561 // be used to force the variable into the RTOS kernel's privileged data area.
562 static PRIVILEGED_DATA StaticTask_t xTaskBuffer;
563 static const TaskParameters_t xCheckTaskParameters =
565 vATask, // pvTaskCode - the function that implements the task.
566 "ATask", // pcName - just a text name for the task to assist debugging.
567 100, // usStackDepth - the stack size DEFINED IN WORDS.
568 NULL, // pvParameters - passed into the task function as the function parameters.
569 ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
570 cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
572 // xRegions - Allocate up to three separate memory regions for access by
573 // the task, with appropriate access permissions. Different processors have
574 // different memory alignment requirements - refer to the FreeRTOS documentation
575 // for full information.
577 // Base address Length Parameters
578 { cReadWriteArray, 32, portMPU_REGION_READ_WRITE },
579 { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY },
580 { cPrivilegedOnlyAccessArray, 128, portMPU_REGION_PRIVILEGED_READ_WRITE }
583 &xTaskBuffer; // Holds the task's data structure.
588 TaskHandle_t xHandle;
590 // Create a task from the const structure defined above. The task handle
591 // is requested (the second parameter is not NULL) but in this case just for
592 // demonstration purposes as its not actually used.
593 xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
595 // Start the scheduler.
596 vTaskStartScheduler();
598 // Will only get here if there was insufficient memory to create the idle
599 // and/or timer task.
603 * \defgroup xTaskCreateRestrictedStatic xTaskCreateRestrictedStatic
606 #if( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
607 BaseType_t xTaskCreateRestrictedStatic( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ) PRIVILEGED_FUNCTION;
613 void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions );</pre>
615 * Memory regions are assigned to a restricted task when the task is created by
616 * a call to xTaskCreateRestricted(). These regions can be redefined using
617 * vTaskAllocateMPURegions().
619 * @param xTask The handle of the task being updated.
621 * @param xRegions A pointer to an MemoryRegion_t structure that contains the
622 * new memory region definitions.
626 // Define an array of MemoryRegion_t structures that configures an MPU region
627 // allowing read/write access for 1024 bytes starting at the beginning of the
628 // ucOneKByte array. The other two of the maximum 3 definable regions are
629 // unused so set to zero.
630 static const MemoryRegion_t xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] =
632 // Base address Length Parameters
633 { ucOneKByte, 1024, portMPU_REGION_READ_WRITE },
638 void vATask( void *pvParameters )
640 // This task was created such that it has access to certain regions of
641 // memory as defined by the MPU configuration. At some point it is
642 // desired that these MPU regions are replaced with that defined in the
643 // xAltRegions const struct above. Use a call to vTaskAllocateMPURegions()
644 // for this purpose. NULL is used as the task handle to indicate that this
645 // function should modify the MPU regions of the calling task.
646 vTaskAllocateMPURegions( NULL, xAltRegions );
648 // Now the task can continue its function, but from this point on can only
649 // access its stack and the ucOneKByte array (unless any other statically
650 // defined or shared regions have been declared elsewhere).
653 * \defgroup xTaskCreateRestricted xTaskCreateRestricted
656 void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions ) PRIVILEGED_FUNCTION;
660 * <pre>void vTaskDelete( TaskHandle_t xTask );</pre>
662 * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.
663 * See the configuration section for more information.
665 * Remove a task from the RTOS real time kernel's management. The task being
666 * deleted will be removed from all ready, blocked, suspended and event lists.
668 * NOTE: The idle task is responsible for freeing the kernel allocated
669 * memory from tasks that have been deleted. It is therefore important that
670 * the idle task is not starved of microcontroller processing time if your
671 * application makes any calls to vTaskDelete (). Memory allocated by the
672 * task code is not automatically freed, and should be freed before the task
675 * See the demo application file death.c for sample code that utilises
678 * @param xTask The handle of the task to be deleted. Passing NULL will
679 * cause the calling task to be deleted.
683 void vOtherFunction( void )
685 TaskHandle_t xHandle;
687 // Create the task, storing the handle.
688 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
690 // Use the handle to delete the task.
691 vTaskDelete( xHandle );
694 * \defgroup vTaskDelete vTaskDelete
697 void vTaskDelete( TaskHandle_t xTaskToDelete ) PRIVILEGED_FUNCTION;
699 /*-----------------------------------------------------------
701 *----------------------------------------------------------*/
705 * <pre>void vTaskDelay( const TickType_t xTicksToDelay );</pre>
707 * Delay a task for a given number of ticks. The actual time that the
708 * task remains blocked depends on the tick rate. The constant
709 * portTICK_PERIOD_MS can be used to calculate real time from the tick
710 * rate - with the resolution of one tick period.
712 * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
713 * See the configuration section for more information.
716 * vTaskDelay() specifies a time at which the task wishes to unblock relative to
717 * the time at which vTaskDelay() is called. For example, specifying a block
718 * period of 100 ticks will cause the task to unblock 100 ticks after
719 * vTaskDelay() is called. vTaskDelay() does not therefore provide a good method
720 * of controlling the frequency of a periodic task as the path taken through the
721 * code, as well as other task and interrupt activity, will effect the frequency
722 * at which vTaskDelay() gets called and therefore the time at which the task
723 * next executes. See vTaskDelayUntil() for an alternative API function designed
724 * to facilitate fixed frequency execution. It does this by specifying an
725 * absolute time (rather than a relative time) at which the calling task should
728 * @param xTicksToDelay The amount of time, in tick periods, that
729 * the calling task should block.
733 void vTaskFunction( void * pvParameters )
736 const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
740 // Simply toggle the LED every 500ms, blocking between each toggle.
742 vTaskDelay( xDelay );
746 * \defgroup vTaskDelay vTaskDelay
749 void vTaskDelay( const TickType_t xTicksToDelay ) PRIVILEGED_FUNCTION;
753 * <pre>void vTaskDelayUntil( TickType_t *pxPreviousWakeTime, const TickType_t xTimeIncrement );</pre>
755 * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available.
756 * See the configuration section for more information.
758 * Delay a task until a specified time. This function can be used by periodic
759 * tasks to ensure a constant execution frequency.
761 * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will
762 * cause a task to block for the specified number of ticks from the time vTaskDelay () is
763 * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed
764 * execution frequency as the time between a task starting to execute and that task
765 * calling vTaskDelay () may not be fixed [the task may take a different path though the
766 * code between calls, or may get interrupted or preempted a different number of times
767 * each time it executes].
769 * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
770 * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
773 * The constant portTICK_PERIOD_MS can be used to calculate real time from the tick
774 * rate - with the resolution of one tick period.
776 * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
777 * task was last unblocked. The variable must be initialised with the current time
778 * prior to its first use (see the example below). Following this the variable is
779 * automatically updated within vTaskDelayUntil ().
781 * @param xTimeIncrement The cycle time period. The task will be unblocked at
782 * time *pxPreviousWakeTime + xTimeIncrement. Calling vTaskDelayUntil with the
783 * same xTimeIncrement parameter value will cause the task to execute with
784 * a fixed interface period.
788 // Perform an action every 10 ticks.
789 void vTaskFunction( void * pvParameters )
791 TickType_t xLastWakeTime;
792 const TickType_t xFrequency = 10;
794 // Initialise the xLastWakeTime variable with the current time.
795 xLastWakeTime = xTaskGetTickCount ();
798 // Wait for the next cycle.
799 vTaskDelayUntil( &xLastWakeTime, xFrequency );
801 // Perform action here.
805 * \defgroup vTaskDelayUntil vTaskDelayUntil
808 void vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, const TickType_t xTimeIncrement ) PRIVILEGED_FUNCTION;
812 * <pre>BaseType_t xTaskAbortDelay( TaskHandle_t xTask );</pre>
814 * INCLUDE_xTaskAbortDelay must be defined as 1 in FreeRTOSConfig.h for this
815 * function to be available.
817 * A task will enter the Blocked state when it is waiting for an event. The
818 * event it is waiting for can be a temporal event (waiting for a time), such
819 * as when vTaskDelay() is called, or an event on an object, such as when
820 * xQueueReceive() or ulTaskNotifyTake() is called. If the handle of a task
821 * that is in the Blocked state is used in a call to xTaskAbortDelay() then the
822 * task will leave the Blocked state, and return from whichever function call
823 * placed the task into the Blocked state.
825 * @param xTask The handle of the task to remove from the Blocked state.
827 * @return If the task referenced by xTask was not in the Blocked state then
828 * pdFAIL is returned. Otherwise pdPASS is returned.
830 * \defgroup xTaskAbortDelay xTaskAbortDelay
833 BaseType_t xTaskAbortDelay( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
837 * <pre>UBaseType_t uxTaskPriorityGet( TaskHandle_t xTask );</pre>
839 * INCLUDE_uxTaskPriorityGet must be defined as 1 for this function to be available.
840 * See the configuration section for more information.
842 * Obtain the priority of any task.
844 * @param xTask Handle of the task to be queried. Passing a NULL
845 * handle results in the priority of the calling task being returned.
847 * @return The priority of xTask.
851 void vAFunction( void )
853 TaskHandle_t xHandle;
855 // Create a task, storing the handle.
856 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
860 // Use the handle to obtain the priority of the created task.
861 // It was created with tskIDLE_PRIORITY, but may have changed
863 if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
865 // The task has changed it's priority.
870 // Is our priority higher than the created task?
871 if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
873 // Our priority (obtained using NULL handle) is higher.
877 * \defgroup uxTaskPriorityGet uxTaskPriorityGet
880 UBaseType_t uxTaskPriorityGet( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
884 * <pre>UBaseType_t uxTaskPriorityGetFromISR( TaskHandle_t xTask );</pre>
886 * A version of uxTaskPriorityGet() that can be used from an ISR.
888 UBaseType_t uxTaskPriorityGetFromISR( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
892 * <pre>eTaskState eTaskGetState( TaskHandle_t xTask );</pre>
894 * INCLUDE_eTaskGetState must be defined as 1 for this function to be available.
895 * See the configuration section for more information.
897 * Obtain the state of any task. States are encoded by the eTaskState
900 * @param xTask Handle of the task to be queried.
902 * @return The state of xTask at the time the function was called. Note the
903 * state of the task might change between the function being called, and the
904 * functions return value being tested by the calling task.
906 eTaskState eTaskGetState( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
910 * <pre>void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState );</pre>
912 * configUSE_TRACE_FACILITY must be defined as 1 for this function to be
913 * available. See the configuration section for more information.
915 * Populates a TaskStatus_t structure with information about a task.
917 * @param xTask Handle of the task being queried. If xTask is NULL then
918 * information will be returned about the calling task.
920 * @param pxTaskStatus A pointer to the TaskStatus_t structure that will be
921 * filled with information about the task referenced by the handle passed using
922 * the xTask parameter.
924 * @xGetFreeStackSpace The TaskStatus_t structure contains a member to report
925 * the stack high water mark of the task being queried. Calculating the stack
926 * high water mark takes a relatively long time, and can make the system
927 * temporarily unresponsive - so the xGetFreeStackSpace parameter is provided to
928 * allow the high water mark checking to be skipped. The high watermark value
929 * will only be written to the TaskStatus_t structure if xGetFreeStackSpace is
930 * not set to pdFALSE;
932 * @param eState The TaskStatus_t structure contains a member to report the
933 * state of the task being queried. Obtaining the task state is not as fast as
934 * a simple assignment - so the eState parameter is provided to allow the state
935 * information to be omitted from the TaskStatus_t structure. To obtain state
936 * information then set eState to eInvalid - otherwise the value passed in
937 * eState will be reported as the task state in the TaskStatus_t structure.
941 void vAFunction( void )
943 TaskHandle_t xHandle;
944 TaskStatus_t xTaskDetails;
946 // Obtain the handle of a task from its name.
947 xHandle = xTaskGetHandle( "Task_Name" );
949 // Check the handle is not NULL.
950 configASSERT( xHandle );
952 // Use the handle to obtain further information about the task.
953 vTaskGetInfo( xHandle,
955 pdTRUE, // Include the high water mark in xTaskDetails.
956 eInvalid ); // Include the task state in xTaskDetails.
959 * \defgroup vTaskGetInfo vTaskGetInfo
962 void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState ) PRIVILEGED_FUNCTION;
966 * <pre>void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority );</pre>
968 * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
969 * See the configuration section for more information.
971 * Set the priority of any task.
973 * A context switch will occur before the function returns if the priority
974 * being set is higher than the currently executing task.
976 * @param xTask Handle to the task for which the priority is being set.
977 * Passing a NULL handle results in the priority of the calling task being set.
979 * @param uxNewPriority The priority to which the task will be set.
983 void vAFunction( void )
985 TaskHandle_t xHandle;
987 // Create a task, storing the handle.
988 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
992 // Use the handle to raise the priority of the created task.
993 vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
997 // Use a NULL handle to raise our priority to the same value.
998 vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
1001 * \defgroup vTaskPrioritySet vTaskPrioritySet
1004 void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority ) PRIVILEGED_FUNCTION;
1008 * <pre>void vTaskSuspend( TaskHandle_t xTaskToSuspend );</pre>
1010 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
1011 * See the configuration section for more information.
1013 * Suspend any task. When suspended a task will never get any microcontroller
1014 * processing time, no matter what its priority.
1016 * Calls to vTaskSuspend are not accumulative -
1017 * i.e. calling vTaskSuspend () twice on the same task still only requires one
1018 * call to vTaskResume () to ready the suspended task.
1020 * @param xTaskToSuspend Handle to the task being suspended. Passing a NULL
1021 * handle will cause the calling task to be suspended.
1025 void vAFunction( void )
1027 TaskHandle_t xHandle;
1029 // Create a task, storing the handle.
1030 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
1034 // Use the handle to suspend the created task.
1035 vTaskSuspend( xHandle );
1039 // The created task will not run during this period, unless
1040 // another task calls vTaskResume( xHandle ).
1045 // Suspend ourselves.
1046 vTaskSuspend( NULL );
1048 // We cannot get here unless another task calls vTaskResume
1049 // with our handle as the parameter.
1052 * \defgroup vTaskSuspend vTaskSuspend
1055 void vTaskSuspend( TaskHandle_t xTaskToSuspend ) PRIVILEGED_FUNCTION;
1059 * <pre>void vTaskResume( TaskHandle_t xTaskToResume );</pre>
1061 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
1062 * See the configuration section for more information.
1064 * Resumes a suspended task.
1066 * A task that has been suspended by one or more calls to vTaskSuspend ()
1067 * will be made available for running again by a single call to
1070 * @param xTaskToResume Handle to the task being readied.
1074 void vAFunction( void )
1076 TaskHandle_t xHandle;
1078 // Create a task, storing the handle.
1079 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
1083 // Use the handle to suspend the created task.
1084 vTaskSuspend( xHandle );
1088 // The created task will not run during this period, unless
1089 // another task calls vTaskResume( xHandle ).
1094 // Resume the suspended task ourselves.
1095 vTaskResume( xHandle );
1097 // The created task will once again get microcontroller processing
1098 // time in accordance with its priority within the system.
1101 * \defgroup vTaskResume vTaskResume
1104 void vTaskResume( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
1108 * <pre>void xTaskResumeFromISR( TaskHandle_t xTaskToResume );</pre>
1110 * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
1111 * available. See the configuration section for more information.
1113 * An implementation of vTaskResume() that can be called from within an ISR.
1115 * A task that has been suspended by one or more calls to vTaskSuspend ()
1116 * will be made available for running again by a single call to
1117 * xTaskResumeFromISR ().
1119 * xTaskResumeFromISR() should not be used to synchronise a task with an
1120 * interrupt if there is a chance that the interrupt could arrive prior to the
1121 * task being suspended - as this can lead to interrupts being missed. Use of a
1122 * semaphore as a synchronisation mechanism would avoid this eventuality.
1124 * @param xTaskToResume Handle to the task being readied.
1126 * @return pdTRUE if resuming the task should result in a context switch,
1127 * otherwise pdFALSE. This is used by the ISR to determine if a context switch
1128 * may be required following the ISR.
1130 * \defgroup vTaskResumeFromISR vTaskResumeFromISR
1133 BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
1135 /*-----------------------------------------------------------
1137 *----------------------------------------------------------*/
1141 * <pre>void vTaskStartScheduler( void );</pre>
1143 * Starts the real time kernel tick processing. After calling the kernel
1144 * has control over which tasks are executed and when.
1146 * See the demo application file main.c for an example of creating
1147 * tasks and starting the kernel.
1151 void vAFunction( void )
1153 // Create at least one task before starting the kernel.
1154 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
1156 // Start the real time kernel with preemption.
1157 vTaskStartScheduler ();
1159 // Will not get here unless a task calls vTaskEndScheduler ()
1163 * \defgroup vTaskStartScheduler vTaskStartScheduler
1164 * \ingroup SchedulerControl
1166 void vTaskStartScheduler( void ) PRIVILEGED_FUNCTION;
1170 * <pre>void vTaskEndScheduler( void );</pre>
1172 * NOTE: At the time of writing only the x86 real mode port, which runs on a PC
1173 * in place of DOS, implements this function.
1175 * Stops the real time kernel tick. All created tasks will be automatically
1176 * deleted and multitasking (either preemptive or cooperative) will
1177 * stop. Execution then resumes from the point where vTaskStartScheduler ()
1178 * was called, as if vTaskStartScheduler () had just returned.
1180 * See the demo application file main. c in the demo/PC directory for an
1181 * example that uses vTaskEndScheduler ().
1183 * vTaskEndScheduler () requires an exit function to be defined within the
1184 * portable layer (see vPortEndScheduler () in port. c for the PC port). This
1185 * performs hardware specific operations such as stopping the kernel tick.
1187 * vTaskEndScheduler () will cause all of the resources allocated by the
1188 * kernel to be freed - but will not free resources allocated by application
1193 void vTaskCode( void * pvParameters )
1197 // Task code goes here.
1199 // At some point we want to end the real time kernel processing
1201 vTaskEndScheduler ();
1205 void vAFunction( void )
1207 // Create at least one task before starting the kernel.
1208 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
1210 // Start the real time kernel with preemption.
1211 vTaskStartScheduler ();
1213 // Will only get here when the vTaskCode () task has called
1214 // vTaskEndScheduler (). When we get here we are back to single task
1219 * \defgroup vTaskEndScheduler vTaskEndScheduler
1220 * \ingroup SchedulerControl
1222 void vTaskEndScheduler( void ) PRIVILEGED_FUNCTION;
1226 * <pre>void vTaskSuspendAll( void );</pre>
1228 * Suspends the scheduler without disabling interrupts. Context switches will
1229 * not occur while the scheduler is suspended.
1231 * After calling vTaskSuspendAll () the calling task will continue to execute
1232 * without risk of being swapped out until a call to xTaskResumeAll () has been
1235 * API functions that have the potential to cause a context switch (for example,
1236 * vTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler
1241 void vTask1( void * pvParameters )
1245 // Task code goes here.
1249 // At some point the task wants to perform a long operation during
1250 // which it does not want to get swapped out. It cannot use
1251 // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
1252 // operation may cause interrupts to be missed - including the
1255 // Prevent the real time kernel swapping out the task.
1258 // Perform the operation here. There is no need to use critical
1259 // sections as we have all the microcontroller processing time.
1260 // During this time interrupts will still operate and the kernel
1261 // tick count will be maintained.
1265 // The operation is complete. Restart the kernel.
1270 * \defgroup vTaskSuspendAll vTaskSuspendAll
1271 * \ingroup SchedulerControl
1273 void vTaskSuspendAll( void ) PRIVILEGED_FUNCTION;
1277 * <pre>BaseType_t xTaskResumeAll( void );</pre>
1279 * Resumes scheduler activity after it was suspended by a call to
1280 * vTaskSuspendAll().
1282 * xTaskResumeAll() only resumes the scheduler. It does not unsuspend tasks
1283 * that were previously suspended by a call to vTaskSuspend().
1285 * @return If resuming the scheduler caused a context switch then pdTRUE is
1286 * returned, otherwise pdFALSE is returned.
1290 void vTask1( void * pvParameters )
1294 // Task code goes here.
1298 // At some point the task wants to perform a long operation during
1299 // which it does not want to get swapped out. It cannot use
1300 // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
1301 // operation may cause interrupts to be missed - including the
1304 // Prevent the real time kernel swapping out the task.
1307 // Perform the operation here. There is no need to use critical
1308 // sections as we have all the microcontroller processing time.
1309 // During this time interrupts will still operate and the real
1310 // time kernel tick count will be maintained.
1314 // The operation is complete. Restart the kernel. We want to force
1315 // a context switch - but there is no point if resuming the scheduler
1316 // caused a context switch already.
1317 if( !xTaskResumeAll () )
1324 * \defgroup xTaskResumeAll xTaskResumeAll
1325 * \ingroup SchedulerControl
1327 BaseType_t xTaskResumeAll( void ) PRIVILEGED_FUNCTION;
1329 /*-----------------------------------------------------------
1331 *----------------------------------------------------------*/
1335 * <PRE>TickType_t xTaskGetTickCount( void );</PRE>
1337 * @return The count of ticks since vTaskStartScheduler was called.
1339 * \defgroup xTaskGetTickCount xTaskGetTickCount
1340 * \ingroup TaskUtils
1342 TickType_t xTaskGetTickCount( void ) PRIVILEGED_FUNCTION;
1346 * <PRE>TickType_t xTaskGetTickCountFromISR( void );</PRE>
1348 * @return The count of ticks since vTaskStartScheduler was called.
1350 * This is a version of xTaskGetTickCount() that is safe to be called from an
1351 * ISR - provided that TickType_t is the natural word size of the
1352 * microcontroller being used or interrupt nesting is either not supported or
1355 * \defgroup xTaskGetTickCountFromISR xTaskGetTickCountFromISR
1356 * \ingroup TaskUtils
1358 TickType_t xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION;
1362 * <PRE>uint16_t uxTaskGetNumberOfTasks( void );</PRE>
1364 * @return The number of tasks that the real time kernel is currently managing.
1365 * This includes all ready, blocked and suspended tasks. A task that
1366 * has been deleted but not yet freed by the idle task will also be
1367 * included in the count.
1369 * \defgroup uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
1370 * \ingroup TaskUtils
1372 UBaseType_t uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION;
1376 * <PRE>char *pcTaskGetName( TaskHandle_t xTaskToQuery );</PRE>
1378 * @return The text (human readable) name of the task referenced by the handle
1379 * xTaskToQuery. A task can query its own name by either passing in its own
1380 * handle, or by setting xTaskToQuery to NULL.
1382 * \defgroup pcTaskGetName pcTaskGetName
1383 * \ingroup TaskUtils
1385 char *pcTaskGetName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1389 * <PRE>TaskHandle_t xTaskGetHandle( const char *pcNameToQuery );</PRE>
1391 * NOTE: This function takes a relatively long time to complete and should be
1394 * @return The handle of the task that has the human readable name pcNameToQuery.
1395 * NULL is returned if no matching name is found. INCLUDE_xTaskGetHandle
1396 * must be set to 1 in FreeRTOSConfig.h for pcTaskGetHandle() to be available.
1398 * \defgroup pcTaskGetHandle pcTaskGetHandle
1399 * \ingroup TaskUtils
1401 TaskHandle_t xTaskGetHandle( const char *pcNameToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1405 * <PRE>UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask );</PRE>
1407 * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
1408 * this function to be available.
1410 * Returns the high water mark of the stack associated with xTask. That is,
1411 * the minimum free stack space there has been (in words, so on a 32 bit machine
1412 * a value of 1 means 4 bytes) since the task started. The smaller the returned
1413 * number the closer the task has come to overflowing its stack.
1415 * @param xTask Handle of the task associated with the stack to be checked.
1416 * Set xTask to NULL to check the stack of the calling task.
1418 * @return The smallest amount of free stack space there has been (in words, so
1419 * actual spaces on the stack rather than bytes) since the task referenced by
1420 * xTask was created.
1422 UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1424 /* When using trace macros it is sometimes necessary to include task.h before
1425 FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined,
1426 so the following two prototypes will cause a compilation error. This can be
1427 fixed by simply guarding against the inclusion of these two prototypes unless
1428 they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration
1430 #ifdef configUSE_APPLICATION_TASK_TAG
1431 #if configUSE_APPLICATION_TASK_TAG == 1
1434 * <pre>void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction );</pre>
1436 * Sets pxHookFunction to be the task hook function used by the task xTask.
1437 * Passing xTask as NULL has the effect of setting the calling tasks hook
1440 void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction ) PRIVILEGED_FUNCTION;
1444 * <pre>void xTaskGetApplicationTaskTag( TaskHandle_t xTask );</pre>
1446 * Returns the pxHookFunction value assigned to the task xTask.
1448 TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1449 #endif /* configUSE_APPLICATION_TASK_TAG ==1 */
1450 #endif /* ifdef configUSE_APPLICATION_TASK_TAG */
1452 #if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )
1454 /* Each task contains an array of pointers that is dimensioned by the
1455 configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h. The
1456 kernel does not use the pointers itself, so the application writer can use
1457 the pointers for any purpose they wish. The following two functions are
1458 used to set and query a pointer respectively. */
1459 void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue ) PRIVILEGED_FUNCTION;
1460 void *pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, BaseType_t xIndex ) PRIVILEGED_FUNCTION;
1466 * <pre>BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter );</pre>
1468 * Calls the hook function associated with xTask. Passing xTask as NULL has
1469 * the effect of calling the Running tasks (the calling task) hook function.
1471 * pvParameter is passed to the hook function for the task to interpret as it
1472 * wants. The return value is the value returned by the task hook function
1473 * registered by the user.
1475 BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter ) PRIVILEGED_FUNCTION;
1478 * xTaskGetIdleTaskHandle() is only available if
1479 * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.
1481 * Simply returns the handle of the idle task. It is not valid to call
1482 * xTaskGetIdleTaskHandle() before the scheduler has been started.
1484 TaskHandle_t xTaskGetIdleTaskHandle( void ) PRIVILEGED_FUNCTION;
1487 * configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for
1488 * uxTaskGetSystemState() to be available.
1490 * uxTaskGetSystemState() populates an TaskStatus_t structure for each task in
1491 * the system. TaskStatus_t structures contain, among other things, members
1492 * for the task handle, task name, task priority, task state, and total amount
1493 * of run time consumed by the task. See the TaskStatus_t structure
1494 * definition in this file for the full member list.
1496 * NOTE: This function is intended for debugging use only as its use results in
1497 * the scheduler remaining suspended for an extended period.
1499 * @param pxTaskStatusArray A pointer to an array of TaskStatus_t structures.
1500 * The array must contain at least one TaskStatus_t structure for each task
1501 * that is under the control of the RTOS. The number of tasks under the control
1502 * of the RTOS can be determined using the uxTaskGetNumberOfTasks() API function.
1504 * @param uxArraySize The size of the array pointed to by the pxTaskStatusArray
1505 * parameter. The size is specified as the number of indexes in the array, or
1506 * the number of TaskStatus_t structures contained in the array, not by the
1507 * number of bytes in the array.
1509 * @param pulTotalRunTime If configGENERATE_RUN_TIME_STATS is set to 1 in
1510 * FreeRTOSConfig.h then *pulTotalRunTime is set by uxTaskGetSystemState() to the
1511 * total run time (as defined by the run time stats clock, see
1512 * http://www.freertos.org/rtos-run-time-stats.html) since the target booted.
1513 * pulTotalRunTime can be set to NULL to omit the total run time information.
1515 * @return The number of TaskStatus_t structures that were populated by
1516 * uxTaskGetSystemState(). This should equal the number returned by the
1517 * uxTaskGetNumberOfTasks() API function, but will be zero if the value passed
1518 * in the uxArraySize parameter was too small.
1522 // This example demonstrates how a human readable table of run time stats
1523 // information is generated from raw data provided by uxTaskGetSystemState().
1524 // The human readable table is written to pcWriteBuffer
1525 void vTaskGetRunTimeStats( char *pcWriteBuffer )
1527 TaskStatus_t *pxTaskStatusArray;
1528 volatile UBaseType_t uxArraySize, x;
1529 uint32_t ulTotalRunTime, ulStatsAsPercentage;
1531 // Make sure the write buffer does not contain a string.
1532 *pcWriteBuffer = 0x00;
1534 // Take a snapshot of the number of tasks in case it changes while this
1535 // function is executing.
1536 uxArraySize = uxTaskGetNumberOfTasks();
1538 // Allocate a TaskStatus_t structure for each task. An array could be
1539 // allocated statically at compile time.
1540 pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
1542 if( pxTaskStatusArray != NULL )
1544 // Generate raw status information about each task.
1545 uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );
1547 // For percentage calculations.
1548 ulTotalRunTime /= 100UL;
1550 // Avoid divide by zero errors.
1551 if( ulTotalRunTime > 0 )
1553 // For each populated position in the pxTaskStatusArray array,
1554 // format the raw data as human readable ASCII data
1555 for( x = 0; x < uxArraySize; x++ )
1557 // What percentage of the total run time has the task used?
1558 // This will always be rounded down to the nearest integer.
1559 // ulTotalRunTimeDiv100 has already been divided by 100.
1560 ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;
1562 if( ulStatsAsPercentage > 0UL )
1564 sprintf( pcWriteBuffer, "%s\t\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );
1568 // If the percentage is zero here then the task has
1569 // consumed less than 1% of the total run time.
1570 sprintf( pcWriteBuffer, "%s\t\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter );
1573 pcWriteBuffer += strlen( ( char * ) pcWriteBuffer );
1577 // The array is no longer needed, free the memory it consumes.
1578 vPortFree( pxTaskStatusArray );
1583 UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime ) PRIVILEGED_FUNCTION;
1587 * <PRE>void vTaskList( char *pcWriteBuffer );</PRE>
1589 * configUSE_TRACE_FACILITY and configUSE_STATS_FORMATTING_FUNCTIONS must
1590 * both be defined as 1 for this function to be available. See the
1591 * configuration section of the FreeRTOS.org website for more information.
1593 * NOTE 1: This function will disable interrupts for its duration. It is
1594 * not intended for normal application runtime use but as a debug aid.
1596 * Lists all the current tasks, along with their current state and stack
1597 * usage high water mark.
1599 * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or
1604 * This function is provided for convenience only, and is used by many of the
1605 * demo applications. Do not consider it to be part of the scheduler.
1607 * vTaskList() calls uxTaskGetSystemState(), then formats part of the
1608 * uxTaskGetSystemState() output into a human readable table that displays task
1609 * names, states and stack usage.
1611 * vTaskList() has a dependency on the sprintf() C library function that might
1612 * bloat the code size, use a lot of stack, and provide different results on
1613 * different platforms. An alternative, tiny, third party, and limited
1614 * functionality implementation of sprintf() is provided in many of the
1615 * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
1616 * printf-stdarg.c does not provide a full snprintf() implementation!).
1618 * It is recommended that production systems call uxTaskGetSystemState()
1619 * directly to get access to raw stats data, rather than indirectly through a
1620 * call to vTaskList().
1622 * @param pcWriteBuffer A buffer into which the above mentioned details
1623 * will be written, in ASCII form. This buffer is assumed to be large
1624 * enough to contain the generated report. Approximately 40 bytes per
1625 * task should be sufficient.
1627 * \defgroup vTaskList vTaskList
1628 * \ingroup TaskUtils
1630 void vTaskList( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1634 * <PRE>void vTaskGetRunTimeStats( char *pcWriteBuffer );</PRE>
1636 * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS
1637 * must both be defined as 1 for this function to be available. The application
1638 * must also then provide definitions for
1639 * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()
1640 * to configure a peripheral timer/counter and return the timers current count
1641 * value respectively. The counter should be at least 10 times the frequency of
1644 * NOTE 1: This function will disable interrupts for its duration. It is
1645 * not intended for normal application runtime use but as a debug aid.
1647 * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
1648 * accumulated execution time being stored for each task. The resolution
1649 * of the accumulated time value depends on the frequency of the timer
1650 * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
1651 * Calling vTaskGetRunTimeStats() writes the total execution time of each
1652 * task into a buffer, both as an absolute count value and as a percentage
1653 * of the total system execution time.
1657 * This function is provided for convenience only, and is used by many of the
1658 * demo applications. Do not consider it to be part of the scheduler.
1660 * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part of the
1661 * uxTaskGetSystemState() output into a human readable table that displays the
1662 * amount of time each task has spent in the Running state in both absolute and
1665 * vTaskGetRunTimeStats() has a dependency on the sprintf() C library function
1666 * that might bloat the code size, use a lot of stack, and provide different
1667 * results on different platforms. An alternative, tiny, third party, and
1668 * limited functionality implementation of sprintf() is provided in many of the
1669 * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
1670 * printf-stdarg.c does not provide a full snprintf() implementation!).
1672 * It is recommended that production systems call uxTaskGetSystemState() directly
1673 * to get access to raw stats data, rather than indirectly through a call to
1674 * vTaskGetRunTimeStats().
1676 * @param pcWriteBuffer A buffer into which the execution times will be
1677 * written, in ASCII form. This buffer is assumed to be large enough to
1678 * contain the generated report. Approximately 40 bytes per task should
1681 * \defgroup vTaskGetRunTimeStats vTaskGetRunTimeStats
1682 * \ingroup TaskUtils
1684 void vTaskGetRunTimeStats( char *pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1688 * <PRE>BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction );</PRE>
1690 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
1691 * function to be available.
1693 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
1694 * "notification value", which is a 32-bit unsigned integer (uint32_t).
1696 * Events can be sent to a task using an intermediary object. Examples of such
1697 * objects are queues, semaphores, mutexes and event groups. Task notifications
1698 * are a method of sending an event directly to a task without the need for such
1699 * an intermediary object.
1701 * A notification sent to a task can optionally perform an action, such as
1702 * update, overwrite or increment the task's notification value. In that way
1703 * task notifications can be used to send data to a task, or be used as light
1704 * weight and fast binary or counting semaphores.
1706 * A notification sent to a task will remain pending until it is cleared by the
1707 * task calling xTaskNotifyWait() or ulTaskNotifyTake(). If the task was
1708 * already in the Blocked state to wait for a notification when the notification
1709 * arrives then the task will automatically be removed from the Blocked state
1710 * (unblocked) and the notification cleared.
1712 * A task can use xTaskNotifyWait() to [optionally] block to wait for a
1713 * notification to be pending, or ulTaskNotifyTake() to [optionally] block
1714 * to wait for its notification value to have a non-zero value. The task does
1715 * not consume any CPU time while it is in the Blocked state.
1717 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
1719 * @param xTaskToNotify The handle of the task being notified. The handle to a
1720 * task can be returned from the xTaskCreate() API function used to create the
1721 * task, and the handle of the currently running task can be obtained by calling
1722 * xTaskGetCurrentTaskHandle().
1724 * @param ulValue Data that can be sent with the notification. How the data is
1725 * used depends on the value of the eAction parameter.
1727 * @param eAction Specifies how the notification updates the task's notification
1728 * value, if at all. Valid values for eAction are as follows:
1731 * The task's notification value is bitwise ORed with ulValue. xTaskNofify()
1732 * always returns pdPASS in this case.
1735 * The task's notification value is incremented. ulValue is not used and
1736 * xTaskNotify() always returns pdPASS in this case.
1738 * eSetValueWithOverwrite -
1739 * The task's notification value is set to the value of ulValue, even if the
1740 * task being notified had not yet processed the previous notification (the
1741 * task already had a notification pending). xTaskNotify() always returns
1742 * pdPASS in this case.
1744 * eSetValueWithoutOverwrite -
1745 * If the task being notified did not already have a notification pending then
1746 * the task's notification value is set to ulValue and xTaskNotify() will
1747 * return pdPASS. If the task being notified already had a notification
1748 * pending then no action is performed and pdFAIL is returned.
1751 * The task receives a notification without its notification value being
1752 * updated. ulValue is not used and xTaskNotify() always returns pdPASS in
1755 * pulPreviousNotificationValue -
1756 * Can be used to pass out the subject task's notification value before any
1757 * bits are modified by the notify function.
1759 * @return Dependent on the value of eAction. See the description of the
1760 * eAction parameter.
1762 * \defgroup xTaskNotify xTaskNotify
1763 * \ingroup TaskNotifications
1765 BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue ) PRIVILEGED_FUNCTION;
1766 #define xTaskNotify( xTaskToNotify, ulValue, eAction ) xTaskGenericNotify( ( xTaskToNotify ), ( ulValue ), ( eAction ), NULL )
1767 #define xTaskNotifyAndQuery( xTaskToNotify, ulValue, eAction, pulPreviousNotifyValue ) xTaskGenericNotify( ( xTaskToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) )
1771 * <PRE>BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
1773 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
1774 * function to be available.
1776 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
1777 * "notification value", which is a 32-bit unsigned integer (uint32_t).
1779 * A version of xTaskNotify() that can be used from an interrupt service routine
1782 * Events can be sent to a task using an intermediary object. Examples of such
1783 * objects are queues, semaphores, mutexes and event groups. Task notifications
1784 * are a method of sending an event directly to a task without the need for such
1785 * an intermediary object.
1787 * A notification sent to a task can optionally perform an action, such as
1788 * update, overwrite or increment the task's notification value. In that way
1789 * task notifications can be used to send data to a task, or be used as light
1790 * weight and fast binary or counting semaphores.
1792 * A notification sent to a task will remain pending until it is cleared by the
1793 * task calling xTaskNotifyWait() or ulTaskNotifyTake(). If the task was
1794 * already in the Blocked state to wait for a notification when the notification
1795 * arrives then the task will automatically be removed from the Blocked state
1796 * (unblocked) and the notification cleared.
1798 * A task can use xTaskNotifyWait() to [optionally] block to wait for a
1799 * notification to be pending, or ulTaskNotifyTake() to [optionally] block
1800 * to wait for its notification value to have a non-zero value. The task does
1801 * not consume any CPU time while it is in the Blocked state.
1803 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
1805 * @param xTaskToNotify The handle of the task being notified. The handle to a
1806 * task can be returned from the xTaskCreate() API function used to create the
1807 * task, and the handle of the currently running task can be obtained by calling
1808 * xTaskGetCurrentTaskHandle().
1810 * @param ulValue Data that can be sent with the notification. How the data is
1811 * used depends on the value of the eAction parameter.
1813 * @param eAction Specifies how the notification updates the task's notification
1814 * value, if at all. Valid values for eAction are as follows:
1817 * The task's notification value is bitwise ORed with ulValue. xTaskNofify()
1818 * always returns pdPASS in this case.
1821 * The task's notification value is incremented. ulValue is not used and
1822 * xTaskNotify() always returns pdPASS in this case.
1824 * eSetValueWithOverwrite -
1825 * The task's notification value is set to the value of ulValue, even if the
1826 * task being notified had not yet processed the previous notification (the
1827 * task already had a notification pending). xTaskNotify() always returns
1828 * pdPASS in this case.
1830 * eSetValueWithoutOverwrite -
1831 * If the task being notified did not already have a notification pending then
1832 * the task's notification value is set to ulValue and xTaskNotify() will
1833 * return pdPASS. If the task being notified already had a notification
1834 * pending then no action is performed and pdFAIL is returned.
1837 * The task receives a notification without its notification value being
1838 * updated. ulValue is not used and xTaskNotify() always returns pdPASS in
1841 * @param pxHigherPriorityTaskWoken xTaskNotifyFromISR() will set
1842 * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
1843 * task to which the notification was sent to leave the Blocked state, and the
1844 * unblocked task has a priority higher than the currently running task. If
1845 * xTaskNotifyFromISR() sets this value to pdTRUE then a context switch should
1846 * be requested before the interrupt is exited. How a context switch is
1847 * requested from an ISR is dependent on the port - see the documentation page
1848 * for the port in use.
1850 * @return Dependent on the value of eAction. See the description of the
1851 * eAction parameter.
1853 * \defgroup xTaskNotify xTaskNotify
1854 * \ingroup TaskNotifications
1856 BaseType_t xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1857 #define xTaskNotifyFromISR( xTaskToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) )
1858 #define xTaskNotifyAndQueryFromISR( xTaskToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) )
1862 * <PRE>BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );</pre>
1864 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
1865 * function to be available.
1867 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
1868 * "notification value", which is a 32-bit unsigned integer (uint32_t).
1870 * Events can be sent to a task using an intermediary object. Examples of such
1871 * objects are queues, semaphores, mutexes and event groups. Task notifications
1872 * are a method of sending an event directly to a task without the need for such
1873 * an intermediary object.
1875 * A notification sent to a task can optionally perform an action, such as
1876 * update, overwrite or increment the task's notification value. In that way
1877 * task notifications can be used to send data to a task, or be used as light
1878 * weight and fast binary or counting semaphores.
1880 * A notification sent to a task will remain pending until it is cleared by the
1881 * task calling xTaskNotifyWait() or ulTaskNotifyTake(). If the task was
1882 * already in the Blocked state to wait for a notification when the notification
1883 * arrives then the task will automatically be removed from the Blocked state
1884 * (unblocked) and the notification cleared.
1886 * A task can use xTaskNotifyWait() to [optionally] block to wait for a
1887 * notification to be pending, or ulTaskNotifyTake() to [optionally] block
1888 * to wait for its notification value to have a non-zero value. The task does
1889 * not consume any CPU time while it is in the Blocked state.
1891 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
1893 * @param ulBitsToClearOnEntry Bits that are set in ulBitsToClearOnEntry value
1894 * will be cleared in the calling task's notification value before the task
1895 * checks to see if any notifications are pending, and optionally blocks if no
1896 * notifications are pending. Setting ulBitsToClearOnEntry to ULONG_MAX (if
1897 * limits.h is included) or 0xffffffffUL (if limits.h is not included) will have
1898 * the effect of resetting the task's notification value to 0. Setting
1899 * ulBitsToClearOnEntry to 0 will leave the task's notification value unchanged.
1901 * @param ulBitsToClearOnExit If a notification is pending or received before
1902 * the calling task exits the xTaskNotifyWait() function then the task's
1903 * notification value (see the xTaskNotify() API function) is passed out using
1904 * the pulNotificationValue parameter. Then any bits that are set in
1905 * ulBitsToClearOnExit will be cleared in the task's notification value (note
1906 * *pulNotificationValue is set before any bits are cleared). Setting
1907 * ulBitsToClearOnExit to ULONG_MAX (if limits.h is included) or 0xffffffffUL
1908 * (if limits.h is not included) will have the effect of resetting the task's
1909 * notification value to 0 before the function exits. Setting
1910 * ulBitsToClearOnExit to 0 will leave the task's notification value unchanged
1911 * when the function exits (in which case the value passed out in
1912 * pulNotificationValue will match the task's notification value).
1914 * @param pulNotificationValue Used to pass the task's notification value out
1915 * of the function. Note the value passed out will not be effected by the
1916 * clearing of any bits caused by ulBitsToClearOnExit being non-zero.
1918 * @param xTicksToWait The maximum amount of time that the task should wait in
1919 * the Blocked state for a notification to be received, should a notification
1920 * not already be pending when xTaskNotifyWait() was called. The task
1921 * will not consume any processing time while it is in the Blocked state. This
1922 * is specified in kernel ticks, the macro pdMS_TO_TICSK( value_in_ms ) can be
1923 * used to convert a time specified in milliseconds to a time specified in
1926 * @return If a notification was received (including notifications that were
1927 * already pending when xTaskNotifyWait was called) then pdPASS is
1928 * returned. Otherwise pdFAIL is returned.
1930 * \defgroup xTaskNotifyWait xTaskNotifyWait
1931 * \ingroup TaskNotifications
1933 BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1937 * <PRE>BaseType_t xTaskNotifyGive( TaskHandle_t xTaskToNotify );</PRE>
1939 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
1942 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
1943 * "notification value", which is a 32-bit unsigned integer (uint32_t).
1945 * Events can be sent to a task using an intermediary object. Examples of such
1946 * objects are queues, semaphores, mutexes and event groups. Task notifications
1947 * are a method of sending an event directly to a task without the need for such
1948 * an intermediary object.
1950 * A notification sent to a task can optionally perform an action, such as
1951 * update, overwrite or increment the task's notification value. In that way
1952 * task notifications can be used to send data to a task, or be used as light
1953 * weight and fast binary or counting semaphores.
1955 * xTaskNotifyGive() is a helper macro intended for use when task notifications
1956 * are used as light weight and faster binary or counting semaphore equivalents.
1957 * Actual FreeRTOS semaphores are given using the xSemaphoreGive() API function,
1958 * the equivalent action that instead uses a task notification is
1959 * xTaskNotifyGive().
1961 * When task notifications are being used as a binary or counting semaphore
1962 * equivalent then the task being notified should wait for the notification
1963 * using the ulTaskNotificationTake() API function rather than the
1964 * xTaskNotifyWait() API function.
1966 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
1968 * @param xTaskToNotify The handle of the task being notified. The handle to a
1969 * task can be returned from the xTaskCreate() API function used to create the
1970 * task, and the handle of the currently running task can be obtained by calling
1971 * xTaskGetCurrentTaskHandle().
1973 * @return xTaskNotifyGive() is a macro that calls xTaskNotify() with the
1974 * eAction parameter set to eIncrement - so pdPASS is always returned.
1976 * \defgroup xTaskNotifyGive xTaskNotifyGive
1977 * \ingroup TaskNotifications
1979 #define xTaskNotifyGive( xTaskToNotify ) xTaskGenericNotify( ( xTaskToNotify ), ( 0 ), eIncrement, NULL )
1983 * <PRE>void vTaskNotifyGiveFromISR( TaskHandle_t xTaskHandle, BaseType_t *pxHigherPriorityTaskWoken );
1985 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
1988 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
1989 * "notification value", which is a 32-bit unsigned integer (uint32_t).
1991 * A version of xTaskNotifyGive() that can be called from an interrupt service
1994 * Events can be sent to a task using an intermediary object. Examples of such
1995 * objects are queues, semaphores, mutexes and event groups. Task notifications
1996 * are a method of sending an event directly to a task without the need for such
1997 * an intermediary object.
1999 * A notification sent to a task can optionally perform an action, such as
2000 * update, overwrite or increment the task's notification value. In that way
2001 * task notifications can be used to send data to a task, or be used as light
2002 * weight and fast binary or counting semaphores.
2004 * vTaskNotifyGiveFromISR() is intended for use when task notifications are
2005 * used as light weight and faster binary or counting semaphore equivalents.
2006 * Actual FreeRTOS semaphores are given from an ISR using the
2007 * xSemaphoreGiveFromISR() API function, the equivalent action that instead uses
2008 * a task notification is vTaskNotifyGiveFromISR().
2010 * When task notifications are being used as a binary or counting semaphore
2011 * equivalent then the task being notified should wait for the notification
2012 * using the ulTaskNotificationTake() API function rather than the
2013 * xTaskNotifyWait() API function.
2015 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
2017 * @param xTaskToNotify The handle of the task being notified. The handle to a
2018 * task can be returned from the xTaskCreate() API function used to create the
2019 * task, and the handle of the currently running task can be obtained by calling
2020 * xTaskGetCurrentTaskHandle().
2022 * @param pxHigherPriorityTaskWoken vTaskNotifyGiveFromISR() will set
2023 * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
2024 * task to which the notification was sent to leave the Blocked state, and the
2025 * unblocked task has a priority higher than the currently running task. If
2026 * vTaskNotifyGiveFromISR() sets this value to pdTRUE then a context switch
2027 * should be requested before the interrupt is exited. How a context switch is
2028 * requested from an ISR is dependent on the port - see the documentation page
2029 * for the port in use.
2031 * \defgroup xTaskNotifyWait xTaskNotifyWait
2032 * \ingroup TaskNotifications
2034 void vTaskNotifyGiveFromISR( TaskHandle_t xTaskToNotify, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
2038 * <PRE>uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait );</pre>
2040 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
2041 * function to be available.
2043 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
2044 * "notification value", which is a 32-bit unsigned integer (uint32_t).
2046 * Events can be sent to a task using an intermediary object. Examples of such
2047 * objects are queues, semaphores, mutexes and event groups. Task notifications
2048 * are a method of sending an event directly to a task without the need for such
2049 * an intermediary object.
2051 * A notification sent to a task can optionally perform an action, such as
2052 * update, overwrite or increment the task's notification value. In that way
2053 * task notifications can be used to send data to a task, or be used as light
2054 * weight and fast binary or counting semaphores.
2056 * ulTaskNotifyTake() is intended for use when a task notification is used as a
2057 * faster and lighter weight binary or counting semaphore alternative. Actual
2058 * FreeRTOS semaphores are taken using the xSemaphoreTake() API function, the
2059 * equivalent action that instead uses a task notification is
2060 * ulTaskNotifyTake().
2062 * When a task is using its notification value as a binary or counting semaphore
2063 * other tasks should send notifications to it using the xTaskNotifyGive()
2064 * macro, or xTaskNotify() function with the eAction parameter set to
2067 * ulTaskNotifyTake() can either clear the task's notification value to
2068 * zero on exit, in which case the notification value acts like a binary
2069 * semaphore, or decrement the task's notification value on exit, in which case
2070 * the notification value acts like a counting semaphore.
2072 * A task can use ulTaskNotifyTake() to [optionally] block to wait for a
2073 * the task's notification value to be non-zero. The task does not consume any
2074 * CPU time while it is in the Blocked state.
2076 * Where as xTaskNotifyWait() will return when a notification is pending,
2077 * ulTaskNotifyTake() will return when the task's notification value is
2080 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
2082 * @param xClearCountOnExit if xClearCountOnExit is pdFALSE then the task's
2083 * notification value is decremented when the function exits. In this way the
2084 * notification value acts like a counting semaphore. If xClearCountOnExit is
2085 * not pdFALSE then the task's notification value is cleared to zero when the
2086 * function exits. In this way the notification value acts like a binary
2089 * @param xTicksToWait The maximum amount of time that the task should wait in
2090 * the Blocked state for the task's notification value to be greater than zero,
2091 * should the count not already be greater than zero when
2092 * ulTaskNotifyTake() was called. The task will not consume any processing
2093 * time while it is in the Blocked state. This is specified in kernel ticks,
2094 * the macro pdMS_TO_TICSK( value_in_ms ) can be used to convert a time
2095 * specified in milliseconds to a time specified in ticks.
2097 * @return The task's notification count before it is either cleared to zero or
2098 * decremented (see the xClearCountOnExit parameter).
2100 * \defgroup ulTaskNotifyTake ulTaskNotifyTake
2101 * \ingroup TaskNotifications
2103 uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2107 * <PRE>BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask );</pre>
2109 * If the notification state of the task referenced by the handle xTask is
2110 * eNotified, then set the task's notification state to eNotWaitingNotification.
2111 * The task's notification value is not altered. Set xTask to NULL to clear the
2112 * notification state of the calling task.
2114 * @return pdTRUE if the task's notification state was set to
2115 * eNotWaitingNotification, otherwise pdFALSE.
2116 * \defgroup xTaskNotifyStateClear xTaskNotifyStateClear
2117 * \ingroup TaskNotifications
2119 BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask );
2121 /*-----------------------------------------------------------
2122 * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
2123 *----------------------------------------------------------*/
2126 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
2127 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
2128 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2130 * Called from the real time kernel tick (either preemptive or cooperative),
2131 * this increments the tick count and checks if any tasks that are blocked
2132 * for a finite period required removing from a blocked list and placing on
2133 * a ready list. If a non-zero value is returned then a context switch is
2134 * required because either:
2135 * + A task was removed from a blocked list because its timeout had expired,
2137 * + Time slicing is in use and there is a task of equal priority to the
2138 * currently running task.
2140 BaseType_t xTaskIncrementTick( void ) PRIVILEGED_FUNCTION;
2143 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
2144 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2146 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
2148 * Removes the calling task from the ready list and places it both
2149 * on the list of tasks waiting for a particular event, and the
2150 * list of delayed tasks. The task will be removed from both lists
2151 * and replaced on the ready list should either the event occur (and
2152 * there be no higher priority tasks waiting on the same event) or
2153 * the delay period expires.
2155 * The 'unordered' version replaces the event list item value with the
2156 * xItemValue value, and inserts the list item at the end of the list.
2158 * The 'ordered' version uses the existing event list item value (which is the
2159 * owning tasks priority) to insert the list item into the event list is task
2162 * @param pxEventList The list containing tasks that are blocked waiting
2163 * for the event to occur.
2165 * @param xItemValue The item value to use for the event list item when the
2166 * event list is not ordered by task priority.
2168 * @param xTicksToWait The maximum amount of time that the task should wait
2169 * for the event to occur. This is specified in kernel ticks,the constant
2170 * portTICK_PERIOD_MS can be used to convert kernel ticks into a real time
2173 void vTaskPlaceOnEventList( List_t * const pxEventList, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2174 void vTaskPlaceOnUnorderedEventList( List_t * pxEventList, const TickType_t xItemValue, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2177 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
2178 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2180 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
2182 * This function performs nearly the same function as vTaskPlaceOnEventList().
2183 * The difference being that this function does not permit tasks to block
2184 * indefinitely, whereas vTaskPlaceOnEventList() does.
2187 void vTaskPlaceOnEventListRestricted( List_t * const pxEventList, TickType_t xTicksToWait, const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION;
2190 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
2191 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2193 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
2195 * Removes a task from both the specified event list and the list of blocked
2196 * tasks, and places it on a ready queue.
2198 * xTaskRemoveFromEventList()/vTaskRemoveFromUnorderedEventList() will be called
2199 * if either an event occurs to unblock a task, or the block timeout period
2202 * xTaskRemoveFromEventList() is used when the event list is in task priority
2203 * order. It removes the list item from the head of the event list as that will
2204 * have the highest priority owning task of all the tasks on the event list.
2205 * vTaskRemoveFromUnorderedEventList() is used when the event list is not
2206 * ordered and the event list items hold something other than the owning tasks
2207 * priority. In this case the event list item value is updated to the value
2208 * passed in the xItemValue parameter.
2210 * @return pdTRUE if the task being removed has a higher priority than the task
2211 * making the call, otherwise pdFALSE.
2213 BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList ) PRIVILEGED_FUNCTION;
2214 void vTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem, const TickType_t xItemValue ) PRIVILEGED_FUNCTION;
2217 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
2218 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
2219 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2221 * Sets the pointer to the current TCB to the TCB of the highest priority task
2222 * that is ready to run.
2224 void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION;
2227 * THESE FUNCTIONS MUST NOT BE USED FROM APPLICATION CODE. THEY ARE USED BY
2228 * THE EVENT BITS MODULE.
2230 TickType_t uxTaskResetEventItemValue( void ) PRIVILEGED_FUNCTION;
2233 * Return the handle of the calling task.
2235 TaskHandle_t xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION;
2238 * Capture the current time status for future reference.
2240 void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
2243 * Compare the time status now with that previously captured to see if the
2244 * timeout has expired.
2246 BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait ) PRIVILEGED_FUNCTION;
2249 * Shortcut used by the queue implementation to prevent unnecessary call to
2252 void vTaskMissedYield( void ) PRIVILEGED_FUNCTION;
2255 * Returns the scheduler state as taskSCHEDULER_RUNNING,
2256 * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
2258 BaseType_t xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION;
2261 * Raises the priority of the mutex holder to that of the calling task should
2262 * the mutex holder have a priority less than the calling task.
2264 BaseType_t xTaskPriorityInherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
2267 * Set the priority of a task back to its proper priority in the case that it
2268 * inherited a higher priority while it was holding a semaphore.
2270 BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
2273 * If a higher priority task attempting to obtain a mutex caused a lower
2274 * priority task to inherit the higher priority task's priority - but the higher
2275 * priority task then timed out without obtaining the mutex, then the lower
2276 * priority task will disinherit the priority again - but only down as far as
2277 * the highest priority task that is still waiting for the mutex (if there were
2278 * more than one task waiting for the mutex).
2280 void vTaskPriorityDisinheritAfterTimeout( TaskHandle_t const pxMutexHolder, UBaseType_t uxHighestPriorityWaitingTask ) PRIVILEGED_FUNCTION;
2283 * Get the uxTCBNumber assigned to the task referenced by the xTask parameter.
2285 UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
2288 * Set the uxTaskNumber of the task referenced by the xTask parameter to
2291 void vTaskSetTaskNumber( TaskHandle_t xTask, const UBaseType_t uxHandle ) PRIVILEGED_FUNCTION;
2294 * Only available when configUSE_TICKLESS_IDLE is set to 1.
2295 * If tickless mode is being used, or a low power mode is implemented, then
2296 * the tick interrupt will not execute during idle periods. When this is the
2297 * case, the tick count value maintained by the scheduler needs to be kept up
2298 * to date with the actual execution time by being skipped forward by a time
2299 * equal to the idle period.
2301 void vTaskStepTick( const TickType_t xTicksToJump ) PRIVILEGED_FUNCTION;
2304 * Only avilable when configUSE_TICKLESS_IDLE is set to 1.
2305 * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port
2306 * specific sleep function to determine if it is ok to proceed with the sleep,
2307 * and if it is ok to proceed, if it is ok to sleep indefinitely.
2309 * This function is necessary because portSUPPRESS_TICKS_AND_SLEEP() is only
2310 * called with the scheduler suspended, not from within a critical section. It
2311 * is therefore possible for an interrupt to request a context switch between
2312 * portSUPPRESS_TICKS_AND_SLEEP() and the low power mode actually being
2313 * entered. eTaskConfirmSleepModeStatus() should be called from a short
2314 * critical section between the timer being stopped and the sleep mode being
2315 * entered to ensure it is ok to proceed into the sleep mode.
2317 eSleepModeStatus eTaskConfirmSleepModeStatus( void ) PRIVILEGED_FUNCTION;
2320 * For internal use only. Increment the mutex held count when a mutex is
2321 * taken and return the handle of the task that has taken the mutex.
2323 void *pvTaskIncrementMutexHeldCount( void ) PRIVILEGED_FUNCTION;
2326 * For internal use only. Same as vTaskSetTimeOutState(), but without a critial
2329 void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
2335 #endif /* INC_TASK_H */