2 * FreeRTOS Kernel V10.2.0
3 * Copyright (C) 2019 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.2.0"
47 #define tskKERNEL_VERSION_MAJOR 10
48 #define tskKERNEL_VERSION_MINOR 2
49 #define tskKERNEL_VERSION_BUILD 0
51 /* MPU region parameters passed in ulParameters
52 * of MemoryRegion_t struct. */
53 #define tskMPU_REGION_READ_ONLY ( 1UL << 0UL )
54 #define tskMPU_REGION_READ_WRITE ( 1UL << 1UL )
55 #define tskMPU_REGION_EXECUTE_NEVER ( 1UL << 2UL )
56 #define tskMPU_REGION_NORMAL_MEMORY ( 1UL << 3UL )
57 #define tskMPU_REGION_DEVICE_MEMORY ( 1UL << 4UL )
62 * Type by which tasks are referenced. For example, a call to xTaskCreate
63 * returns (via a pointer parameter) an TaskHandle_t variable that can then
64 * be used as a parameter to vTaskDelete to delete the task.
66 * \defgroup TaskHandle_t TaskHandle_t
69 struct tskTaskControlBlock; /* The old naming convention is used to prevent breaking kernel aware debuggers. */
70 typedef struct tskTaskControlBlock* TaskHandle_t;
73 * Defines the prototype to which the application task hook function must
76 typedef BaseType_t (*TaskHookFunction_t)( void * );
78 /* Task states returned by eTaskGetState. */
81 eRunning = 0, /* A task is querying the state of itself, so must be running. */
82 eReady, /* The task being queried is in a read or pending ready list. */
83 eBlocked, /* The task being queried is in the Blocked state. */
84 eSuspended, /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */
85 eDeleted, /* The task being queried has been deleted, but its TCB has not yet been freed. */
86 eInvalid /* Used as an 'invalid state' value. */
89 /* Actions that can be performed when vTaskNotify() is called. */
92 eNoAction = 0, /* Notify the task without updating its notify value. */
93 eSetBits, /* Set bits in the task's notification value. */
94 eIncrement, /* Increment the task's notification value. */
95 eSetValueWithOverwrite, /* Set the task's notification value to a specific value even if the previous value has not yet been read by the task. */
96 eSetValueWithoutOverwrite /* Set the task's notification value if the previous value has been read by the task. */
100 * Used internally only.
102 typedef struct xTIME_OUT
104 BaseType_t xOverflowCount;
105 TickType_t xTimeOnEntering;
109 * Defines the memory ranges allocated to the task when an MPU is used.
111 typedef struct xMEMORY_REGION
114 uint32_t ulLengthInBytes;
115 uint32_t ulParameters;
119 * Parameters required to create an MPU protected task.
121 typedef struct xTASK_PARAMETERS
123 TaskFunction_t pvTaskCode;
124 const char * const pcName; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
125 configSTACK_DEPTH_TYPE usStackDepth;
127 UBaseType_t uxPriority;
128 StackType_t *puxStackBuffer;
129 MemoryRegion_t xRegions[ portNUM_CONFIGURABLE_REGIONS ];
130 #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
131 StaticTask_t * const pxTaskBuffer;
135 /* Used with the uxTaskGetSystemState() function to return the state of each task
137 typedef struct xTASK_STATUS
139 TaskHandle_t xHandle; /* The handle of the task to which the rest of the information in the structure relates. */
140 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. */
141 UBaseType_t xTaskNumber; /* A number unique to the task. */
142 eTaskState eCurrentState; /* The state in which the task existed when the structure was populated. */
143 UBaseType_t uxCurrentPriority; /* The priority at which the task was running (may be inherited) when the structure was populated. */
144 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. */
145 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. */
146 StackType_t *pxStackBase; /* Points to the lowest address of the task's stack area. */
147 configSTACK_DEPTH_TYPE usStackHighWaterMark; /* The minimum amount of stack space that has remained for the task since the task was created. The closer this value is to zero the closer the task has come to overflowing its stack. */
150 /* Possible return values for eTaskConfirmSleepModeStatus(). */
153 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. */
154 eStandardSleep, /* Enter a sleep mode that will not last any longer than the expected idle time. */
155 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. */
159 * Defines the priority used by the idle task. This must not be modified.
163 #define tskIDLE_PRIORITY ( ( UBaseType_t ) 0U )
168 * Macro for forcing a context switch.
170 * \defgroup taskYIELD taskYIELD
171 * \ingroup SchedulerControl
173 #define taskYIELD() portYIELD()
178 * Macro to mark the start of a critical code region. Preemptive context
179 * switches cannot occur when in a critical region.
181 * NOTE: This may alter the stack (depending on the portable implementation)
182 * so must be used with care!
184 * \defgroup taskENTER_CRITICAL taskENTER_CRITICAL
185 * \ingroup SchedulerControl
187 #define taskENTER_CRITICAL() portENTER_CRITICAL()
188 #define taskENTER_CRITICAL_FROM_ISR() portSET_INTERRUPT_MASK_FROM_ISR()
193 * Macro to mark the end of a critical code region. Preemptive context
194 * switches cannot occur when in a critical region.
196 * NOTE: This may alter the stack (depending on the portable implementation)
197 * so must be used with care!
199 * \defgroup taskEXIT_CRITICAL taskEXIT_CRITICAL
200 * \ingroup SchedulerControl
202 #define taskEXIT_CRITICAL() portEXIT_CRITICAL()
203 #define taskEXIT_CRITICAL_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( x )
207 * Macro to disable all maskable interrupts.
209 * \defgroup taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS
210 * \ingroup SchedulerControl
212 #define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS()
217 * Macro to enable microcontroller interrupts.
219 * \defgroup taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS
220 * \ingroup SchedulerControl
222 #define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS()
224 /* Definitions returned by xTaskGetSchedulerState(). taskSCHEDULER_SUSPENDED is
225 0 to generate more optimal code when configASSERT() is defined as the constant
226 is used in assert() statements. */
227 #define taskSCHEDULER_SUSPENDED ( ( BaseType_t ) 0 )
228 #define taskSCHEDULER_NOT_STARTED ( ( BaseType_t ) 1 )
229 #define taskSCHEDULER_RUNNING ( ( BaseType_t ) 2 )
232 /*-----------------------------------------------------------
234 *----------------------------------------------------------*/
239 BaseType_t xTaskCreate(
240 TaskFunction_t pvTaskCode,
241 const char * const pcName,
242 configSTACK_DEPTH_TYPE usStackDepth,
244 UBaseType_t uxPriority,
245 TaskHandle_t *pvCreatedTask
248 * Create a new task and add it to the list of tasks that are ready to run.
250 * Internally, within the FreeRTOS implementation, tasks use two blocks of
251 * memory. The first block is used to hold the task's data structures. The
252 * second block is used by the task as its stack. If a task is created using
253 * xTaskCreate() then both blocks of memory are automatically dynamically
254 * allocated inside the xTaskCreate() function. (see
255 * http://www.freertos.org/a00111.html). If a task is created using
256 * xTaskCreateStatic() then the application writer must provide the required
257 * memory. xTaskCreateStatic() therefore allows a task to be created without
258 * using any dynamic memory allocation.
260 * See xTaskCreateStatic() for a version that does not use any dynamic memory
263 * xTaskCreate() can only be used to create a task that has unrestricted
264 * access to the entire microcontroller memory map. Systems that include MPU
265 * support can alternatively create an MPU constrained task using
266 * xTaskCreateRestricted().
268 * @param pvTaskCode Pointer to the task entry function. Tasks
269 * must be implemented to never return (i.e. continuous loop).
271 * @param pcName A descriptive name for the task. This is mainly used to
272 * facilitate debugging. Max length defined by configMAX_TASK_NAME_LEN - default
275 * @param usStackDepth The size of the task stack specified as the number of
276 * variables the stack can hold - not the number of bytes. For example, if
277 * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
278 * will be allocated for stack storage.
280 * @param pvParameters Pointer that will be used as the parameter for the task
283 * @param uxPriority The priority at which the task should run. Systems that
284 * include MPU support can optionally create tasks in a privileged (system)
285 * mode by setting bit portPRIVILEGE_BIT of the priority parameter. For
286 * example, to create a privileged task at priority 2 the uxPriority parameter
287 * should be set to ( 2 | portPRIVILEGE_BIT ).
289 * @param pvCreatedTask Used to pass back a handle by which the created task
292 * @return pdPASS if the task was successfully created and added to a ready
293 * list, otherwise an error code defined in the file projdefs.h
297 // Task to be created.
298 void vTaskCode( void * pvParameters )
302 // Task code goes here.
306 // Function that creates a task.
307 void vOtherFunction( void )
309 static uint8_t ucParameterToPass;
310 TaskHandle_t xHandle = NULL;
312 // Create the task, storing the handle. Note that the passed parameter ucParameterToPass
313 // must exist for the lifetime of the task, so in this case is declared static. If it was just an
314 // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
315 // the new task attempts to access it.
316 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
317 configASSERT( xHandle );
319 // Use the handle to delete the task.
320 if( xHandle != NULL )
322 vTaskDelete( xHandle );
326 * \defgroup xTaskCreate xTaskCreate
329 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
330 BaseType_t xTaskCreate( TaskFunction_t pxTaskCode,
331 const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
332 const configSTACK_DEPTH_TYPE usStackDepth,
333 void * const pvParameters,
334 UBaseType_t uxPriority,
335 TaskHandle_t * const pxCreatedTask ) PRIVILEGED_FUNCTION;
341 TaskHandle_t xTaskCreateStatic( TaskFunction_t pvTaskCode,
342 const char * const pcName,
343 uint32_t ulStackDepth,
345 UBaseType_t uxPriority,
346 StackType_t *pxStackBuffer,
347 StaticTask_t *pxTaskBuffer );</pre>
349 * Create a new task and add it to the list of tasks that are ready to run.
351 * Internally, within the FreeRTOS implementation, tasks use two blocks of
352 * memory. The first block is used to hold the task's data structures. The
353 * second block is used by the task as its stack. If a task is created using
354 * xTaskCreate() then both blocks of memory are automatically dynamically
355 * allocated inside the xTaskCreate() function. (see
356 * http://www.freertos.org/a00111.html). If a task is created using
357 * xTaskCreateStatic() then the application writer must provide the required
358 * memory. xTaskCreateStatic() therefore allows a task to be created without
359 * using any dynamic memory allocation.
361 * @param pvTaskCode Pointer to the task entry function. Tasks
362 * must be implemented to never return (i.e. continuous loop).
364 * @param pcName A descriptive name for the task. This is mainly used to
365 * facilitate debugging. The maximum length of the string is defined by
366 * configMAX_TASK_NAME_LEN in FreeRTOSConfig.h.
368 * @param ulStackDepth The size of the task stack specified as the number of
369 * variables the stack can hold - not the number of bytes. For example, if
370 * the stack is 32-bits wide and ulStackDepth is defined as 100 then 400 bytes
371 * will be allocated for stack storage.
373 * @param pvParameters Pointer that will be used as the parameter for the task
376 * @param uxPriority The priority at which the task will run.
378 * @param pxStackBuffer Must point to a StackType_t array that has at least
379 * ulStackDepth indexes - the array will then be used as the task's stack,
380 * removing the need for the stack to be allocated dynamically.
382 * @param pxTaskBuffer Must point to a variable of type StaticTask_t, which will
383 * then be used to hold the task's data structures, removing the need for the
384 * memory to be allocated dynamically.
386 * @return If neither pxStackBuffer or pxTaskBuffer are NULL, then the task will
387 * be created and a handle to the created task is returned. If either
388 * pxStackBuffer or pxTaskBuffer are NULL then the task will not be created and
394 // Dimensions the buffer that the task being created will use as its stack.
395 // NOTE: This is the number of words the stack will hold, not the number of
396 // bytes. For example, if each stack item is 32-bits, and this is set to 100,
397 // then 400 bytes (100 * 32-bits) will be allocated.
398 #define STACK_SIZE 200
400 // Structure that will hold the TCB of the task being created.
401 StaticTask_t xTaskBuffer;
403 // Buffer that the task being created will use as its stack. Note this is
404 // an array of StackType_t variables. The size of StackType_t is dependent on
406 StackType_t xStack[ STACK_SIZE ];
408 // Function that implements the task being created.
409 void vTaskCode( void * pvParameters )
411 // The parameter value is expected to be 1 as 1 is passed in the
412 // pvParameters value in the call to xTaskCreateStatic().
413 configASSERT( ( uint32_t ) pvParameters == 1UL );
417 // Task code goes here.
421 // Function that creates a task.
422 void vOtherFunction( void )
424 TaskHandle_t xHandle = NULL;
426 // Create the task without using any dynamic memory allocation.
427 xHandle = xTaskCreateStatic(
428 vTaskCode, // Function that implements the task.
429 "NAME", // Text name for the task.
430 STACK_SIZE, // Stack size in words, not bytes.
431 ( void * ) 1, // Parameter passed into the task.
432 tskIDLE_PRIORITY,// Priority at which the task is created.
433 xStack, // Array to use as the task's stack.
434 &xTaskBuffer ); // Variable to hold the task's data structure.
436 // puxStackBuffer and pxTaskBuffer were not NULL, so the task will have
437 // been created, and xHandle will be the task's handle. Use the handle
438 // to suspend the task.
439 vTaskSuspend( xHandle );
442 * \defgroup xTaskCreateStatic xTaskCreateStatic
445 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
446 TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,
447 const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
448 const uint32_t ulStackDepth,
449 void * const pvParameters,
450 UBaseType_t uxPriority,
451 StackType_t * const puxStackBuffer,
452 StaticTask_t * const pxTaskBuffer ) PRIVILEGED_FUNCTION;
453 #endif /* configSUPPORT_STATIC_ALLOCATION */
458 BaseType_t xTaskCreateRestricted( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );</pre>
460 * Only available when configSUPPORT_DYNAMIC_ALLOCATION is set to 1.
462 * xTaskCreateRestricted() should only be used in systems that include an MPU
465 * Create a new task and add it to the list of tasks that are ready to run.
466 * The function parameters define the memory regions and associated access
467 * permissions allocated to the task.
469 * See xTaskCreateRestrictedStatic() for a version that does not use any
470 * dynamic memory allocation.
472 * @param pxTaskDefinition Pointer to a structure that contains a member
473 * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API
474 * documentation) plus an optional stack buffer and the memory region
477 * @param pxCreatedTask Used to pass back a handle by which the created task
480 * @return pdPASS if the task was successfully created and added to a ready
481 * list, otherwise an error code defined in the file projdefs.h
485 // Create an TaskParameters_t structure that defines the task to be created.
486 static const TaskParameters_t xCheckTaskParameters =
488 vATask, // pvTaskCode - the function that implements the task.
489 "ATask", // pcName - just a text name for the task to assist debugging.
490 100, // usStackDepth - the stack size DEFINED IN WORDS.
491 NULL, // pvParameters - passed into the task function as the function parameters.
492 ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
493 cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
495 // xRegions - Allocate up to three separate memory regions for access by
496 // the task, with appropriate access permissions. Different processors have
497 // different memory alignment requirements - refer to the FreeRTOS documentation
498 // for full information.
500 // Base address Length Parameters
501 { cReadWriteArray, 32, portMPU_REGION_READ_WRITE },
502 { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY },
503 { cPrivilegedOnlyAccessArray, 128, portMPU_REGION_PRIVILEGED_READ_WRITE }
509 TaskHandle_t xHandle;
511 // Create a task from the const structure defined above. The task handle
512 // is requested (the second parameter is not NULL) but in this case just for
513 // demonstration purposes as its not actually used.
514 xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
516 // Start the scheduler.
517 vTaskStartScheduler();
519 // Will only get here if there was insufficient memory to create the idle
520 // and/or timer task.
524 * \defgroup xTaskCreateRestricted xTaskCreateRestricted
527 #if( portUSING_MPU_WRAPPERS == 1 )
528 BaseType_t xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ) PRIVILEGED_FUNCTION;
534 BaseType_t xTaskCreateRestrictedStatic( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );</pre>
536 * Only available when configSUPPORT_STATIC_ALLOCATION is set to 1.
538 * xTaskCreateRestrictedStatic() should only be used in systems that include an
539 * MPU implementation.
541 * Internally, within the FreeRTOS implementation, tasks use two blocks of
542 * memory. The first block is used to hold the task's data structures. The
543 * second block is used by the task as its stack. If a task is created using
544 * xTaskCreateRestricted() then the stack is provided by the application writer,
545 * and the memory used to hold the task's data structure is automatically
546 * dynamically allocated inside the xTaskCreateRestricted() function. If a task
547 * is created using xTaskCreateRestrictedStatic() then the application writer
548 * must provide the memory used to hold the task's data structures too.
549 * xTaskCreateRestrictedStatic() therefore allows a memory protected task to be
550 * created without using any dynamic memory allocation.
552 * @param pxTaskDefinition Pointer to a structure that contains a member
553 * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API
554 * documentation) plus an optional stack buffer and the memory region
555 * definitions. If configSUPPORT_STATIC_ALLOCATION is set to 1 the structure
556 * contains an additional member, which is used to point to a variable of type
557 * StaticTask_t - which is then used to hold the task's data structure.
559 * @param pxCreatedTask Used to pass back a handle by which the created task
562 * @return pdPASS if the task was successfully created and added to a ready
563 * list, otherwise an error code defined in the file projdefs.h
567 // Create an TaskParameters_t structure that defines the task to be created.
568 // The StaticTask_t variable is only included in the structure when
569 // configSUPPORT_STATIC_ALLOCATION is set to 1. The PRIVILEGED_DATA macro can
570 // be used to force the variable into the RTOS kernel's privileged data area.
571 static PRIVILEGED_DATA StaticTask_t xTaskBuffer;
572 static const TaskParameters_t xCheckTaskParameters =
574 vATask, // pvTaskCode - the function that implements the task.
575 "ATask", // pcName - just a text name for the task to assist debugging.
576 100, // usStackDepth - the stack size DEFINED IN WORDS.
577 NULL, // pvParameters - passed into the task function as the function parameters.
578 ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
579 cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
581 // xRegions - Allocate up to three separate memory regions for access by
582 // the task, with appropriate access permissions. Different processors have
583 // different memory alignment requirements - refer to the FreeRTOS documentation
584 // for full information.
586 // Base address Length Parameters
587 { cReadWriteArray, 32, portMPU_REGION_READ_WRITE },
588 { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY },
589 { cPrivilegedOnlyAccessArray, 128, portMPU_REGION_PRIVILEGED_READ_WRITE }
592 &xTaskBuffer; // Holds the task's data structure.
597 TaskHandle_t xHandle;
599 // Create a task from the const structure defined above. The task handle
600 // is requested (the second parameter is not NULL) but in this case just for
601 // demonstration purposes as its not actually used.
602 xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
604 // Start the scheduler.
605 vTaskStartScheduler();
607 // Will only get here if there was insufficient memory to create the idle
608 // and/or timer task.
612 * \defgroup xTaskCreateRestrictedStatic xTaskCreateRestrictedStatic
615 #if( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
616 BaseType_t xTaskCreateRestrictedStatic( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ) PRIVILEGED_FUNCTION;
622 void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions );</pre>
624 * Memory regions are assigned to a restricted task when the task is created by
625 * a call to xTaskCreateRestricted(). These regions can be redefined using
626 * vTaskAllocateMPURegions().
628 * @param xTask The handle of the task being updated.
630 * @param xRegions A pointer to an MemoryRegion_t structure that contains the
631 * new memory region definitions.
635 // Define an array of MemoryRegion_t structures that configures an MPU region
636 // allowing read/write access for 1024 bytes starting at the beginning of the
637 // ucOneKByte array. The other two of the maximum 3 definable regions are
638 // unused so set to zero.
639 static const MemoryRegion_t xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] =
641 // Base address Length Parameters
642 { ucOneKByte, 1024, portMPU_REGION_READ_WRITE },
647 void vATask( void *pvParameters )
649 // This task was created such that it has access to certain regions of
650 // memory as defined by the MPU configuration. At some point it is
651 // desired that these MPU regions are replaced with that defined in the
652 // xAltRegions const struct above. Use a call to vTaskAllocateMPURegions()
653 // for this purpose. NULL is used as the task handle to indicate that this
654 // function should modify the MPU regions of the calling task.
655 vTaskAllocateMPURegions( NULL, xAltRegions );
657 // Now the task can continue its function, but from this point on can only
658 // access its stack and the ucOneKByte array (unless any other statically
659 // defined or shared regions have been declared elsewhere).
662 * \defgroup xTaskCreateRestricted xTaskCreateRestricted
665 void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions ) PRIVILEGED_FUNCTION;
669 * <pre>void vTaskDelete( TaskHandle_t xTask );</pre>
671 * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.
672 * See the configuration section for more information.
674 * Remove a task from the RTOS real time kernel's management. The task being
675 * deleted will be removed from all ready, blocked, suspended and event lists.
677 * NOTE: The idle task is responsible for freeing the kernel allocated
678 * memory from tasks that have been deleted. It is therefore important that
679 * the idle task is not starved of microcontroller processing time if your
680 * application makes any calls to vTaskDelete (). Memory allocated by the
681 * task code is not automatically freed, and should be freed before the task
684 * See the demo application file death.c for sample code that utilises
687 * @param xTask The handle of the task to be deleted. Passing NULL will
688 * cause the calling task to be deleted.
692 void vOtherFunction( void )
694 TaskHandle_t xHandle;
696 // Create the task, storing the handle.
697 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
699 // Use the handle to delete the task.
700 vTaskDelete( xHandle );
703 * \defgroup vTaskDelete vTaskDelete
706 void vTaskDelete( TaskHandle_t xTaskToDelete ) PRIVILEGED_FUNCTION;
708 /*-----------------------------------------------------------
710 *----------------------------------------------------------*/
714 * <pre>void vTaskDelay( const TickType_t xTicksToDelay );</pre>
716 * Delay a task for a given number of ticks. The actual time that the
717 * task remains blocked depends on the tick rate. The constant
718 * portTICK_PERIOD_MS can be used to calculate real time from the tick
719 * rate - with the resolution of one tick period.
721 * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
722 * See the configuration section for more information.
725 * vTaskDelay() specifies a time at which the task wishes to unblock relative to
726 * the time at which vTaskDelay() is called. For example, specifying a block
727 * period of 100 ticks will cause the task to unblock 100 ticks after
728 * vTaskDelay() is called. vTaskDelay() does not therefore provide a good method
729 * of controlling the frequency of a periodic task as the path taken through the
730 * code, as well as other task and interrupt activity, will effect the frequency
731 * at which vTaskDelay() gets called and therefore the time at which the task
732 * next executes. See vTaskDelayUntil() for an alternative API function designed
733 * to facilitate fixed frequency execution. It does this by specifying an
734 * absolute time (rather than a relative time) at which the calling task should
737 * @param xTicksToDelay The amount of time, in tick periods, that
738 * the calling task should block.
742 void vTaskFunction( void * pvParameters )
745 const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
749 // Simply toggle the LED every 500ms, blocking between each toggle.
751 vTaskDelay( xDelay );
755 * \defgroup vTaskDelay vTaskDelay
758 void vTaskDelay( const TickType_t xTicksToDelay ) PRIVILEGED_FUNCTION;
762 * <pre>void vTaskDelayUntil( TickType_t *pxPreviousWakeTime, const TickType_t xTimeIncrement );</pre>
764 * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available.
765 * See the configuration section for more information.
767 * Delay a task until a specified time. This function can be used by periodic
768 * tasks to ensure a constant execution frequency.
770 * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will
771 * cause a task to block for the specified number of ticks from the time vTaskDelay () is
772 * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed
773 * execution frequency as the time between a task starting to execute and that task
774 * calling vTaskDelay () may not be fixed [the task may take a different path though the
775 * code between calls, or may get interrupted or preempted a different number of times
776 * each time it executes].
778 * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
779 * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
782 * The constant portTICK_PERIOD_MS can be used to calculate real time from the tick
783 * rate - with the resolution of one tick period.
785 * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
786 * task was last unblocked. The variable must be initialised with the current time
787 * prior to its first use (see the example below). Following this the variable is
788 * automatically updated within vTaskDelayUntil ().
790 * @param xTimeIncrement The cycle time period. The task will be unblocked at
791 * time *pxPreviousWakeTime + xTimeIncrement. Calling vTaskDelayUntil with the
792 * same xTimeIncrement parameter value will cause the task to execute with
793 * a fixed interface period.
797 // Perform an action every 10 ticks.
798 void vTaskFunction( void * pvParameters )
800 TickType_t xLastWakeTime;
801 const TickType_t xFrequency = 10;
803 // Initialise the xLastWakeTime variable with the current time.
804 xLastWakeTime = xTaskGetTickCount ();
807 // Wait for the next cycle.
808 vTaskDelayUntil( &xLastWakeTime, xFrequency );
810 // Perform action here.
814 * \defgroup vTaskDelayUntil vTaskDelayUntil
817 void vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, const TickType_t xTimeIncrement ) PRIVILEGED_FUNCTION;
821 * <pre>BaseType_t xTaskAbortDelay( TaskHandle_t xTask );</pre>
823 * INCLUDE_xTaskAbortDelay must be defined as 1 in FreeRTOSConfig.h for this
824 * function to be available.
826 * A task will enter the Blocked state when it is waiting for an event. The
827 * event it is waiting for can be a temporal event (waiting for a time), such
828 * as when vTaskDelay() is called, or an event on an object, such as when
829 * xQueueReceive() or ulTaskNotifyTake() is called. If the handle of a task
830 * that is in the Blocked state is used in a call to xTaskAbortDelay() then the
831 * task will leave the Blocked state, and return from whichever function call
832 * placed the task into the Blocked state.
834 * @param xTask The handle of the task to remove from the Blocked state.
836 * @return If the task referenced by xTask was not in the Blocked state then
837 * pdFAIL is returned. Otherwise pdPASS is returned.
839 * \defgroup xTaskAbortDelay xTaskAbortDelay
842 BaseType_t xTaskAbortDelay( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
846 * <pre>UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask );</pre>
848 * INCLUDE_uxTaskPriorityGet must be defined as 1 for this function to be available.
849 * See the configuration section for more information.
851 * Obtain the priority of any task.
853 * @param xTask Handle of the task to be queried. Passing a NULL
854 * handle results in the priority of the calling task being returned.
856 * @return The priority of xTask.
860 void vAFunction( void )
862 TaskHandle_t xHandle;
864 // Create a task, storing the handle.
865 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
869 // Use the handle to obtain the priority of the created task.
870 // It was created with tskIDLE_PRIORITY, but may have changed
872 if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
874 // The task has changed it's priority.
879 // Is our priority higher than the created task?
880 if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
882 // Our priority (obtained using NULL handle) is higher.
886 * \defgroup uxTaskPriorityGet uxTaskPriorityGet
889 UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
893 * <pre>UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask );</pre>
895 * A version of uxTaskPriorityGet() that can be used from an ISR.
897 UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
901 * <pre>eTaskState eTaskGetState( TaskHandle_t xTask );</pre>
903 * INCLUDE_eTaskGetState must be defined as 1 for this function to be available.
904 * See the configuration section for more information.
906 * Obtain the state of any task. States are encoded by the eTaskState
909 * @param xTask Handle of the task to be queried.
911 * @return The state of xTask at the time the function was called. Note the
912 * state of the task might change between the function being called, and the
913 * functions return value being tested by the calling task.
915 eTaskState eTaskGetState( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
919 * <pre>void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState );</pre>
921 * configUSE_TRACE_FACILITY must be defined as 1 for this function to be
922 * available. See the configuration section for more information.
924 * Populates a TaskStatus_t structure with information about a task.
926 * @param xTask Handle of the task being queried. If xTask is NULL then
927 * information will be returned about the calling task.
929 * @param pxTaskStatus A pointer to the TaskStatus_t structure that will be
930 * filled with information about the task referenced by the handle passed using
931 * the xTask parameter.
933 * @xGetFreeStackSpace The TaskStatus_t structure contains a member to report
934 * the stack high water mark of the task being queried. Calculating the stack
935 * high water mark takes a relatively long time, and can make the system
936 * temporarily unresponsive - so the xGetFreeStackSpace parameter is provided to
937 * allow the high water mark checking to be skipped. The high watermark value
938 * will only be written to the TaskStatus_t structure if xGetFreeStackSpace is
939 * not set to pdFALSE;
941 * @param eState The TaskStatus_t structure contains a member to report the
942 * state of the task being queried. Obtaining the task state is not as fast as
943 * a simple assignment - so the eState parameter is provided to allow the state
944 * information to be omitted from the TaskStatus_t structure. To obtain state
945 * information then set eState to eInvalid - otherwise the value passed in
946 * eState will be reported as the task state in the TaskStatus_t structure.
950 void vAFunction( void )
952 TaskHandle_t xHandle;
953 TaskStatus_t xTaskDetails;
955 // Obtain the handle of a task from its name.
956 xHandle = xTaskGetHandle( "Task_Name" );
958 // Check the handle is not NULL.
959 configASSERT( xHandle );
961 // Use the handle to obtain further information about the task.
962 vTaskGetInfo( xHandle,
964 pdTRUE, // Include the high water mark in xTaskDetails.
965 eInvalid ); // Include the task state in xTaskDetails.
968 * \defgroup vTaskGetInfo vTaskGetInfo
971 void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState ) PRIVILEGED_FUNCTION;
975 * <pre>void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority );</pre>
977 * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
978 * See the configuration section for more information.
980 * Set the priority of any task.
982 * A context switch will occur before the function returns if the priority
983 * being set is higher than the currently executing task.
985 * @param xTask Handle to the task for which the priority is being set.
986 * Passing a NULL handle results in the priority of the calling task being set.
988 * @param uxNewPriority The priority to which the task will be set.
992 void vAFunction( void )
994 TaskHandle_t xHandle;
996 // Create a task, storing the handle.
997 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
1001 // Use the handle to raise the priority of the created task.
1002 vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
1006 // Use a NULL handle to raise our priority to the same value.
1007 vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
1010 * \defgroup vTaskPrioritySet vTaskPrioritySet
1013 void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority ) PRIVILEGED_FUNCTION;
1017 * <pre>void vTaskSuspend( TaskHandle_t xTaskToSuspend );</pre>
1019 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
1020 * See the configuration section for more information.
1022 * Suspend any task. When suspended a task will never get any microcontroller
1023 * processing time, no matter what its priority.
1025 * Calls to vTaskSuspend are not accumulative -
1026 * i.e. calling vTaskSuspend () twice on the same task still only requires one
1027 * call to vTaskResume () to ready the suspended task.
1029 * @param xTaskToSuspend Handle to the task being suspended. Passing a NULL
1030 * handle will cause the calling task to be suspended.
1034 void vAFunction( void )
1036 TaskHandle_t xHandle;
1038 // Create a task, storing the handle.
1039 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
1043 // Use the handle to suspend the created task.
1044 vTaskSuspend( xHandle );
1048 // The created task will not run during this period, unless
1049 // another task calls vTaskResume( xHandle ).
1054 // Suspend ourselves.
1055 vTaskSuspend( NULL );
1057 // We cannot get here unless another task calls vTaskResume
1058 // with our handle as the parameter.
1061 * \defgroup vTaskSuspend vTaskSuspend
1064 void vTaskSuspend( TaskHandle_t xTaskToSuspend ) PRIVILEGED_FUNCTION;
1068 * <pre>void vTaskResume( TaskHandle_t xTaskToResume );</pre>
1070 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
1071 * See the configuration section for more information.
1073 * Resumes a suspended task.
1075 * A task that has been suspended by one or more calls to vTaskSuspend ()
1076 * will be made available for running again by a single call to
1079 * @param xTaskToResume Handle to the task being readied.
1083 void vAFunction( void )
1085 TaskHandle_t xHandle;
1087 // Create a task, storing the handle.
1088 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
1092 // Use the handle to suspend the created task.
1093 vTaskSuspend( xHandle );
1097 // The created task will not run during this period, unless
1098 // another task calls vTaskResume( xHandle ).
1103 // Resume the suspended task ourselves.
1104 vTaskResume( xHandle );
1106 // The created task will once again get microcontroller processing
1107 // time in accordance with its priority within the system.
1110 * \defgroup vTaskResume vTaskResume
1113 void vTaskResume( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
1117 * <pre>void xTaskResumeFromISR( TaskHandle_t xTaskToResume );</pre>
1119 * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
1120 * available. See the configuration section for more information.
1122 * An implementation of vTaskResume() that can be called from within an ISR.
1124 * A task that has been suspended by one or more calls to vTaskSuspend ()
1125 * will be made available for running again by a single call to
1126 * xTaskResumeFromISR ().
1128 * xTaskResumeFromISR() should not be used to synchronise a task with an
1129 * interrupt if there is a chance that the interrupt could arrive prior to the
1130 * task being suspended - as this can lead to interrupts being missed. Use of a
1131 * semaphore as a synchronisation mechanism would avoid this eventuality.
1133 * @param xTaskToResume Handle to the task being readied.
1135 * @return pdTRUE if resuming the task should result in a context switch,
1136 * otherwise pdFALSE. This is used by the ISR to determine if a context switch
1137 * may be required following the ISR.
1139 * \defgroup vTaskResumeFromISR vTaskResumeFromISR
1142 BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
1144 /*-----------------------------------------------------------
1146 *----------------------------------------------------------*/
1150 * <pre>void vTaskStartScheduler( void );</pre>
1152 * Starts the real time kernel tick processing. After calling the kernel
1153 * has control over which tasks are executed and when.
1155 * See the demo application file main.c for an example of creating
1156 * tasks and starting the kernel.
1160 void vAFunction( void )
1162 // Create at least one task before starting the kernel.
1163 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
1165 // Start the real time kernel with preemption.
1166 vTaskStartScheduler ();
1168 // Will not get here unless a task calls vTaskEndScheduler ()
1172 * \defgroup vTaskStartScheduler vTaskStartScheduler
1173 * \ingroup SchedulerControl
1175 void vTaskStartScheduler( void ) PRIVILEGED_FUNCTION;
1179 * <pre>void vTaskEndScheduler( void );</pre>
1181 * NOTE: At the time of writing only the x86 real mode port, which runs on a PC
1182 * in place of DOS, implements this function.
1184 * Stops the real time kernel tick. All created tasks will be automatically
1185 * deleted and multitasking (either preemptive or cooperative) will
1186 * stop. Execution then resumes from the point where vTaskStartScheduler ()
1187 * was called, as if vTaskStartScheduler () had just returned.
1189 * See the demo application file main. c in the demo/PC directory for an
1190 * example that uses vTaskEndScheduler ().
1192 * vTaskEndScheduler () requires an exit function to be defined within the
1193 * portable layer (see vPortEndScheduler () in port. c for the PC port). This
1194 * performs hardware specific operations such as stopping the kernel tick.
1196 * vTaskEndScheduler () will cause all of the resources allocated by the
1197 * kernel to be freed - but will not free resources allocated by application
1202 void vTaskCode( void * pvParameters )
1206 // Task code goes here.
1208 // At some point we want to end the real time kernel processing
1210 vTaskEndScheduler ();
1214 void vAFunction( void )
1216 // Create at least one task before starting the kernel.
1217 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
1219 // Start the real time kernel with preemption.
1220 vTaskStartScheduler ();
1222 // Will only get here when the vTaskCode () task has called
1223 // vTaskEndScheduler (). When we get here we are back to single task
1228 * \defgroup vTaskEndScheduler vTaskEndScheduler
1229 * \ingroup SchedulerControl
1231 void vTaskEndScheduler( void ) PRIVILEGED_FUNCTION;
1235 * <pre>void vTaskSuspendAll( void );</pre>
1237 * Suspends the scheduler without disabling interrupts. Context switches will
1238 * not occur while the scheduler is suspended.
1240 * After calling vTaskSuspendAll () the calling task will continue to execute
1241 * without risk of being swapped out until a call to xTaskResumeAll () has been
1244 * API functions that have the potential to cause a context switch (for example,
1245 * vTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler
1250 void vTask1( void * pvParameters )
1254 // Task code goes here.
1258 // At some point the task wants to perform a long operation during
1259 // which it does not want to get swapped out. It cannot use
1260 // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
1261 // operation may cause interrupts to be missed - including the
1264 // Prevent the real time kernel swapping out the task.
1267 // Perform the operation here. There is no need to use critical
1268 // sections as we have all the microcontroller processing time.
1269 // During this time interrupts will still operate and the kernel
1270 // tick count will be maintained.
1274 // The operation is complete. Restart the kernel.
1279 * \defgroup vTaskSuspendAll vTaskSuspendAll
1280 * \ingroup SchedulerControl
1282 void vTaskSuspendAll( void ) PRIVILEGED_FUNCTION;
1286 * <pre>BaseType_t xTaskResumeAll( void );</pre>
1288 * Resumes scheduler activity after it was suspended by a call to
1289 * vTaskSuspendAll().
1291 * xTaskResumeAll() only resumes the scheduler. It does not unsuspend tasks
1292 * that were previously suspended by a call to vTaskSuspend().
1294 * @return If resuming the scheduler caused a context switch then pdTRUE is
1295 * returned, otherwise pdFALSE is returned.
1299 void vTask1( void * pvParameters )
1303 // Task code goes here.
1307 // At some point the task wants to perform a long operation during
1308 // which it does not want to get swapped out. It cannot use
1309 // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
1310 // operation may cause interrupts to be missed - including the
1313 // Prevent the real time kernel swapping out the task.
1316 // Perform the operation here. There is no need to use critical
1317 // sections as we have all the microcontroller processing time.
1318 // During this time interrupts will still operate and the real
1319 // time kernel tick count will be maintained.
1323 // The operation is complete. Restart the kernel. We want to force
1324 // a context switch - but there is no point if resuming the scheduler
1325 // caused a context switch already.
1326 if( !xTaskResumeAll () )
1333 * \defgroup xTaskResumeAll xTaskResumeAll
1334 * \ingroup SchedulerControl
1336 BaseType_t xTaskResumeAll( void ) PRIVILEGED_FUNCTION;
1338 /*-----------------------------------------------------------
1340 *----------------------------------------------------------*/
1344 * <PRE>TickType_t xTaskGetTickCount( void );</PRE>
1346 * @return The count of ticks since vTaskStartScheduler was called.
1348 * \defgroup xTaskGetTickCount xTaskGetTickCount
1349 * \ingroup TaskUtils
1351 TickType_t xTaskGetTickCount( void ) PRIVILEGED_FUNCTION;
1355 * <PRE>TickType_t xTaskGetTickCountFromISR( void );</PRE>
1357 * @return The count of ticks since vTaskStartScheduler was called.
1359 * This is a version of xTaskGetTickCount() that is safe to be called from an
1360 * ISR - provided that TickType_t is the natural word size of the
1361 * microcontroller being used or interrupt nesting is either not supported or
1364 * \defgroup xTaskGetTickCountFromISR xTaskGetTickCountFromISR
1365 * \ingroup TaskUtils
1367 TickType_t xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION;
1371 * <PRE>uint16_t uxTaskGetNumberOfTasks( void );</PRE>
1373 * @return The number of tasks that the real time kernel is currently managing.
1374 * This includes all ready, blocked and suspended tasks. A task that
1375 * has been deleted but not yet freed by the idle task will also be
1376 * included in the count.
1378 * \defgroup uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
1379 * \ingroup TaskUtils
1381 UBaseType_t uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION;
1385 * <PRE>char *pcTaskGetName( TaskHandle_t xTaskToQuery );</PRE>
1387 * @return The text (human readable) name of the task referenced by the handle
1388 * xTaskToQuery. A task can query its own name by either passing in its own
1389 * handle, or by setting xTaskToQuery to NULL.
1391 * \defgroup pcTaskGetName pcTaskGetName
1392 * \ingroup TaskUtils
1394 char *pcTaskGetName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1398 * <PRE>TaskHandle_t xTaskGetHandle( const char *pcNameToQuery );</PRE>
1400 * NOTE: This function takes a relatively long time to complete and should be
1403 * @return The handle of the task that has the human readable name pcNameToQuery.
1404 * NULL is returned if no matching name is found. INCLUDE_xTaskGetHandle
1405 * must be set to 1 in FreeRTOSConfig.h for pcTaskGetHandle() to be available.
1407 * \defgroup pcTaskGetHandle pcTaskGetHandle
1408 * \ingroup TaskUtils
1410 TaskHandle_t xTaskGetHandle( const char *pcNameToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1414 * <PRE>UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask );</PRE>
1416 * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
1417 * this function to be available.
1419 * Returns the high water mark of the stack associated with xTask. That is,
1420 * the minimum free stack space there has been (in words, so on a 32 bit machine
1421 * a value of 1 means 4 bytes) since the task started. The smaller the returned
1422 * number the closer the task has come to overflowing its stack.
1424 * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
1425 * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
1426 * user to determine the return type. It gets around the problem of the value
1427 * overflowing on 8-bit types without breaking backward compatibility for
1428 * applications that expect an 8-bit return type.
1430 * @param xTask Handle of the task associated with the stack to be checked.
1431 * Set xTask to NULL to check the stack of the calling task.
1433 * @return The smallest amount of free stack space there has been (in words, so
1434 * actual spaces on the stack rather than bytes) since the task referenced by
1435 * xTask was created.
1437 UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1441 * <PRE>configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask );</PRE>
1443 * INCLUDE_uxTaskGetStackHighWaterMark2 must be set to 1 in FreeRTOSConfig.h for
1444 * this function to be available.
1446 * Returns the high water mark of the stack associated with xTask. That is,
1447 * the minimum free stack space there has been (in words, so on a 32 bit machine
1448 * a value of 1 means 4 bytes) since the task started. The smaller the returned
1449 * number the closer the task has come to overflowing its stack.
1451 * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
1452 * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
1453 * user to determine the return type. It gets around the problem of the value
1454 * overflowing on 8-bit types without breaking backward compatibility for
1455 * applications that expect an 8-bit return type.
1457 * @param xTask Handle of the task associated with the stack to be checked.
1458 * Set xTask to NULL to check the stack of the calling task.
1460 * @return The smallest amount of free stack space there has been (in words, so
1461 * actual spaces on the stack rather than bytes) since the task referenced by
1462 * xTask was created.
1464 configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1466 /* When using trace macros it is sometimes necessary to include task.h before
1467 FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined,
1468 so the following two prototypes will cause a compilation error. This can be
1469 fixed by simply guarding against the inclusion of these two prototypes unless
1470 they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration
1472 #ifdef configUSE_APPLICATION_TASK_TAG
1473 #if configUSE_APPLICATION_TASK_TAG == 1
1476 * <pre>void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction );</pre>
1478 * Sets pxHookFunction to be the task hook function used by the task xTask.
1479 * Passing xTask as NULL has the effect of setting the calling tasks hook
1482 void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction ) PRIVILEGED_FUNCTION;
1486 * <pre>void xTaskGetApplicationTaskTag( TaskHandle_t xTask );</pre>
1488 * Returns the pxHookFunction value assigned to the task xTask. Do not
1489 * call from an interrupt service routine - call
1490 * xTaskGetApplicationTaskTagFromISR() instead.
1492 TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1496 * <pre>void xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask );</pre>
1498 * Returns the pxHookFunction value assigned to the task xTask. Can
1499 * be called from an interrupt service routine.
1501 TaskHookFunction_t xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1502 #endif /* configUSE_APPLICATION_TASK_TAG ==1 */
1503 #endif /* ifdef configUSE_APPLICATION_TASK_TAG */
1505 #if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )
1507 /* Each task contains an array of pointers that is dimensioned by the
1508 configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h. The
1509 kernel does not use the pointers itself, so the application writer can use
1510 the pointers for any purpose they wish. The following two functions are
1511 used to set and query a pointer respectively. */
1512 void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue ) PRIVILEGED_FUNCTION;
1513 void *pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, BaseType_t xIndex ) PRIVILEGED_FUNCTION;
1519 * <pre>BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter );</pre>
1521 * Calls the hook function associated with xTask. Passing xTask as NULL has
1522 * the effect of calling the Running tasks (the calling task) hook function.
1524 * pvParameter is passed to the hook function for the task to interpret as it
1525 * wants. The return value is the value returned by the task hook function
1526 * registered by the user.
1528 BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter ) PRIVILEGED_FUNCTION;
1531 * xTaskGetIdleTaskHandle() is only available if
1532 * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.
1534 * Simply returns the handle of the idle task. It is not valid to call
1535 * xTaskGetIdleTaskHandle() before the scheduler has been started.
1537 TaskHandle_t xTaskGetIdleTaskHandle( void ) PRIVILEGED_FUNCTION;
1540 * configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for
1541 * uxTaskGetSystemState() to be available.
1543 * uxTaskGetSystemState() populates an TaskStatus_t structure for each task in
1544 * the system. TaskStatus_t structures contain, among other things, members
1545 * for the task handle, task name, task priority, task state, and total amount
1546 * of run time consumed by the task. See the TaskStatus_t structure
1547 * definition in this file for the full member list.
1549 * NOTE: This function is intended for debugging use only as its use results in
1550 * the scheduler remaining suspended for an extended period.
1552 * @param pxTaskStatusArray A pointer to an array of TaskStatus_t structures.
1553 * The array must contain at least one TaskStatus_t structure for each task
1554 * that is under the control of the RTOS. The number of tasks under the control
1555 * of the RTOS can be determined using the uxTaskGetNumberOfTasks() API function.
1557 * @param uxArraySize The size of the array pointed to by the pxTaskStatusArray
1558 * parameter. The size is specified as the number of indexes in the array, or
1559 * the number of TaskStatus_t structures contained in the array, not by the
1560 * number of bytes in the array.
1562 * @param pulTotalRunTime If configGENERATE_RUN_TIME_STATS is set to 1 in
1563 * FreeRTOSConfig.h then *pulTotalRunTime is set by uxTaskGetSystemState() to the
1564 * total run time (as defined by the run time stats clock, see
1565 * http://www.freertos.org/rtos-run-time-stats.html) since the target booted.
1566 * pulTotalRunTime can be set to NULL to omit the total run time information.
1568 * @return The number of TaskStatus_t structures that were populated by
1569 * uxTaskGetSystemState(). This should equal the number returned by the
1570 * uxTaskGetNumberOfTasks() API function, but will be zero if the value passed
1571 * in the uxArraySize parameter was too small.
1575 // This example demonstrates how a human readable table of run time stats
1576 // information is generated from raw data provided by uxTaskGetSystemState().
1577 // The human readable table is written to pcWriteBuffer
1578 void vTaskGetRunTimeStats( char *pcWriteBuffer )
1580 TaskStatus_t *pxTaskStatusArray;
1581 volatile UBaseType_t uxArraySize, x;
1582 uint32_t ulTotalRunTime, ulStatsAsPercentage;
1584 // Make sure the write buffer does not contain a string.
1585 *pcWriteBuffer = 0x00;
1587 // Take a snapshot of the number of tasks in case it changes while this
1588 // function is executing.
1589 uxArraySize = uxTaskGetNumberOfTasks();
1591 // Allocate a TaskStatus_t structure for each task. An array could be
1592 // allocated statically at compile time.
1593 pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
1595 if( pxTaskStatusArray != NULL )
1597 // Generate raw status information about each task.
1598 uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );
1600 // For percentage calculations.
1601 ulTotalRunTime /= 100UL;
1603 // Avoid divide by zero errors.
1604 if( ulTotalRunTime > 0 )
1606 // For each populated position in the pxTaskStatusArray array,
1607 // format the raw data as human readable ASCII data
1608 for( x = 0; x < uxArraySize; x++ )
1610 // What percentage of the total run time has the task used?
1611 // This will always be rounded down to the nearest integer.
1612 // ulTotalRunTimeDiv100 has already been divided by 100.
1613 ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;
1615 if( ulStatsAsPercentage > 0UL )
1617 sprintf( pcWriteBuffer, "%s\t\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );
1621 // If the percentage is zero here then the task has
1622 // consumed less than 1% of the total run time.
1623 sprintf( pcWriteBuffer, "%s\t\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter );
1626 pcWriteBuffer += strlen( ( char * ) pcWriteBuffer );
1630 // The array is no longer needed, free the memory it consumes.
1631 vPortFree( pxTaskStatusArray );
1636 UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime ) PRIVILEGED_FUNCTION;
1640 * <PRE>void vTaskList( char *pcWriteBuffer );</PRE>
1642 * configUSE_TRACE_FACILITY and configUSE_STATS_FORMATTING_FUNCTIONS must
1643 * both be defined as 1 for this function to be available. See the
1644 * configuration section of the FreeRTOS.org website for more information.
1646 * NOTE 1: This function will disable interrupts for its duration. It is
1647 * not intended for normal application runtime use but as a debug aid.
1649 * Lists all the current tasks, along with their current state and stack
1650 * usage high water mark.
1652 * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or
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 * vTaskList() calls uxTaskGetSystemState(), then formats part of the
1661 * uxTaskGetSystemState() output into a human readable table that displays task
1662 * names, states and stack usage.
1664 * vTaskList() has a dependency on the sprintf() C library function that might
1665 * bloat the code size, use a lot of stack, and provide different results on
1666 * different platforms. An alternative, tiny, third party, and limited
1667 * functionality implementation of sprintf() is provided in many of the
1668 * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
1669 * printf-stdarg.c does not provide a full snprintf() implementation!).
1671 * It is recommended that production systems call uxTaskGetSystemState()
1672 * directly to get access to raw stats data, rather than indirectly through a
1673 * call to vTaskList().
1675 * @param pcWriteBuffer A buffer into which the above mentioned details
1676 * will be written, in ASCII form. This buffer is assumed to be large
1677 * enough to contain the generated report. Approximately 40 bytes per
1678 * task should be sufficient.
1680 * \defgroup vTaskList vTaskList
1681 * \ingroup TaskUtils
1683 void vTaskList( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1687 * <PRE>void vTaskGetRunTimeStats( char *pcWriteBuffer );</PRE>
1689 * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS
1690 * must both be defined as 1 for this function to be available. The application
1691 * must also then provide definitions for
1692 * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()
1693 * to configure a peripheral timer/counter and return the timers current count
1694 * value respectively. The counter should be at least 10 times the frequency of
1697 * NOTE 1: This function will disable interrupts for its duration. It is
1698 * not intended for normal application runtime use but as a debug aid.
1700 * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
1701 * accumulated execution time being stored for each task. The resolution
1702 * of the accumulated time value depends on the frequency of the timer
1703 * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
1704 * Calling vTaskGetRunTimeStats() writes the total execution time of each
1705 * task into a buffer, both as an absolute count value and as a percentage
1706 * of the total system execution time.
1710 * This function is provided for convenience only, and is used by many of the
1711 * demo applications. Do not consider it to be part of the scheduler.
1713 * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part of the
1714 * uxTaskGetSystemState() output into a human readable table that displays the
1715 * amount of time each task has spent in the Running state in both absolute and
1718 * vTaskGetRunTimeStats() has a dependency on the sprintf() C library function
1719 * that might bloat the code size, use a lot of stack, and provide different
1720 * results on different platforms. An alternative, tiny, third party, and
1721 * limited functionality implementation of sprintf() is provided in many of the
1722 * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
1723 * printf-stdarg.c does not provide a full snprintf() implementation!).
1725 * It is recommended that production systems call uxTaskGetSystemState() directly
1726 * to get access to raw stats data, rather than indirectly through a call to
1727 * vTaskGetRunTimeStats().
1729 * @param pcWriteBuffer A buffer into which the execution times will be
1730 * written, in ASCII form. This buffer is assumed to be large enough to
1731 * contain the generated report. Approximately 40 bytes per task should
1734 * \defgroup vTaskGetRunTimeStats vTaskGetRunTimeStats
1735 * \ingroup TaskUtils
1737 void vTaskGetRunTimeStats( char *pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1741 * <PRE>TickType_t xTaskGetIdleRunTimeCounter( void );</PRE>
1743 * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS
1744 * must both be defined as 1 for this function to be available. The application
1745 * must also then provide definitions for
1746 * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()
1747 * to configure a peripheral timer/counter and return the timers current count
1748 * value respectively. The counter should be at least 10 times the frequency of
1751 * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
1752 * accumulated execution time being stored for each task. The resolution
1753 * of the accumulated time value depends on the frequency of the timer
1754 * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
1755 * While uxTaskGetSystemState() and vTaskGetRunTimeStats() writes the total
1756 * execution time of each task into a buffer, xTaskGetIdleRunTimeCounter()
1757 * returns the total execution time of just the idle task.
1759 * @return The total run time of the idle task. This is the amount of time the
1760 * idle task has actually been executing. The unit of time is dependent on the
1761 * frequency configured using the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and
1762 * portGET_RUN_TIME_COUNTER_VALUE() macros.
1764 * \defgroup xTaskGetIdleRunTimeCounter xTaskGetIdleRunTimeCounter
1765 * \ingroup TaskUtils
1767 TickType_t xTaskGetIdleRunTimeCounter( void ) PRIVILEGED_FUNCTION;
1771 * <PRE>BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction );</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 * Events can be sent to a task using an intermediary object. Examples of such
1780 * objects are queues, semaphores, mutexes and event groups. Task notifications
1781 * are a method of sending an event directly to a task without the need for such
1782 * an intermediary object.
1784 * A notification sent to a task can optionally perform an action, such as
1785 * update, overwrite or increment the task's notification value. In that way
1786 * task notifications can be used to send data to a task, or be used as light
1787 * weight and fast binary or counting semaphores.
1789 * A notification sent to a task will remain pending until it is cleared by the
1790 * task calling xTaskNotifyWait() or ulTaskNotifyTake(). If the task was
1791 * already in the Blocked state to wait for a notification when the notification
1792 * arrives then the task will automatically be removed from the Blocked state
1793 * (unblocked) and the notification cleared.
1795 * A task can use xTaskNotifyWait() to [optionally] block to wait for a
1796 * notification to be pending, or ulTaskNotifyTake() to [optionally] block
1797 * to wait for its notification value to have a non-zero value. The task does
1798 * not consume any CPU time while it is in the Blocked state.
1800 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
1802 * @param xTaskToNotify The handle of the task being notified. The handle to a
1803 * task can be returned from the xTaskCreate() API function used to create the
1804 * task, and the handle of the currently running task can be obtained by calling
1805 * xTaskGetCurrentTaskHandle().
1807 * @param ulValue Data that can be sent with the notification. How the data is
1808 * used depends on the value of the eAction parameter.
1810 * @param eAction Specifies how the notification updates the task's notification
1811 * value, if at all. Valid values for eAction are as follows:
1814 * The task's notification value is bitwise ORed with ulValue. xTaskNofify()
1815 * always returns pdPASS in this case.
1818 * The task's notification value is incremented. ulValue is not used and
1819 * xTaskNotify() always returns pdPASS in this case.
1821 * eSetValueWithOverwrite -
1822 * The task's notification value is set to the value of ulValue, even if the
1823 * task being notified had not yet processed the previous notification (the
1824 * task already had a notification pending). xTaskNotify() always returns
1825 * pdPASS in this case.
1827 * eSetValueWithoutOverwrite -
1828 * If the task being notified did not already have a notification pending then
1829 * the task's notification value is set to ulValue and xTaskNotify() will
1830 * return pdPASS. If the task being notified already had a notification
1831 * pending then no action is performed and pdFAIL is returned.
1834 * The task receives a notification without its notification value being
1835 * updated. ulValue is not used and xTaskNotify() always returns pdPASS in
1838 * pulPreviousNotificationValue -
1839 * Can be used to pass out the subject task's notification value before any
1840 * bits are modified by the notify function.
1842 * @return Dependent on the value of eAction. See the description of the
1843 * eAction parameter.
1845 * \defgroup xTaskNotify xTaskNotify
1846 * \ingroup TaskNotifications
1848 BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue ) PRIVILEGED_FUNCTION;
1849 #define xTaskNotify( xTaskToNotify, ulValue, eAction ) xTaskGenericNotify( ( xTaskToNotify ), ( ulValue ), ( eAction ), NULL )
1850 #define xTaskNotifyAndQuery( xTaskToNotify, ulValue, eAction, pulPreviousNotifyValue ) xTaskGenericNotify( ( xTaskToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) )
1854 * <PRE>BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
1856 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
1857 * function to be available.
1859 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
1860 * "notification value", which is a 32-bit unsigned integer (uint32_t).
1862 * A version of xTaskNotify() that can be used from an interrupt service routine
1865 * Events can be sent to a task using an intermediary object. Examples of such
1866 * objects are queues, semaphores, mutexes and event groups. Task notifications
1867 * are a method of sending an event directly to a task without the need for such
1868 * an intermediary object.
1870 * A notification sent to a task can optionally perform an action, such as
1871 * update, overwrite or increment the task's notification value. In that way
1872 * task notifications can be used to send data to a task, or be used as light
1873 * weight and fast binary or counting semaphores.
1875 * A notification sent to a task will remain pending until it is cleared by the
1876 * task calling xTaskNotifyWait() or ulTaskNotifyTake(). If the task was
1877 * already in the Blocked state to wait for a notification when the notification
1878 * arrives then the task will automatically be removed from the Blocked state
1879 * (unblocked) and the notification cleared.
1881 * A task can use xTaskNotifyWait() to [optionally] block to wait for a
1882 * notification to be pending, or ulTaskNotifyTake() to [optionally] block
1883 * to wait for its notification value to have a non-zero value. The task does
1884 * not consume any CPU time while it is in the Blocked state.
1886 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
1888 * @param xTaskToNotify The handle of the task being notified. The handle to a
1889 * task can be returned from the xTaskCreate() API function used to create the
1890 * task, and the handle of the currently running task can be obtained by calling
1891 * xTaskGetCurrentTaskHandle().
1893 * @param ulValue Data that can be sent with the notification. How the data is
1894 * used depends on the value of the eAction parameter.
1896 * @param eAction Specifies how the notification updates the task's notification
1897 * value, if at all. Valid values for eAction are as follows:
1900 * The task's notification value is bitwise ORed with ulValue. xTaskNofify()
1901 * always returns pdPASS in this case.
1904 * The task's notification value is incremented. ulValue is not used and
1905 * xTaskNotify() always returns pdPASS in this case.
1907 * eSetValueWithOverwrite -
1908 * The task's notification value is set to the value of ulValue, even if the
1909 * task being notified had not yet processed the previous notification (the
1910 * task already had a notification pending). xTaskNotify() always returns
1911 * pdPASS in this case.
1913 * eSetValueWithoutOverwrite -
1914 * If the task being notified did not already have a notification pending then
1915 * the task's notification value is set to ulValue and xTaskNotify() will
1916 * return pdPASS. If the task being notified already had a notification
1917 * pending then no action is performed and pdFAIL is returned.
1920 * The task receives a notification without its notification value being
1921 * updated. ulValue is not used and xTaskNotify() always returns pdPASS in
1924 * @param pxHigherPriorityTaskWoken xTaskNotifyFromISR() will set
1925 * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
1926 * task to which the notification was sent to leave the Blocked state, and the
1927 * unblocked task has a priority higher than the currently running task. If
1928 * xTaskNotifyFromISR() sets this value to pdTRUE then a context switch should
1929 * be requested before the interrupt is exited. How a context switch is
1930 * requested from an ISR is dependent on the port - see the documentation page
1931 * for the port in use.
1933 * @return Dependent on the value of eAction. See the description of the
1934 * eAction parameter.
1936 * \defgroup xTaskNotify xTaskNotify
1937 * \ingroup TaskNotifications
1939 BaseType_t xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1940 #define xTaskNotifyFromISR( xTaskToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) )
1941 #define xTaskNotifyAndQueryFromISR( xTaskToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) )
1945 * <PRE>BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );</pre>
1947 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
1948 * function to be available.
1950 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
1951 * "notification value", which is a 32-bit unsigned integer (uint32_t).
1953 * Events can be sent to a task using an intermediary object. Examples of such
1954 * objects are queues, semaphores, mutexes and event groups. Task notifications
1955 * are a method of sending an event directly to a task without the need for such
1956 * an intermediary object.
1958 * A notification sent to a task can optionally perform an action, such as
1959 * update, overwrite or increment the task's notification value. In that way
1960 * task notifications can be used to send data to a task, or be used as light
1961 * weight and fast binary or counting semaphores.
1963 * A notification sent to a task will remain pending until it is cleared by the
1964 * task calling xTaskNotifyWait() or ulTaskNotifyTake(). If the task was
1965 * already in the Blocked state to wait for a notification when the notification
1966 * arrives then the task will automatically be removed from the Blocked state
1967 * (unblocked) and the notification cleared.
1969 * A task can use xTaskNotifyWait() to [optionally] block to wait for a
1970 * notification to be pending, or ulTaskNotifyTake() to [optionally] block
1971 * to wait for its notification value to have a non-zero value. The task does
1972 * not consume any CPU time while it is in the Blocked state.
1974 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
1976 * @param ulBitsToClearOnEntry Bits that are set in ulBitsToClearOnEntry value
1977 * will be cleared in the calling task's notification value before the task
1978 * checks to see if any notifications are pending, and optionally blocks if no
1979 * notifications are pending. Setting ulBitsToClearOnEntry to ULONG_MAX (if
1980 * limits.h is included) or 0xffffffffUL (if limits.h is not included) will have
1981 * the effect of resetting the task's notification value to 0. Setting
1982 * ulBitsToClearOnEntry to 0 will leave the task's notification value unchanged.
1984 * @param ulBitsToClearOnExit If a notification is pending or received before
1985 * the calling task exits the xTaskNotifyWait() function then the task's
1986 * notification value (see the xTaskNotify() API function) is passed out using
1987 * the pulNotificationValue parameter. Then any bits that are set in
1988 * ulBitsToClearOnExit will be cleared in the task's notification value (note
1989 * *pulNotificationValue is set before any bits are cleared). Setting
1990 * ulBitsToClearOnExit to ULONG_MAX (if limits.h is included) or 0xffffffffUL
1991 * (if limits.h is not included) will have the effect of resetting the task's
1992 * notification value to 0 before the function exits. Setting
1993 * ulBitsToClearOnExit to 0 will leave the task's notification value unchanged
1994 * when the function exits (in which case the value passed out in
1995 * pulNotificationValue will match the task's notification value).
1997 * @param pulNotificationValue Used to pass the task's notification value out
1998 * of the function. Note the value passed out will not be effected by the
1999 * clearing of any bits caused by ulBitsToClearOnExit being non-zero.
2001 * @param xTicksToWait The maximum amount of time that the task should wait in
2002 * the Blocked state for a notification to be received, should a notification
2003 * not already be pending when xTaskNotifyWait() was called. The task
2004 * will not consume any processing time while it is in the Blocked state. This
2005 * is specified in kernel ticks, the macro pdMS_TO_TICSK( value_in_ms ) can be
2006 * used to convert a time specified in milliseconds to a time specified in
2009 * @return If a notification was received (including notifications that were
2010 * already pending when xTaskNotifyWait was called) then pdPASS is
2011 * returned. Otherwise pdFAIL is returned.
2013 * \defgroup xTaskNotifyWait xTaskNotifyWait
2014 * \ingroup TaskNotifications
2016 BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2020 * <PRE>BaseType_t xTaskNotifyGive( TaskHandle_t xTaskToNotify );</PRE>
2022 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
2025 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
2026 * "notification value", which is a 32-bit unsigned integer (uint32_t).
2028 * Events can be sent to a task using an intermediary object. Examples of such
2029 * objects are queues, semaphores, mutexes and event groups. Task notifications
2030 * are a method of sending an event directly to a task without the need for such
2031 * an intermediary object.
2033 * A notification sent to a task can optionally perform an action, such as
2034 * update, overwrite or increment the task's notification value. In that way
2035 * task notifications can be used to send data to a task, or be used as light
2036 * weight and fast binary or counting semaphores.
2038 * xTaskNotifyGive() is a helper macro intended for use when task notifications
2039 * are used as light weight and faster binary or counting semaphore equivalents.
2040 * Actual FreeRTOS semaphores are given using the xSemaphoreGive() API function,
2041 * the equivalent action that instead uses a task notification is
2042 * xTaskNotifyGive().
2044 * When task notifications are being used as a binary or counting semaphore
2045 * equivalent then the task being notified should wait for the notification
2046 * using the ulTaskNotificationTake() API function rather than the
2047 * xTaskNotifyWait() API function.
2049 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
2051 * @param xTaskToNotify The handle of the task being notified. The handle to a
2052 * task can be returned from the xTaskCreate() API function used to create the
2053 * task, and the handle of the currently running task can be obtained by calling
2054 * xTaskGetCurrentTaskHandle().
2056 * @return xTaskNotifyGive() is a macro that calls xTaskNotify() with the
2057 * eAction parameter set to eIncrement - so pdPASS is always returned.
2059 * \defgroup xTaskNotifyGive xTaskNotifyGive
2060 * \ingroup TaskNotifications
2062 #define xTaskNotifyGive( xTaskToNotify ) xTaskGenericNotify( ( xTaskToNotify ), ( 0 ), eIncrement, NULL )
2066 * <PRE>void vTaskNotifyGiveFromISR( TaskHandle_t xTaskHandle, BaseType_t *pxHigherPriorityTaskWoken );
2068 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
2071 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
2072 * "notification value", which is a 32-bit unsigned integer (uint32_t).
2074 * A version of xTaskNotifyGive() that can be called from an interrupt service
2077 * Events can be sent to a task using an intermediary object. Examples of such
2078 * objects are queues, semaphores, mutexes and event groups. Task notifications
2079 * are a method of sending an event directly to a task without the need for such
2080 * an intermediary object.
2082 * A notification sent to a task can optionally perform an action, such as
2083 * update, overwrite or increment the task's notification value. In that way
2084 * task notifications can be used to send data to a task, or be used as light
2085 * weight and fast binary or counting semaphores.
2087 * vTaskNotifyGiveFromISR() is intended for use when task notifications are
2088 * used as light weight and faster binary or counting semaphore equivalents.
2089 * Actual FreeRTOS semaphores are given from an ISR using the
2090 * xSemaphoreGiveFromISR() API function, the equivalent action that instead uses
2091 * a task notification is vTaskNotifyGiveFromISR().
2093 * When task notifications are being used as a binary or counting semaphore
2094 * equivalent then the task being notified should wait for the notification
2095 * using the ulTaskNotificationTake() API function rather than the
2096 * xTaskNotifyWait() API function.
2098 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
2100 * @param xTaskToNotify The handle of the task being notified. The handle to a
2101 * task can be returned from the xTaskCreate() API function used to create the
2102 * task, and the handle of the currently running task can be obtained by calling
2103 * xTaskGetCurrentTaskHandle().
2105 * @param pxHigherPriorityTaskWoken vTaskNotifyGiveFromISR() will set
2106 * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
2107 * task to which the notification was sent to leave the Blocked state, and the
2108 * unblocked task has a priority higher than the currently running task. If
2109 * vTaskNotifyGiveFromISR() sets this value to pdTRUE then a context switch
2110 * should be requested before the interrupt is exited. How a context switch is
2111 * requested from an ISR is dependent on the port - see the documentation page
2112 * for the port in use.
2114 * \defgroup xTaskNotifyWait xTaskNotifyWait
2115 * \ingroup TaskNotifications
2117 void vTaskNotifyGiveFromISR( TaskHandle_t xTaskToNotify, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
2121 * <PRE>uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait );</pre>
2123 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
2124 * function to be available.
2126 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
2127 * "notification value", which is a 32-bit unsigned integer (uint32_t).
2129 * Events can be sent to a task using an intermediary object. Examples of such
2130 * objects are queues, semaphores, mutexes and event groups. Task notifications
2131 * are a method of sending an event directly to a task without the need for such
2132 * an intermediary object.
2134 * A notification sent to a task can optionally perform an action, such as
2135 * update, overwrite or increment the task's notification value. In that way
2136 * task notifications can be used to send data to a task, or be used as light
2137 * weight and fast binary or counting semaphores.
2139 * ulTaskNotifyTake() is intended for use when a task notification is used as a
2140 * faster and lighter weight binary or counting semaphore alternative. Actual
2141 * FreeRTOS semaphores are taken using the xSemaphoreTake() API function, the
2142 * equivalent action that instead uses a task notification is
2143 * ulTaskNotifyTake().
2145 * When a task is using its notification value as a binary or counting semaphore
2146 * other tasks should send notifications to it using the xTaskNotifyGive()
2147 * macro, or xTaskNotify() function with the eAction parameter set to
2150 * ulTaskNotifyTake() can either clear the task's notification value to
2151 * zero on exit, in which case the notification value acts like a binary
2152 * semaphore, or decrement the task's notification value on exit, in which case
2153 * the notification value acts like a counting semaphore.
2155 * A task can use ulTaskNotifyTake() to [optionally] block to wait for a
2156 * the task's notification value to be non-zero. The task does not consume any
2157 * CPU time while it is in the Blocked state.
2159 * Where as xTaskNotifyWait() will return when a notification is pending,
2160 * ulTaskNotifyTake() will return when the task's notification value is
2163 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
2165 * @param xClearCountOnExit if xClearCountOnExit is pdFALSE then the task's
2166 * notification value is decremented when the function exits. In this way the
2167 * notification value acts like a counting semaphore. If xClearCountOnExit is
2168 * not pdFALSE then the task's notification value is cleared to zero when the
2169 * function exits. In this way the notification value acts like a binary
2172 * @param xTicksToWait The maximum amount of time that the task should wait in
2173 * the Blocked state for the task's notification value to be greater than zero,
2174 * should the count not already be greater than zero when
2175 * ulTaskNotifyTake() was called. The task will not consume any processing
2176 * time while it is in the Blocked state. This is specified in kernel ticks,
2177 * the macro pdMS_TO_TICSK( value_in_ms ) can be used to convert a time
2178 * specified in milliseconds to a time specified in ticks.
2180 * @return The task's notification count before it is either cleared to zero or
2181 * decremented (see the xClearCountOnExit parameter).
2183 * \defgroup ulTaskNotifyTake ulTaskNotifyTake
2184 * \ingroup TaskNotifications
2186 uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2190 * <PRE>BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask );</pre>
2192 * If the notification state of the task referenced by the handle xTask is
2193 * eNotified, then set the task's notification state to eNotWaitingNotification.
2194 * The task's notification value is not altered. Set xTask to NULL to clear the
2195 * notification state of the calling task.
2197 * @return pdTRUE if the task's notification state was set to
2198 * eNotWaitingNotification, otherwise pdFALSE.
2199 * \defgroup xTaskNotifyStateClear xTaskNotifyStateClear
2200 * \ingroup TaskNotifications
2202 BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask );
2204 /*-----------------------------------------------------------
2205 * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
2206 *----------------------------------------------------------*/
2209 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
2210 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
2211 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2213 * Called from the real time kernel tick (either preemptive or cooperative),
2214 * this increments the tick count and checks if any tasks that are blocked
2215 * for a finite period required removing from a blocked list and placing on
2216 * a ready list. If a non-zero value is returned then a context switch is
2217 * required because either:
2218 * + A task was removed from a blocked list because its timeout had expired,
2220 * + Time slicing is in use and there is a task of equal priority to the
2221 * currently running task.
2223 BaseType_t xTaskIncrementTick( void ) PRIVILEGED_FUNCTION;
2226 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
2227 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2229 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
2231 * Removes the calling task from the ready list and places it both
2232 * on the list of tasks waiting for a particular event, and the
2233 * list of delayed tasks. The task will be removed from both lists
2234 * and replaced on the ready list should either the event occur (and
2235 * there be no higher priority tasks waiting on the same event) or
2236 * the delay period expires.
2238 * The 'unordered' version replaces the event list item value with the
2239 * xItemValue value, and inserts the list item at the end of the list.
2241 * The 'ordered' version uses the existing event list item value (which is the
2242 * owning tasks priority) to insert the list item into the event list is task
2245 * @param pxEventList The list containing tasks that are blocked waiting
2246 * for the event to occur.
2248 * @param xItemValue The item value to use for the event list item when the
2249 * event list is not ordered by task priority.
2251 * @param xTicksToWait The maximum amount of time that the task should wait
2252 * for the event to occur. This is specified in kernel ticks,the constant
2253 * portTICK_PERIOD_MS can be used to convert kernel ticks into a real time
2256 void vTaskPlaceOnEventList( List_t * const pxEventList, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2257 void vTaskPlaceOnUnorderedEventList( List_t * pxEventList, const TickType_t xItemValue, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2260 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
2261 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2263 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
2265 * This function performs nearly the same function as vTaskPlaceOnEventList().
2266 * The difference being that this function does not permit tasks to block
2267 * indefinitely, whereas vTaskPlaceOnEventList() does.
2270 void vTaskPlaceOnEventListRestricted( List_t * const pxEventList, TickType_t xTicksToWait, const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION;
2273 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
2274 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2276 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
2278 * Removes a task from both the specified event list and the list of blocked
2279 * tasks, and places it on a ready queue.
2281 * xTaskRemoveFromEventList()/vTaskRemoveFromUnorderedEventList() will be called
2282 * if either an event occurs to unblock a task, or the block timeout period
2285 * xTaskRemoveFromEventList() is used when the event list is in task priority
2286 * order. It removes the list item from the head of the event list as that will
2287 * have the highest priority owning task of all the tasks on the event list.
2288 * vTaskRemoveFromUnorderedEventList() is used when the event list is not
2289 * ordered and the event list items hold something other than the owning tasks
2290 * priority. In this case the event list item value is updated to the value
2291 * passed in the xItemValue parameter.
2293 * @return pdTRUE if the task being removed has a higher priority than the task
2294 * making the call, otherwise pdFALSE.
2296 BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList ) PRIVILEGED_FUNCTION;
2297 void vTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem, const TickType_t xItemValue ) PRIVILEGED_FUNCTION;
2300 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
2301 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
2302 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2304 * Sets the pointer to the current TCB to the TCB of the highest priority task
2305 * that is ready to run.
2307 void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION;
2310 * THESE FUNCTIONS MUST NOT BE USED FROM APPLICATION CODE. THEY ARE USED BY
2311 * THE EVENT BITS MODULE.
2313 TickType_t uxTaskResetEventItemValue( void ) PRIVILEGED_FUNCTION;
2316 * Return the handle of the calling task.
2318 TaskHandle_t xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION;
2321 * Capture the current time status for future reference.
2323 void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
2326 * Compare the time status now with that previously captured to see if the
2327 * timeout has expired.
2329 BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait ) PRIVILEGED_FUNCTION;
2332 * Shortcut used by the queue implementation to prevent unnecessary call to
2335 void vTaskMissedYield( void ) PRIVILEGED_FUNCTION;
2338 * Returns the scheduler state as taskSCHEDULER_RUNNING,
2339 * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
2341 BaseType_t xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION;
2344 * Raises the priority of the mutex holder to that of the calling task should
2345 * the mutex holder have a priority less than the calling task.
2347 BaseType_t xTaskPriorityInherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
2350 * Set the priority of a task back to its proper priority in the case that it
2351 * inherited a higher priority while it was holding a semaphore.
2353 BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
2356 * If a higher priority task attempting to obtain a mutex caused a lower
2357 * priority task to inherit the higher priority task's priority - but the higher
2358 * priority task then timed out without obtaining the mutex, then the lower
2359 * priority task will disinherit the priority again - but only down as far as
2360 * the highest priority task that is still waiting for the mutex (if there were
2361 * more than one task waiting for the mutex).
2363 void vTaskPriorityDisinheritAfterTimeout( TaskHandle_t const pxMutexHolder, UBaseType_t uxHighestPriorityWaitingTask ) PRIVILEGED_FUNCTION;
2366 * Get the uxTCBNumber assigned to the task referenced by the xTask parameter.
2368 UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
2371 * Set the uxTaskNumber of the task referenced by the xTask parameter to
2374 void vTaskSetTaskNumber( TaskHandle_t xTask, const UBaseType_t uxHandle ) PRIVILEGED_FUNCTION;
2377 * Only available when configUSE_TICKLESS_IDLE is set to 1.
2378 * If tickless mode is being used, or a low power mode is implemented, then
2379 * the tick interrupt will not execute during idle periods. When this is the
2380 * case, the tick count value maintained by the scheduler needs to be kept up
2381 * to date with the actual execution time by being skipped forward by a time
2382 * equal to the idle period.
2384 void vTaskStepTick( const TickType_t xTicksToJump ) PRIVILEGED_FUNCTION;
2387 * Only available when configUSE_TICKLESS_IDLE is set to 1.
2388 * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port
2389 * specific sleep function to determine if it is ok to proceed with the sleep,
2390 * and if it is ok to proceed, if it is ok to sleep indefinitely.
2392 * This function is necessary because portSUPPRESS_TICKS_AND_SLEEP() is only
2393 * called with the scheduler suspended, not from within a critical section. It
2394 * is therefore possible for an interrupt to request a context switch between
2395 * portSUPPRESS_TICKS_AND_SLEEP() and the low power mode actually being
2396 * entered. eTaskConfirmSleepModeStatus() should be called from a short
2397 * critical section between the timer being stopped and the sleep mode being
2398 * entered to ensure it is ok to proceed into the sleep mode.
2400 eSleepModeStatus eTaskConfirmSleepModeStatus( void ) PRIVILEGED_FUNCTION;
2403 * For internal use only. Increment the mutex held count when a mutex is
2404 * taken and return the handle of the task that has taken the mutex.
2406 TaskHandle_t pvTaskIncrementMutexHeldCount( void ) PRIVILEGED_FUNCTION;
2409 * For internal use only. Same as vTaskSetTimeOutState(), but without a critial
2412 void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
2418 #endif /* INC_TASK_H */