2 FreeRTOS V8.2.0 - Copyright (C) 2015 Real Time Engineers Ltd.
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
7 This file is part of the FreeRTOS distribution.
9 FreeRTOS is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License (version 2) as published by the
11 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
13 ***************************************************************************
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
15 >>! distribute a combined work that includes FreeRTOS without being !<<
16 >>! obliged to provide the source code for proprietary components !<<
17 >>! outside of the FreeRTOS kernel. !<<
18 ***************************************************************************
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
23 link: http://www.freertos.org/a00114.html
25 ***************************************************************************
27 * FreeRTOS provides completely free yet professionally developed, *
28 * robust, strictly quality controlled, supported, and cross *
29 * platform software that is more than just the market leader, it *
30 * is the industry's de facto standard. *
32 * Help yourself get started quickly while simultaneously helping *
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
34 * tutorial book, reference manual, or both: *
35 * http://www.FreeRTOS.org/Documentation *
37 ***************************************************************************
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
40 the FAQ page "My application does not run, what could be wrong?". Have you
41 defined configASSERT()?
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
44 embedded software for free we request you assist our global community by
45 participating in the support forum.
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
48 be as productive as possible as early as possible. Now you can receive
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50 Ltd, and the world's leading authority on the world's leading RTOS.
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
61 licenses offer ticketed support, indemnification and commercial middleware.
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64 engineered and independently SIL3 certified version for use in safety and
65 mission critical applications that require provable dependability.
74 #ifndef INC_FREERTOS_H
75 #error "include FreeRTOS.h must appear in source files before include task.h"
81 #include "portmacro.h"
87 /*-----------------------------------------------------------
88 * MACROS AND DEFINITIONS
89 *----------------------------------------------------------*/
91 #define tskKERNEL_VERSION_NUMBER "V8.2.0"
92 #define tskKERNEL_VERSION_MAJOR 8
93 #define tskKERNEL_VERSION_MINOR 2
94 #define tskKERNEL_VERSION_BUILD 0
96 #define tskNO_AFFINITY INT_MAX
101 * Type by which tasks are referenced. For example, a call to xTaskCreate
102 * returns (via a pointer parameter) an TaskHandle_t variable that can then
103 * be used as a parameter to vTaskDelete to delete the task.
107 typedef void * TaskHandle_t;
110 * Defines the prototype to which the application task hook function must
113 typedef BaseType_t (*TaskHookFunction_t)( void * );
115 /** Task states returned by eTaskGetState. */
118 eRunning = 0, /*!< A task is querying the state of itself, so must be running. */
119 eReady, /*!< The task being queried is in a read or pending ready list. */
120 eBlocked, /*!< The task being queried is in the Blocked state. */
121 eSuspended, /*!< The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */
122 eDeleted /*!< The task being queried has been deleted, but its TCB has not yet been freed. */
125 /** Actions that can be performed when vTaskNotify() is called. */
128 eNoAction = 0, /*!< Notify the task without updating its notify value. */
129 eSetBits, /*!< Set bits in the task's notification value. */
130 eIncrement, /*!< Increment the task's notification value. */
131 eSetValueWithOverwrite, /*!< Set the task's notification value to a specific value even if the previous value has not yet been read by the task. */
132 eSetValueWithoutOverwrite /*!< Set the task's notification value if the previous value has been read by the task. */
137 * Used internally only.
139 typedef struct xTIME_OUT
141 BaseType_t xOverflowCount;
142 TickType_t xTimeOnEntering;
146 * Defines the memory ranges allocated to the task when an MPU is used.
148 typedef struct xMEMORY_REGION
151 uint32_t ulLengthInBytes;
152 uint32_t ulParameters;
156 * Parameters required to create an MPU protected task.
158 typedef struct xTASK_PARAMETERS
160 TaskFunction_t pvTaskCode;
161 const char * const pcName; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
162 uint32_t usStackDepth;
164 UBaseType_t uxPriority;
165 StackType_t *puxStackBuffer;
166 MemoryRegion_t xRegions[ portNUM_CONFIGURABLE_REGIONS ];
171 * Used with the uxTaskGetSystemState() function to return the state of each task in the system.
173 typedef struct xTASK_STATUS
175 TaskHandle_t xHandle; /*!< The handle of the task to which the rest of the information in the structure relates. */
176 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. */
177 UBaseType_t xTaskNumber; /*!< A number unique to the task. */
178 eTaskState eCurrentState; /*!< The state in which the task existed when the structure was populated. */
179 UBaseType_t uxCurrentPriority; /*!< The priority at which the task was running (may be inherited) when the structure was populated. */
180 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. */
181 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. */
182 StackType_t *pxStackBase; /*!< Points to the lowest address of the task's stack area. */
183 uint32_t usStackHighWaterMark; /*!< The minimum amount of stack space that has remained for the task since the task was created. The closer this value is to zero the closer the task has come to overflowing its stack. */
184 #if configTASKLIST_INCLUDE_COREID
185 BaseType_t xCoreID; /*!< Core this task is pinned to. This field is present if CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID is set. */
190 * Used with the uxTaskGetSnapshotAll() function to save memory snapshot of each task in the system.
191 * We need this struct because TCB_t is defined (hidden) in tasks.c.
193 typedef struct xTASK_SNAPSHOT
195 void *pxTCB; /*!< Address of task control block. */
196 StackType_t *pxTopOfStack; /*!< Points to the location of the last item placed on the tasks stack. */
197 StackType_t *pxEndOfStack; /*!< Points to the end of the stack. pxTopOfStack < pxEndOfStack, stack grows hi2lo
198 pxTopOfStack > pxEndOfStack, stack grows lo2hi*/
202 * Possible return values for eTaskConfirmSleepModeStatus().
206 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. */
207 eStandardSleep, /*!< Enter a sleep mode that will not last any longer than the expected idle time. */
208 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. */
213 * Defines the priority used by the idle task. This must not be modified.
217 #define tskIDLE_PRIORITY ( ( UBaseType_t ) 0U )
222 * Macro for forcing a context switch.
224 * \ingroup SchedulerControl
226 #define taskYIELD() portYIELD()
231 * Macro to mark the start of a critical code region. Preemptive context
232 * switches cannot occur when in a critical region.
234 * @note This may alter the stack (depending on the portable implementation)
235 * so must be used with care!
237 * \ingroup SchedulerControl
239 #ifdef _ESP_FREERTOS_INTERNAL
240 #define taskENTER_CRITICAL(mux) portENTER_CRITICAL(mux)
242 #define taskENTER_CRITICAL(mux) _Pragma("GCC warning \"'taskENTER_CRITICAL(mux)' is deprecated in ESP-IDF, consider using 'portENTER_CRITICAL(mux)'\"") portENTER_CRITICAL(mux)
244 #define taskENTER_CRITICAL_ISR(mux) portENTER_CRITICAL_ISR(mux)
249 * Macro to mark the end of a critical code region. Preemptive context
250 * switches cannot occur when in a critical region.
252 * @note This may alter the stack (depending on the portable implementation)
253 * so must be used with care!
255 * \ingroup SchedulerControl
257 #ifdef _ESP_FREERTOS_INTERNAL
258 #define taskEXIT_CRITICAL(mux) portEXIT_CRITICAL(mux)
260 #define taskEXIT_CRITICAL(mux) _Pragma("GCC warning \"'taskEXIT_CRITICAL(mux)' is deprecated in ESP-IDF, consider using 'portEXIT_CRITICAL(mux)'\"") portEXIT_CRITICAL(mux)
262 #define taskEXIT_CRITICAL_ISR(mux) portEXIT_CRITICAL_ISR(mux)
267 * Macro to disable all maskable interrupts.
269 * \ingroup SchedulerControl
271 #define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS()
276 * Macro to enable microcontroller interrupts.
278 * \ingroup SchedulerControl
280 #define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS()
282 /* Definitions returned by xTaskGetSchedulerState(). taskSCHEDULER_SUSPENDED is
283 0 to generate more optimal code when configASSERT() is defined as the constant
284 is used in assert() statements. */
285 #define taskSCHEDULER_SUSPENDED ( ( BaseType_t ) 0 )
286 #define taskSCHEDULER_NOT_STARTED ( ( BaseType_t ) 1 )
287 #define taskSCHEDULER_RUNNING ( ( BaseType_t ) 2 )
290 /*-----------------------------------------------------------
292 *----------------------------------------------------------*/
295 * Create a new task with a specified affinity.
297 * This function is similar to xTaskCreate, but allows setting task affinity
300 * @param pvTaskCode Pointer to the task entry function. Tasks
301 * must be implemented to never return (i.e. continuous loop).
303 * @param pcName A descriptive name for the task. This is mainly used to
304 * facilitate debugging. Max length defined by configMAX_TASK_NAME_LEN - default
307 * @param usStackDepth The size of the task stack specified as the number of
308 * variables the stack can hold - not the number of bytes. For example, if
309 * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
310 * will be allocated for stack storage.
312 * @param pvParameters Pointer that will be used as the parameter for the task
315 * @param uxPriority The priority at which the task should run. Systems that
316 * include MPU support can optionally create tasks in a privileged (system)
317 * mode by setting bit portPRIVILEGE_BIT of the priority parameter. For
318 * example, to create a privileged task at priority 2 the uxPriority parameter
319 * should be set to ( 2 | portPRIVILEGE_BIT ).
321 * @param pvCreatedTask Used to pass back a handle by which the created task
324 * @param xCoreID If the value is tskNO_AFFINITY, the created task is not
325 * pinned to any CPU, and the scheduler can run it on any core available.
326 * Other values indicate the index number of the CPU which the task should
327 * be pinned to. Specifying values larger than (portNUM_PROCESSORS - 1) will
328 * cause the function to fail.
330 * @return pdPASS if the task was successfully created and added to a ready
331 * list, otherwise an error code defined in the file projdefs.h
335 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
336 BaseType_t xTaskCreatePinnedToCore( TaskFunction_t pvTaskCode,
337 const char * const pcName,
338 const uint32_t usStackDepth,
339 void * const pvParameters,
340 UBaseType_t uxPriority,
341 TaskHandle_t * const pvCreatedTask,
342 const BaseType_t xCoreID);
347 * Create a new task and add it to the list of tasks that are ready to run.
349 * Internally, within the FreeRTOS implementation, tasks use two blocks of
350 * memory. The first block is used to hold the task's data structures. The
351 * second block is used by the task as its stack. If a task is created using
352 * xTaskCreate() then both blocks of memory are automatically dynamically
353 * allocated inside the xTaskCreate() function. (see
354 * http://www.freertos.org/a00111.html). If a task is created using
355 * xTaskCreateStatic() then the application writer must provide the required
356 * memory. xTaskCreateStatic() therefore allows a task to be created without
357 * using any dynamic memory allocation.
359 * See xTaskCreateStatic() for a version that does not use any dynamic memory
362 * xTaskCreate() can only be used to create a task that has unrestricted
363 * access to the entire microcontroller memory map. Systems that include MPU
364 * support can alternatively create an MPU constrained task using
365 * xTaskCreateRestricted().
367 * @param pvTaskCode Pointer to the task entry function. Tasks
368 * must be implemented to never return (i.e. continuous loop).
370 * @param pcName A descriptive name for the task. This is mainly used to
371 * facilitate debugging. Max length defined by configMAX_TASK_NAME_LEN - default
374 * @param usStackDepth The size of the task stack specified as the number of
375 * variables the stack can hold - not the number of bytes. For example, if
376 * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
377 * will be allocated for stack storage.
379 * @param pvParameters Pointer that will be used as the parameter for the task
382 * @param uxPriority The priority at which the task should run. Systems that
383 * include MPU support can optionally create tasks in a privileged (system)
384 * mode by setting bit portPRIVILEGE_BIT of the priority parameter. For
385 * example, to create a privileged task at priority 2 the uxPriority parameter
386 * should be set to ( 2 | portPRIVILEGE_BIT ).
388 * @param pvCreatedTask Used to pass back a handle by which the created task
391 * @return pdPASS if the task was successfully created and added to a ready
392 * list, otherwise an error code defined in the file projdefs.h
394 * @note If program uses thread local variables (ones specified with "__thread" keyword)
395 * then storage for them will be allocated on the task's stack.
399 * // Task to be created.
400 * void vTaskCode( void * pvParameters )
404 * // Task code goes here.
408 * // Function that creates a task.
409 * void vOtherFunction( void )
411 * static uint8_t ucParameterToPass;
412 * TaskHandle_t xHandle = NULL;
414 * // Create the task, storing the handle. Note that the passed parameter ucParameterToPass
415 * // must exist for the lifetime of the task, so in this case is declared static. If it was just an
416 * // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
417 * // the new task attempts to access it.
418 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
419 * configASSERT( xHandle );
421 * // Use the handle to delete the task.
422 * if( xHandle != NULL )
424 * vTaskDelete( xHandle );
431 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
433 static inline IRAM_ATTR BaseType_t xTaskCreate(
434 TaskFunction_t pvTaskCode,
435 const char * const pcName,
436 const uint32_t usStackDepth,
437 void * const pvParameters,
438 UBaseType_t uxPriority,
439 TaskHandle_t * const pvCreatedTask)
441 return xTaskCreatePinnedToCore( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pvCreatedTask, tskNO_AFFINITY );
450 * Create a new task with a specified affinity.
452 * This function is similar to xTaskCreateStatic, but allows specifying
453 * task affinity in an SMP system.
455 * @param pvTaskCode Pointer to the task entry function. Tasks
456 * must be implemented to never return (i.e. continuous loop).
458 * @param pcName A descriptive name for the task. This is mainly used to
459 * facilitate debugging. The maximum length of the string is defined by
460 * configMAX_TASK_NAME_LEN in FreeRTOSConfig.h.
462 * @param ulStackDepth The size of the task stack specified as the number of
463 * variables the stack can hold - not the number of bytes. For example, if
464 * the stack is 32-bits wide and ulStackDepth is defined as 100 then 400 bytes
465 * will be allocated for stack storage.
467 * @param pvParameters Pointer that will be used as the parameter for the task
470 * @param uxPriority The priority at which the task will run.
472 * @param pxStackBuffer Must point to a StackType_t array that has at least
473 * ulStackDepth indexes - the array will then be used as the task's stack,
474 * removing the need for the stack to be allocated dynamically.
476 * @param pxTaskBuffer Must point to a variable of type StaticTask_t, which will
477 * then be used to hold the task's data structures, removing the need for the
478 * memory to be allocated dynamically.
480 * @param xCoreID If the value is tskNO_AFFINITY, the created task is not
481 * pinned to any CPU, and the scheduler can run it on any core available.
482 * Other values indicate the index number of the CPU which the task should
483 * be pinned to. Specifying values larger than (portNUM_PROCESSORS - 1) will
484 * cause the function to fail.
486 * @return If neither pxStackBuffer or pxTaskBuffer are NULL, then the task will
487 * be created and pdPASS is returned. If either pxStackBuffer or pxTaskBuffer
488 * are NULL then the task will not be created and
489 * errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY is returned.
493 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
494 TaskHandle_t xTaskCreateStaticPinnedToCore( TaskFunction_t pvTaskCode,
495 const char * const pcName,
496 const uint32_t ulStackDepth,
497 void * const pvParameters,
498 UBaseType_t uxPriority,
499 StackType_t * const pxStackBuffer,
500 StaticTask_t * const pxTaskBuffer,
501 const BaseType_t xCoreID );
502 #endif /* configSUPPORT_STATIC_ALLOCATION */
505 * Create a new task and add it to the list of tasks that are ready to run.
507 * Internally, within the FreeRTOS implementation, tasks use two blocks of
508 * memory. The first block is used to hold the task's data structures. The
509 * second block is used by the task as its stack. If a task is created using
510 * xTaskCreate() then both blocks of memory are automatically dynamically
511 * allocated inside the xTaskCreate() function. (see
512 * http://www.freertos.org/a00111.html). If a task is created using
513 * xTaskCreateStatic() then the application writer must provide the required
514 * memory. xTaskCreateStatic() therefore allows a task to be created without
515 * using any dynamic memory allocation.
517 * @param pvTaskCode Pointer to the task entry function. Tasks
518 * must be implemented to never return (i.e. continuous loop).
520 * @param pcName A descriptive name for the task. This is mainly used to
521 * facilitate debugging. The maximum length of the string is defined by
522 * configMAX_TASK_NAME_LEN in FreeRTOSConfig.h.
524 * @param ulStackDepth The size of the task stack specified as the number of
525 * variables the stack can hold - not the number of bytes. For example, if
526 * the stack is 32-bits wide and ulStackDepth is defined as 100 then 400 bytes
527 * will be allocated for stack storage.
529 * @param pvParameters Pointer that will be used as the parameter for the task
532 * @param uxPriority The priority at which the task will run.
534 * @param pxStackBuffer Must point to a StackType_t array that has at least
535 * ulStackDepth indexes - the array will then be used as the task's stack,
536 * removing the need for the stack to be allocated dynamically.
538 * @param pxTaskBuffer Must point to a variable of type StaticTask_t, which will
539 * then be used to hold the task's data structures, removing the need for the
540 * memory to be allocated dynamically.
542 * @return If neither pxStackBuffer or pxTaskBuffer are NULL, then the task will
543 * be created and pdPASS is returned. If either pxStackBuffer or pxTaskBuffer
544 * are NULL then the task will not be created and
545 * errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY is returned.
547 * @note If program uses thread local variables (ones specified with "__thread" keyword)
548 * then storage for them will be allocated on the task's stack.
553 * // Dimensions the buffer that the task being created will use as its stack.
554 * // NOTE: This is the number of words the stack will hold, not the number of
555 * // bytes. For example, if each stack item is 32-bits, and this is set to 100,
556 * // then 400 bytes (100 * 32-bits) will be allocated.
557 * #define STACK_SIZE 200
559 * // Structure that will hold the TCB of the task being created.
560 * StaticTask_t xTaskBuffer;
562 * // Buffer that the task being created will use as its stack. Note this is
563 * // an array of StackType_t variables. The size of StackType_t is dependent on
565 * StackType_t xStack[ STACK_SIZE ];
567 * // Function that implements the task being created.
568 * void vTaskCode( void * pvParameters )
570 * // The parameter value is expected to be 1 as 1 is passed in the
571 * // pvParameters value in the call to xTaskCreateStatic().
572 * configASSERT( ( uint32_t ) pvParameters == 1UL );
576 * // Task code goes here.
580 * // Function that creates a task.
581 * void vOtherFunction( void )
583 * TaskHandle_t xHandle = NULL;
585 * // Create the task without using any dynamic memory allocation.
586 * xHandle = xTaskCreateStatic(
587 * vTaskCode, // Function that implements the task.
588 * "NAME", // Text name for the task.
589 * STACK_SIZE, // Stack size in words, not bytes.
590 * ( void * ) 1, // Parameter passed into the task.
591 * tskIDLE_PRIORITY,// Priority at which the task is created.
592 * xStack, // Array to use as the task's stack.
593 * &xTaskBuffer ); // Variable to hold the task's data structure.
595 * // puxStackBuffer and pxTaskBuffer were not NULL, so the task will have
596 * // been created, and xHandle will be the task's handle. Use the handle
597 * // to suspend the task.
598 * vTaskSuspend( xHandle );
604 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
605 static inline IRAM_ATTR TaskHandle_t xTaskCreateStatic(
606 TaskFunction_t pvTaskCode,
607 const char * const pcName,
608 const uint32_t ulStackDepth,
609 void * const pvParameters,
610 UBaseType_t uxPriority,
611 StackType_t * const pxStackBuffer,
612 StaticTask_t * const pxTaskBuffer)
614 return xTaskCreateStaticPinnedToCore( pvTaskCode, pcName, ulStackDepth, pvParameters, uxPriority, pxStackBuffer, pxTaskBuffer, tskNO_AFFINITY );
616 #endif /* configSUPPORT_STATIC_ALLOCATION */
620 * xTaskCreateRestricted() should only be used in systems that include an MPU
623 * Create a new task and add it to the list of tasks that are ready to run.
624 * The function parameters define the memory regions and associated access
625 * permissions allocated to the task.
627 * @param pxTaskDefinition Pointer to a structure that contains a member
628 * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API
629 * documentation) plus an optional stack buffer and the memory region
632 * @param pxCreatedTask Used to pass back a handle by which the created task
635 * @return pdPASS if the task was successfully created and added to a ready
636 * list, otherwise an error code defined in the file projdefs.h
640 * // Create an TaskParameters_t structure that defines the task to be created.
641 * static const TaskParameters_t xCheckTaskParameters =
643 * vATask, // pvTaskCode - the function that implements the task.
644 * "ATask", // pcName - just a text name for the task to assist debugging.
645 * 100, // usStackDepth - the stack size DEFINED IN WORDS.
646 * NULL, // pvParameters - passed into the task function as the function parameters.
647 * ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
648 * cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
650 * // xRegions - Allocate up to three separate memory regions for access by
651 * // the task, with appropriate access permissions. Different processors have
652 * // different memory alignment requirements - refer to the FreeRTOS documentation
653 * // for full information.
655 * // Base address Length Parameters
656 * { cReadWriteArray, 32, portMPU_REGION_READ_WRITE },
657 * { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY },
658 * { cPrivilegedOnlyAccessArray, 128, portMPU_REGION_PRIVILEGED_READ_WRITE }
664 * TaskHandle_t xHandle;
666 * // Create a task from the const structure defined above. The task handle
667 * // is requested (the second parameter is not NULL) but in this case just for
668 * // demonstration purposes as its not actually used.
669 * xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
671 * // Start the scheduler.
672 * vTaskStartScheduler();
674 * // Will only get here if there was insufficient memory to create the idle
675 * // and/or timer task.
681 #if( portUSING_MPU_WRAPPERS == 1 )
682 BaseType_t xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ) PRIVILEGED_FUNCTION;
687 * Memory regions are assigned to a restricted task when the task is created by
688 * a call to xTaskCreateRestricted(). These regions can be redefined using
689 * vTaskAllocateMPURegions().
691 * @param xTask The handle of the task being updated.
693 * @param xRegions A pointer to an MemoryRegion_t structure that contains the
694 * new memory region definitions.
699 * // Define an array of MemoryRegion_t structures that configures an MPU region
700 * // allowing read/write access for 1024 bytes starting at the beginning of the
701 * // ucOneKByte array. The other two of the maximum 3 definable regions are
702 * // unused so set to zero.
703 * static const MemoryRegion_t xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] =
705 * // Base address Length Parameters
706 * { ucOneKByte, 1024, portMPU_REGION_READ_WRITE },
711 * void vATask( void *pvParameters )
713 * // This task was created such that it has access to certain regions of
714 * // memory as defined by the MPU configuration. At some point it is
715 * // desired that these MPU regions are replaced with that defined in the
716 * // xAltRegions const struct above. Use a call to vTaskAllocateMPURegions()
717 * // for this purpose. NULL is used as the task handle to indicate that this
718 * // function should modify the MPU regions of the calling task.
719 * vTaskAllocateMPURegions( NULL, xAltRegions );
721 * // Now the task can continue its function, but from this point on can only
722 * // access its stack and the ucOneKByte array (unless any other statically
723 * // defined or shared regions have been declared elsewhere).
728 void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions ) PRIVILEGED_FUNCTION;
733 * Remove a task from the RTOS real time kernel's management.
735 * The task being deleted will be removed from all ready, blocked, suspended
738 * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.
739 * See the configuration section for more information.
741 * @note The idle task is responsible for freeing the kernel allocated
742 * memory from tasks that have been deleted. It is therefore important that
743 * the idle task is not starved of microcontroller processing time if your
744 * application makes any calls to vTaskDelete (). Memory allocated by the
745 * task code is not automatically freed, and should be freed before the task
748 * See the demo application file death.c for sample code that utilises
751 * @param xTaskToDelete The handle of the task to be deleted. Passing NULL will
752 * cause the calling task to be deleted.
756 * void vOtherFunction( void )
758 * TaskHandle_t xHandle;
760 * // Create the task, storing the handle.
761 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
763 * // Use the handle to delete the task.
764 * vTaskDelete( xHandle );
769 void vTaskDelete( TaskHandle_t xTaskToDelete ) PRIVILEGED_FUNCTION;
771 /*-----------------------------------------------------------
773 *----------------------------------------------------------*/
776 * Delay a task for a given number of ticks.
778 * The actual time that the task remains blocked depends on the tick rate.
779 * The constant portTICK_PERIOD_MS can be used to calculate real time from
780 * the tick rate - with the resolution of one tick period.
782 * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
783 * See the configuration section for more information.
785 * vTaskDelay() specifies a time at which the task wishes to unblock relative to
786 * the time at which vTaskDelay() is called. For example, specifying a block
787 * period of 100 ticks will cause the task to unblock 100 ticks after
788 * vTaskDelay() is called. vTaskDelay() does not therefore provide a good method
789 * of controlling the frequency of a periodic task as the path taken through the
790 * code, as well as other task and interrupt activity, will effect the frequency
791 * at which vTaskDelay() gets called and therefore the time at which the task
792 * next executes. See vTaskDelayUntil() for an alternative API function designed
793 * to facilitate fixed frequency execution. It does this by specifying an
794 * absolute time (rather than a relative time) at which the calling task should
797 * @param xTicksToDelay The amount of time, in tick periods, that
798 * the calling task should block.
802 * void vTaskFunction( void * pvParameters )
804 * // Block for 500ms.
805 * const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
809 * // Simply toggle the LED every 500ms, blocking between each toggle.
811 * vTaskDelay( xDelay );
817 void vTaskDelay( const TickType_t xTicksToDelay ) PRIVILEGED_FUNCTION;
820 * Delay a task until a specified time.
822 * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available.
823 * See the configuration section for more information.
825 * This function can be used by periodic tasks to ensure a constant execution frequency.
827 * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will
828 * cause a task to block for the specified number of ticks from the time vTaskDelay () is
829 * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed
830 * execution frequency as the time between a task starting to execute and that task
831 * calling vTaskDelay () may not be fixed [the task may take a different path though the
832 * code between calls, or may get interrupted or preempted a different number of times
833 * each time it executes].
835 * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
836 * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
839 * The constant portTICK_PERIOD_MS can be used to calculate real time from the tick
840 * rate - with the resolution of one tick period.
842 * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
843 * task was last unblocked. The variable must be initialised with the current time
844 * prior to its first use (see the example below). Following this the variable is
845 * automatically updated within vTaskDelayUntil ().
847 * @param xTimeIncrement The cycle time period. The task will be unblocked at
848 * time *pxPreviousWakeTime + xTimeIncrement. Calling vTaskDelayUntil with the
849 * same xTimeIncrement parameter value will cause the task to execute with
850 * a fixed interface period.
854 * // Perform an action every 10 ticks.
855 * void vTaskFunction( void * pvParameters )
857 * TickType_t xLastWakeTime;
858 * const TickType_t xFrequency = 10;
860 * // Initialise the xLastWakeTime variable with the current time.
861 * xLastWakeTime = xTaskGetTickCount ();
864 * // Wait for the next cycle.
865 * vTaskDelayUntil( &xLastWakeTime, xFrequency );
867 * // Perform action here.
873 void vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, const TickType_t xTimeIncrement ) PRIVILEGED_FUNCTION;
876 * Obtain the priority of any task.
878 * INCLUDE_uxTaskPriorityGet must be defined as 1 for this function to be available.
879 * See the configuration section for more information.
881 * @param xTask Handle of the task to be queried. Passing a NULL
882 * handle results in the priority of the calling task being returned.
884 * @return The priority of xTask.
888 * void vAFunction( void )
890 * TaskHandle_t xHandle;
892 * // Create a task, storing the handle.
893 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
897 * // Use the handle to obtain the priority of the created task.
898 * // It was created with tskIDLE_PRIORITY, but may have changed
900 * if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
902 * // The task has changed it's priority.
907 * // Is our priority higher than the created task?
908 * if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
910 * // Our priority (obtained using NULL handle) is higher.
916 UBaseType_t uxTaskPriorityGet( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
919 * A version of uxTaskPriorityGet() that can be used from an ISR.
921 * @param xTask Handle of the task to be queried. Passing a NULL
922 * handle results in the priority of the calling task being returned.
924 * @return The priority of xTask.
927 UBaseType_t uxTaskPriorityGetFromISR( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
930 * Obtain the state of any task.
932 * States are encoded by the eTaskState enumerated type.
934 * INCLUDE_eTaskGetState must be defined as 1 for this function to be available.
935 * See the configuration section for more information.
937 * @param xTask Handle of the task to be queried.
939 * @return The state of xTask at the time the function was called. Note the
940 * state of the task might change between the function being called, and the
941 * functions return value being tested by the calling task.
943 eTaskState eTaskGetState( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
946 * Set the priority of any task.
948 * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
949 * See the configuration section for more information.
951 * A context switch will occur before the function returns if the priority
952 * being set is higher than the currently executing task.
954 * @param xTask Handle to the task for which the priority is being set.
955 * Passing a NULL handle results in the priority of the calling task being set.
957 * @param uxNewPriority The priority to which the task will be set.
961 * void vAFunction( void )
963 * TaskHandle_t xHandle;
965 * // Create a task, storing the handle.
966 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
970 * // Use the handle to raise the priority of the created task.
971 * vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
975 * // Use a NULL handle to raise our priority to the same value.
976 * vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
981 void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority ) PRIVILEGED_FUNCTION;
986 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
987 * See the configuration section for more information.
989 * When suspended, a task will never get any microcontroller processing time,
990 * no matter what its priority.
992 * Calls to vTaskSuspend are not accumulative -
993 * i.e. calling vTaskSuspend () twice on the same task still only requires one
994 * call to vTaskResume () to ready the suspended task.
996 * @param xTaskToSuspend Handle to the task being suspended. Passing a NULL
997 * handle will cause the calling task to be suspended.
1001 * void vAFunction( void )
1003 * TaskHandle_t xHandle;
1005 * // Create a task, storing the handle.
1006 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
1010 * // Use the handle to suspend the created task.
1011 * vTaskSuspend( xHandle );
1015 * // The created task will not run during this period, unless
1016 * // another task calls vTaskResume( xHandle ).
1021 * // Suspend ourselves.
1022 * vTaskSuspend( NULL );
1024 * // We cannot get here unless another task calls vTaskResume
1025 * // with our handle as the parameter.
1030 void vTaskSuspend( TaskHandle_t xTaskToSuspend ) PRIVILEGED_FUNCTION;
1033 * Resumes a suspended task.
1035 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
1036 * See the configuration section for more information.
1038 * A task that has been suspended by one or more calls to vTaskSuspend ()
1039 * will be made available for running again by a single call to
1042 * @param xTaskToResume Handle to the task being readied.
1046 * void vAFunction( void )
1048 * TaskHandle_t xHandle;
1050 * // Create a task, storing the handle.
1051 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
1055 * // Use the handle to suspend the created task.
1056 * vTaskSuspend( xHandle );
1060 * // The created task will not run during this period, unless
1061 * // another task calls vTaskResume( xHandle ).
1066 * // Resume the suspended task ourselves.
1067 * vTaskResume( xHandle );
1069 * // The created task will once again get microcontroller processing
1070 * // time in accordance with its priority within the system.
1075 void vTaskResume( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
1078 * An implementation of vTaskResume() that can be called from within an ISR.
1080 * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
1081 * available. See the configuration section for more information.
1083 * A task that has been suspended by one or more calls to vTaskSuspend ()
1084 * will be made available for running again by a single call to
1085 * xTaskResumeFromISR ().
1087 * xTaskResumeFromISR() should not be used to synchronise a task with an
1088 * interrupt if there is a chance that the interrupt could arrive prior to the
1089 * task being suspended - as this can lead to interrupts being missed. Use of a
1090 * semaphore as a synchronisation mechanism would avoid this eventuality.
1092 * @param xTaskToResume Handle to the task being readied.
1094 * @return pdTRUE if resuming the task should result in a context switch,
1095 * otherwise pdFALSE. This is used by the ISR to determine if a context switch
1096 * may be required following the ISR.
1100 BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
1102 /*-----------------------------------------------------------
1104 *----------------------------------------------------------*/
1107 * Starts the real time kernel tick processing.
1109 * After calling the kernel has control over which tasks are executed and when.
1111 * See the demo application file main.c for an example of creating
1112 * tasks and starting the kernel.
1116 * void vAFunction( void )
1118 * // Create at least one task before starting the kernel.
1119 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
1121 * // Start the real time kernel with preemption.
1122 * vTaskStartScheduler ();
1124 * // Will not get here unless a task calls vTaskEndScheduler ()
1128 * \ingroup SchedulerControl
1130 void vTaskStartScheduler( void ) PRIVILEGED_FUNCTION;
1133 * Stops the real time kernel tick.
1135 * @note At the time of writing only the x86 real mode port, which runs on a PC
1136 * in place of DOS, implements this function.
1138 * All created tasks will be automatically deleted and multitasking
1139 * (either preemptive or cooperative) will stop.
1140 * Execution then resumes from the point where vTaskStartScheduler ()
1141 * was called, as if vTaskStartScheduler () had just returned.
1143 * See the demo application file main. c in the demo/PC directory for an
1144 * example that uses vTaskEndScheduler ().
1146 * vTaskEndScheduler () requires an exit function to be defined within the
1147 * portable layer (see vPortEndScheduler () in port. c for the PC port). This
1148 * performs hardware specific operations such as stopping the kernel tick.
1150 * vTaskEndScheduler () will cause all of the resources allocated by the
1151 * kernel to be freed - but will not free resources allocated by application
1156 * void vTaskCode( void * pvParameters )
1160 * // Task code goes here.
1162 * // At some point we want to end the real time kernel processing
1164 * vTaskEndScheduler ();
1168 * void vAFunction( void )
1170 * // Create at least one task before starting the kernel.
1171 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
1173 * // Start the real time kernel with preemption.
1174 * vTaskStartScheduler ();
1176 * // Will only get here when the vTaskCode () task has called
1177 * // vTaskEndScheduler (). When we get here we are back to single task
1181 * \ingroup SchedulerControl
1183 void vTaskEndScheduler( void ) PRIVILEGED_FUNCTION;
1188 * Suspends the scheduler without disabling interrupts.
1190 * Context switches will not occur while the scheduler is suspended.
1192 * After calling vTaskSuspendAll () the calling task will continue to execute
1193 * without risk of being swapped out until a call to xTaskResumeAll () has been
1196 * API functions that have the potential to cause a context switch (for example,
1197 * vTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler
1202 * void vTask1( void * pvParameters )
1206 * // Task code goes here.
1210 * // At some point the task wants to perform a long operation during
1211 * // which it does not want to get swapped out. It cannot use
1212 * // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
1213 * // operation may cause interrupts to be missed - including the
1216 * // Prevent the real time kernel swapping out the task.
1217 * vTaskSuspendAll ();
1219 * // Perform the operation here. There is no need to use critical
1220 * // sections as we have all the microcontroller processing time.
1221 * // During this time interrupts will still operate and the kernel
1222 * // tick count will be maintained.
1226 * // The operation is complete. Restart the kernel.
1227 * xTaskResumeAll ();
1231 * \ingroup SchedulerControl
1233 void vTaskSuspendAll( void ) PRIVILEGED_FUNCTION;
1236 * Resumes scheduler activity after it was suspended by a call to
1237 * vTaskSuspendAll().
1239 * xTaskResumeAll() only resumes the scheduler. It does not unsuspend tasks
1240 * that were previously suspended by a call to vTaskSuspend().
1242 * @return If resuming the scheduler caused a context switch then pdTRUE is
1243 * returned, otherwise pdFALSE is returned.
1247 * void vTask1( void * pvParameters )
1251 * // Task code goes here.
1255 * // At some point the task wants to perform a long operation during
1256 * // which it does not want to get swapped out. It cannot use
1257 * // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
1258 * // operation may cause interrupts to be missed - including the
1261 * // Prevent the real time kernel swapping out the task.
1262 * vTaskSuspendAll ();
1264 * // Perform the operation here. There is no need to use critical
1265 * // sections as we have all the microcontroller processing time.
1266 * // During this time interrupts will still operate and the real
1267 * // time kernel tick count will be maintained.
1271 * // The operation is complete. Restart the kernel. We want to force
1272 * // a context switch - but there is no point if resuming the scheduler
1273 * // caused a context switch already.
1274 * if( !xTaskResumeAll () )
1281 * \ingroup SchedulerControl
1283 BaseType_t xTaskResumeAll( void ) PRIVILEGED_FUNCTION;
1285 /*-----------------------------------------------------------
1287 *----------------------------------------------------------*/
1292 * @return The count of ticks since vTaskStartScheduler was called.
1294 * \ingroup TaskUtils
1296 TickType_t xTaskGetTickCount( void ) PRIVILEGED_FUNCTION;
1299 * Get tick count from ISR
1301 * @return The count of ticks since vTaskStartScheduler was called.
1303 * This is a version of xTaskGetTickCount() that is safe to be called from an
1304 * ISR - provided that TickType_t is the natural word size of the
1305 * microcontroller being used or interrupt nesting is either not supported or
1308 * \ingroup TaskUtils
1310 TickType_t xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION;
1313 * Get current number of tasks
1315 * @return The number of tasks that the real time kernel is currently managing.
1316 * This includes all ready, blocked and suspended tasks. A task that
1317 * has been deleted but not yet freed by the idle task will also be
1318 * included in the count.
1320 * \ingroup TaskUtils
1322 UBaseType_t uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION;
1327 * @return The text (human readable) name of the task referenced by the handle
1328 * xTaskToQuery. A task can query its own name by either passing in its own
1329 * handle, or by setting xTaskToQuery to NULL. INCLUDE_pcTaskGetTaskName must be
1330 * set to 1 in FreeRTOSConfig.h for pcTaskGetTaskName() to be available.
1332 * \ingroup TaskUtils
1334 char *pcTaskGetTaskName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1337 * Returns the high water mark of the stack associated with xTask.
1339 * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
1340 * this function to be available.
1342 * High water mark is the minimum free stack space there has been (in words,
1343 * so on a 32 bit machine a value of 1 means 4 bytes) since the task started.
1344 * The smaller the returned number the closer the task has come to overflowing its stack.
1346 * @param xTask Handle of the task associated with the stack to be checked.
1347 * Set xTask to NULL to check the stack of the calling task.
1349 * @return The smallest amount of free stack space there has been (in words, so
1350 * actual spaces on the stack rather than bytes) since the task referenced by
1351 * xTask was created.
1353 UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1356 * Returns the start of the stack associated with xTask.
1358 * INCLUDE_pxTaskGetStackStart must be set to 1 in FreeRTOSConfig.h for
1359 * this function to be available.
1361 * Returns the highest stack memory address on architectures where the stack grows down
1362 * from high memory, and the lowest memory address on architectures where the
1363 * stack grows up from low memory.
1365 * @param xTask Handle of the task associated with the stack returned.
1366 * Set xTask to NULL to return the stack of the calling task.
1368 * @return A pointer to the start of the stack.
1370 uint8_t* pxTaskGetStackStart( TaskHandle_t xTask) PRIVILEGED_FUNCTION;
1372 /* When using trace macros it is sometimes necessary to include task.h before
1373 FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined,
1374 so the following two prototypes will cause a compilation error. This can be
1375 fixed by simply guarding against the inclusion of these two prototypes unless
1376 they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration
1378 #ifdef configUSE_APPLICATION_TASK_TAG
1379 #if configUSE_APPLICATION_TASK_TAG == 1
1381 * Sets pxHookFunction to be the task hook function used by the task xTask.
1382 * @param xTask Handle of the task to set the hook function for
1383 * Passing xTask as NULL has the effect of setting the calling
1384 * tasks hook function.
1385 * @param pxHookFunction Pointer to the hook function.
1387 void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction ) PRIVILEGED_FUNCTION;
1390 * Get the hook function assigned to given task.
1391 * @param xTask Handle of the task to get the hook function for
1392 * Passing xTask as NULL has the effect of getting the calling
1393 * tasks hook function.
1394 * @return The pxHookFunction value assigned to the task xTask.
1396 TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1397 #endif /* configUSE_APPLICATION_TASK_TAG ==1 */
1398 #endif /* ifdef configUSE_APPLICATION_TASK_TAG */
1399 #if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )
1402 * Set local storage pointer specific to the given task.
1404 * Each task contains an array of pointers that is dimensioned by the
1405 * configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h.
1406 * The kernel does not use the pointers itself, so the application writer
1407 * can use the pointers for any purpose they wish.
1409 * @param xTaskToSet Task to set thread local storage pointer for
1410 * @param xIndex The index of the pointer to set, from 0 to
1411 * configNUM_THREAD_LOCAL_STORAGE_POINTERS - 1.
1412 * @param pvValue Pointer value to set.
1414 void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue ) PRIVILEGED_FUNCTION;
1418 * Get local storage pointer specific to the given task.
1420 * Each task contains an array of pointers that is dimensioned by the
1421 * configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h.
1422 * The kernel does not use the pointers itself, so the application writer
1423 * can use the pointers for any purpose they wish.
1425 * @param xTaskToQuery Task to get thread local storage pointer for
1426 * @param xIndex The index of the pointer to get, from 0 to
1427 * configNUM_THREAD_LOCAL_STORAGE_POINTERS - 1.
1428 * @return Pointer value
1430 void *pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, BaseType_t xIndex ) PRIVILEGED_FUNCTION;
1432 #if ( configTHREAD_LOCAL_STORAGE_DELETE_CALLBACKS )
1435 * Prototype of local storage pointer deletion callback.
1437 typedef void (*TlsDeleteCallbackFunction_t)( int, void * );
1440 * Set local storage pointer and deletion callback.
1442 * Each task contains an array of pointers that is dimensioned by the
1443 * configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h.
1444 * The kernel does not use the pointers itself, so the application writer
1445 * can use the pointers for any purpose they wish.
1447 * Local storage pointers set for a task can reference dynamically
1448 * allocated resources. This function is similar to
1449 * vTaskSetThreadLocalStoragePointer, but provides a way to release
1450 * these resources when the task gets deleted. For each pointer,
1451 * a callback function can be set. This function will be called
1452 * when task is deleted, with the local storage pointer index
1453 * and value as arguments.
1455 * @param xTaskToSet Task to set thread local storage pointer for
1456 * @param xIndex The index of the pointer to set, from 0 to
1457 * configNUM_THREAD_LOCAL_STORAGE_POINTERS - 1.
1458 * @param pvValue Pointer value to set.
1459 * @param pvDelCallback Function to call to dispose of the local
1460 * storage pointer when the task is deleted.
1462 void vTaskSetThreadLocalStoragePointerAndDelCallback( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue, TlsDeleteCallbackFunction_t pvDelCallback);
1468 * Calls the hook function associated with xTask. Passing xTask as NULL has
1469 * the effect of calling the Running tasks (the calling task) hook function.
1471 * @param xTask Handle of the task to call the hook for.
1472 * @param pvParameter Parameter passed to the hook function for the task to interpret as it
1473 * wants. The return value is the value returned by the task hook function
1474 * registered by the user.
1476 BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter ) PRIVILEGED_FUNCTION;
1479 * Get the handle of idle task for the current CPU.
1481 * xTaskGetIdleTaskHandle() is only available if
1482 * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.
1484 * @return The handle of the idle task. It is not valid to call
1485 * xTaskGetIdleTaskHandle() before the scheduler has been started.
1487 TaskHandle_t xTaskGetIdleTaskHandle( void );
1490 * Get the handle of idle task for the given CPU.
1492 * xTaskGetIdleTaskHandleForCPU() is only available if
1493 * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.
1495 * @param cpuid The CPU to get the handle for
1497 * @return Idle task handle of a given cpu. It is not valid to call
1498 * xTaskGetIdleTaskHandleForCPU() before the scheduler has been started.
1500 TaskHandle_t xTaskGetIdleTaskHandleForCPU( UBaseType_t cpuid );
1503 * Get the state of tasks in the system.
1505 * configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for
1506 * uxTaskGetSystemState() to be available.
1508 * uxTaskGetSystemState() populates an TaskStatus_t structure for each task in
1509 * the system. TaskStatus_t structures contain, among other things, members
1510 * for the task handle, task name, task priority, task state, and total amount
1511 * of run time consumed by the task. See the TaskStatus_t structure
1512 * definition in this file for the full member list.
1514 * @note This function is intended for debugging use only as its use results in
1515 * the scheduler remaining suspended for an extended period.
1517 * @param pxTaskStatusArray A pointer to an array of TaskStatus_t structures.
1518 * The array must contain at least one TaskStatus_t structure for each task
1519 * that is under the control of the RTOS. The number of tasks under the control
1520 * of the RTOS can be determined using the uxTaskGetNumberOfTasks() API function.
1522 * @param uxArraySize The size of the array pointed to by the pxTaskStatusArray
1523 * parameter. The size is specified as the number of indexes in the array, or
1524 * the number of TaskStatus_t structures contained in the array, not by the
1525 * number of bytes in the array.
1527 * @param pulTotalRunTime If configGENERATE_RUN_TIME_STATS is set to 1 in
1528 * FreeRTOSConfig.h then *pulTotalRunTime is set by uxTaskGetSystemState() to the
1529 * total run time (as defined by the run time stats clock, see
1530 * http://www.freertos.org/rtos-run-time-stats.html) since the target booted.
1531 * pulTotalRunTime can be set to NULL to omit the total run time information.
1533 * @return The number of TaskStatus_t structures that were populated by
1534 * uxTaskGetSystemState(). This should equal the number returned by the
1535 * uxTaskGetNumberOfTasks() API function, but will be zero if the value passed
1536 * in the uxArraySize parameter was too small.
1540 * // This example demonstrates how a human readable table of run time stats
1541 * // information is generated from raw data provided by uxTaskGetSystemState().
1542 * // The human readable table is written to pcWriteBuffer
1543 * void vTaskGetRunTimeStats( char *pcWriteBuffer )
1545 * TaskStatus_t *pxTaskStatusArray;
1546 * volatile UBaseType_t uxArraySize, x;
1547 * uint32_t ulTotalRunTime, ulStatsAsPercentage;
1549 * // Make sure the write buffer does not contain a string.
1550 * *pcWriteBuffer = 0x00;
1552 * // Take a snapshot of the number of tasks in case it changes while this
1553 * // function is executing.
1554 * uxArraySize = uxTaskGetNumberOfTasks();
1556 * // Allocate a TaskStatus_t structure for each task. An array could be
1557 * // allocated statically at compile time.
1558 * pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
1560 * if( pxTaskStatusArray != NULL )
1562 * // Generate raw status information about each task.
1563 * uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );
1565 * // For percentage calculations.
1566 * ulTotalRunTime /= 100UL;
1568 * // Avoid divide by zero errors.
1569 * if( ulTotalRunTime > 0 )
1571 * // For each populated position in the pxTaskStatusArray array,
1572 * // format the raw data as human readable ASCII data
1573 * for( x = 0; x < uxArraySize; x++ )
1575 * // What percentage of the total run time has the task used?
1576 * // This will always be rounded down to the nearest integer.
1577 * // ulTotalRunTimeDiv100 has already been divided by 100.
1578 * ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;
1580 * if( ulStatsAsPercentage > 0UL )
1582 * sprintf( pcWriteBuffer, "%s\t\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );
1586 * // If the percentage is zero here then the task has
1587 * // consumed less than 1% of the total run time.
1588 * sprintf( pcWriteBuffer, "%s\t\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter );
1591 * pcWriteBuffer += strlen( ( char * ) pcWriteBuffer );
1595 * // The array is no longer needed, free the memory it consumes.
1596 * vPortFree( pxTaskStatusArray );
1601 UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime );
1604 * List all the current tasks.
1606 * configUSE_TRACE_FACILITY and configUSE_STATS_FORMATTING_FUNCTIONS must
1607 * both be defined as 1 for this function to be available. See the
1608 * configuration section of the FreeRTOS.org website for more information.
1610 * @note This function will disable interrupts for its duration. It is
1611 * not intended for normal application runtime use but as a debug aid.
1613 * Lists all the current tasks, along with their current state and stack
1614 * usage high water mark.
1616 * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or
1619 * @note This function is provided for convenience only, and is used by many of the
1620 * demo applications. Do not consider it to be part of the scheduler.
1622 * vTaskList() calls uxTaskGetSystemState(), then formats part of the
1623 * uxTaskGetSystemState() output into a human readable table that displays task
1624 * names, states and stack usage.
1626 * vTaskList() has a dependency on the sprintf() C library function that might
1627 * bloat the code size, use a lot of stack, and provide different results on
1628 * different platforms. An alternative, tiny, third party, and limited
1629 * functionality implementation of sprintf() is provided in many of the
1630 * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
1631 * printf-stdarg.c does not provide a full snprintf() implementation!).
1633 * It is recommended that production systems call uxTaskGetSystemState()
1634 * directly to get access to raw stats data, rather than indirectly through a
1635 * call to vTaskList().
1637 * @param pcWriteBuffer A buffer into which the above mentioned details
1638 * will be written, in ASCII form. This buffer is assumed to be large
1639 * enough to contain the generated report. Approximately 40 bytes per
1640 * task should be sufficient.
1642 * \ingroup TaskUtils
1644 void vTaskList( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1647 * Get the state of running tasks as a string
1649 * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS
1650 * must both be defined as 1 for this function to be available. The application
1651 * must also then provide definitions for
1652 * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()
1653 * to configure a peripheral timer/counter and return the timers current count
1654 * value respectively. The counter should be at least 10 times the frequency of
1657 * @note This function will disable interrupts for its duration. It is
1658 * not intended for normal application runtime use but as a debug aid.
1660 * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
1661 * accumulated execution time being stored for each task. The resolution
1662 * of the accumulated time value depends on the frequency of the timer
1663 * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
1664 * Calling vTaskGetRunTimeStats() writes the total execution time of each
1665 * task into a buffer, both as an absolute count value and as a percentage
1666 * of the total system execution time.
1668 * @note This function is provided for convenience only, and is used by many of the
1669 * demo applications. Do not consider it to be part of the scheduler.
1671 * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part of the
1672 * uxTaskGetSystemState() output into a human readable table that displays the
1673 * amount of time each task has spent in the Running state in both absolute and
1676 * vTaskGetRunTimeStats() has a dependency on the sprintf() C library function
1677 * that might bloat the code size, use a lot of stack, and provide different
1678 * results on different platforms. An alternative, tiny, third party, and
1679 * limited functionality implementation of sprintf() is provided in many of the
1680 * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
1681 * printf-stdarg.c does not provide a full snprintf() implementation!).
1683 * It is recommended that production systems call uxTaskGetSystemState() directly
1684 * to get access to raw stats data, rather than indirectly through a call to
1685 * vTaskGetRunTimeStats().
1687 * @param pcWriteBuffer A buffer into which the execution times will be
1688 * written, in ASCII form. This buffer is assumed to be large enough to
1689 * contain the generated report. Approximately 40 bytes per task should
1692 * \ingroup TaskUtils
1694 void vTaskGetRunTimeStats( char *pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1697 * Send task notification.
1699 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
1700 * function to be available.
1702 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
1703 * "notification value", which is a 32-bit unsigned integer (uint32_t).
1705 * Events can be sent to a task using an intermediary object. Examples of such
1706 * objects are queues, semaphores, mutexes and event groups. Task notifications
1707 * are a method of sending an event directly to a task without the need for such
1708 * an intermediary object.
1710 * A notification sent to a task can optionally perform an action, such as
1711 * update, overwrite or increment the task's notification value. In that way
1712 * task notifications can be used to send data to a task, or be used as light
1713 * weight and fast binary or counting semaphores.
1715 * A notification sent to a task will remain pending until it is cleared by the
1716 * task calling xTaskNotifyWait() or ulTaskNotifyTake(). If the task was
1717 * already in the Blocked state to wait for a notification when the notification
1718 * arrives then the task will automatically be removed from the Blocked state
1719 * (unblocked) and the notification cleared.
1721 * A task can use xTaskNotifyWait() to [optionally] block to wait for a
1722 * notification to be pending, or ulTaskNotifyTake() to [optionally] block
1723 * to wait for its notification value to have a non-zero value. The task does
1724 * not consume any CPU time while it is in the Blocked state.
1726 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
1728 * @param xTaskToNotify The handle of the task being notified. The handle to a
1729 * task can be returned from the xTaskCreate() API function used to create the
1730 * task, and the handle of the currently running task can be obtained by calling
1731 * xTaskGetCurrentTaskHandle().
1733 * @param ulValue Data that can be sent with the notification. How the data is
1734 * used depends on the value of the eAction parameter.
1736 * @param eAction Specifies how the notification updates the task's notification
1737 * value, if at all. Valid values for eAction are as follows:
1739 * The task's notification value is bitwise ORed with ulValue. xTaskNofify()
1740 * always returns pdPASS in this case.
1743 * The task's notification value is incremented. ulValue is not used and
1744 * xTaskNotify() always returns pdPASS in this case.
1746 * - eSetValueWithOverwrite:
1747 * The task's notification value is set to the value of ulValue, even if the
1748 * task being notified had not yet processed the previous notification (the
1749 * task already had a notification pending). xTaskNotify() always returns
1750 * pdPASS in this case.
1752 * - eSetValueWithoutOverwrite:
1753 * If the task being notified did not already have a notification pending then
1754 * the task's notification value is set to ulValue and xTaskNotify() will
1755 * return pdPASS. If the task being notified already had a notification
1756 * pending then no action is performed and pdFAIL is returned.
1759 * The task receives a notification without its notification value being
1760 * Â Â updated. ulValue is not used and xTaskNotify() always returns pdPASS in
1763 * @return Dependent on the value of eAction. See the description of the
1764 * eAction parameter.
1766 * \ingroup TaskNotifications
1768 BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction );
1771 * Send task notification from an ISR.
1773 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
1774 * function to be available.
1776 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
1777 * "notification value", which is a 32-bit unsigned integer (uint32_t).
1779 * A version of xTaskNotify() that can be used from an interrupt service routine
1782 * Events can be sent to a task using an intermediary object. Examples of such
1783 * objects are queues, semaphores, mutexes and event groups. Task notifications
1784 * are a method of sending an event directly to a task without the need for such
1785 * an intermediary object.
1787 * A notification sent to a task can optionally perform an action, such as
1788 * update, overwrite or increment the task's notification value. In that way
1789 * task notifications can be used to send data to a task, or be used as light
1790 * weight and fast binary or counting semaphores.
1792 * A notification sent to a task will remain pending until it is cleared by the
1793 * task calling xTaskNotifyWait() or ulTaskNotifyTake(). If the task was
1794 * already in the Blocked state to wait for a notification when the notification
1795 * arrives then the task will automatically be removed from the Blocked state
1796 * (unblocked) and the notification cleared.
1798 * A task can use xTaskNotifyWait() to [optionally] block to wait for a
1799 * notification to be pending, or ulTaskNotifyTake() to [optionally] block
1800 * to wait for its notification value to have a non-zero value. The task does
1801 * not consume any CPU time while it is in the Blocked state.
1803 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
1805 * @param xTaskToNotify The handle of the task being notified. The handle to a
1806 * task can be returned from the xTaskCreate() API function used to create the
1807 * task, and the handle of the currently running task can be obtained by calling
1808 * xTaskGetCurrentTaskHandle().
1810 * @param ulValue Data that can be sent with the notification. How the data is
1811 * used depends on the value of the eAction parameter.
1813 * @param eAction Specifies how the notification updates the task's notification
1814 * value, if at all. Valid values for eAction are as follows:
1816 * The task's notification value is bitwise ORed with ulValue. xTaskNofify()
1817 * always returns pdPASS in this case.
1820 * The task's notification value is incremented. ulValue is not used and
1821 * xTaskNotify() always returns pdPASS in this case.
1823 * - eSetValueWithOverwrite:
1824 * The task's notification value is set to the value of ulValue, even if the
1825 * task being notified had not yet processed the previous notification (the
1826 * task already had a notification pending). xTaskNotify() always returns
1827 * pdPASS in this case.
1829 * - eSetValueWithoutOverwrite:
1830 * If the task being notified did not already have a notification pending then
1831 * the task's notification value is set to ulValue and xTaskNotify() will
1832 * return pdPASS. If the task being notified already had a notification
1833 * pending then no action is performed and pdFAIL is returned.
1836 * The task receives a notification without its notification value being
1837 * updated. ulValue is not used and xTaskNotify() always returns pdPASS in
1840 * @param pxHigherPriorityTaskWoken xTaskNotifyFromISR() will set
1841 * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
1842 * task to which the notification was sent to leave the Blocked state, and the
1843 * unblocked task has a priority higher than the currently running task. If
1844 * xTaskNotifyFromISR() sets this value to pdTRUE then a context switch should
1845 * be requested before the interrupt is exited. How a context switch is
1846 * requested from an ISR is dependent on the port - see the documentation page
1847 * for the port in use.
1849 * @return Dependent on the value of eAction. See the description of the
1850 * eAction parameter.
1852 * \ingroup TaskNotifications
1854 BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );
1857 * Wait for task notification
1859 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
1860 * function to be available.
1862 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
1863 * "notification value", which is a 32-bit unsigned integer (uint32_t).
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 ulBitsToClearOnEntry Bits that are set in ulBitsToClearOnEntry value
1889 * will be cleared in the calling task's notification value before the task
1890 * checks to see if any notifications are pending, and optionally blocks if no
1891 * notifications are pending. Setting ulBitsToClearOnEntry to ULONG_MAX (if
1892 * limits.h is included) or 0xffffffffUL (if limits.h is not included) will have
1893 * the effect of resetting the task's notification value to 0. Setting
1894 * ulBitsToClearOnEntry to 0 will leave the task's notification value unchanged.
1896 * @param ulBitsToClearOnExit If a notification is pending or received before
1897 * the calling task exits the xTaskNotifyWait() function then the task's
1898 * notification value (see the xTaskNotify() API function) is passed out using
1899 * the pulNotificationValue parameter. Then any bits that are set in
1900 * ulBitsToClearOnExit will be cleared in the task's notification value (note
1901 * *pulNotificationValue is set before any bits are cleared). Setting
1902 * ulBitsToClearOnExit to ULONG_MAX (if limits.h is included) or 0xffffffffUL
1903 * (if limits.h is not included) will have the effect of resetting the task's
1904 * notification value to 0 before the function exits. Setting
1905 * ulBitsToClearOnExit to 0 will leave the task's notification value unchanged
1906 * when the function exits (in which case the value passed out in
1907 * pulNotificationValue will match the task's notification value).
1909 * @param pulNotificationValue Used to pass the task's notification value out
1910 * of the function. Note the value passed out will not be effected by the
1911 * clearing of any bits caused by ulBitsToClearOnExit being non-zero.
1913 * @param xTicksToWait The maximum amount of time that the task should wait in
1914 * the Blocked state for a notification to be received, should a notification
1915 * not already be pending when xTaskNotifyWait() was called. The task
1916 * will not consume any processing time while it is in the Blocked state. This
1917 * is specified in kernel ticks, the macro pdMS_TO_TICSK( value_in_ms ) can be
1918 * used to convert a time specified in milliseconds to a time specified in
1921 * @return If a notification was received (including notifications that were
1922 * already pending when xTaskNotifyWait was called) then pdPASS is
1923 * returned. Otherwise pdFAIL is returned.
1925 * \ingroup TaskNotifications
1927 BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );
1930 * Simplified macro for sending task notification.
1932 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
1935 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
1936 * "notification value", which is a 32-bit unsigned integer (uint32_t).
1938 * Events can be sent to a task using an intermediary object. Examples of such
1939 * objects are queues, semaphores, mutexes and event groups. Task notifications
1940 * are a method of sending an event directly to a task without the need for such
1941 * an intermediary object.
1943 * A notification sent to a task can optionally perform an action, such as
1944 * update, overwrite or increment the task's notification value. In that way
1945 * task notifications can be used to send data to a task, or be used as light
1946 * weight and fast binary or counting semaphores.
1948 * xTaskNotifyGive() is a helper macro intended for use when task notifications
1949 * are used as light weight and faster binary or counting semaphore equivalents.
1950 * Actual FreeRTOS semaphores are given using the xSemaphoreGive() API function,
1951 * the equivalent action that instead uses a task notification is
1952 * xTaskNotifyGive().
1954 * When task notifications are being used as a binary or counting semaphore
1955 * equivalent then the task being notified should wait for the notification
1956 * using the ulTaskNotificationTake() API function rather than the
1957 * xTaskNotifyWait() API function.
1959 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
1961 * @param xTaskToNotify The handle of the task being notified. The handle to a
1962 * task can be returned from the xTaskCreate() API function used to create the
1963 * task, and the handle of the currently running task can be obtained by calling
1964 * xTaskGetCurrentTaskHandle().
1966 * @return xTaskNotifyGive() is a macro that calls xTaskNotify() with the
1967 * eAction parameter set to eIncrement - so pdPASS is always returned.
1969 * \ingroup TaskNotifications
1971 #define xTaskNotifyGive( xTaskToNotify ) xTaskNotify( ( xTaskToNotify ), 0, eIncrement );
1974 * Simplified macro for sending task notification from ISR.
1976 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
1979 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
1980 * "notification value", which is a 32-bit unsigned integer (uint32_t).
1982 * A version of xTaskNotifyGive() that can be called from an interrupt service
1985 * Events can be sent to a task using an intermediary object. Examples of such
1986 * objects are queues, semaphores, mutexes and event groups. Task notifications
1987 * are a method of sending an event directly to a task without the need for such
1988 * an intermediary object.
1990 * A notification sent to a task can optionally perform an action, such as
1991 * update, overwrite or increment the task's notification value. In that way
1992 * task notifications can be used to send data to a task, or be used as light
1993 * weight and fast binary or counting semaphores.
1995 * vTaskNotifyGiveFromISR() is intended for use when task notifications are
1996 * used as light weight and faster binary or counting semaphore equivalents.
1997 * Actual FreeRTOS semaphores are given from an ISR using the
1998 * xSemaphoreGiveFromISR() API function, the equivalent action that instead uses
1999 * a task notification is vTaskNotifyGiveFromISR().
2001 * When task notifications are being used as a binary or counting semaphore
2002 * equivalent then the task being notified should wait for the notification
2003 * using the ulTaskNotificationTake() API function rather than the
2004 * xTaskNotifyWait() API function.
2006 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
2008 * @param xTaskToNotify The handle of the task being notified. The handle to a
2009 * task can be returned from the xTaskCreate() API function used to create the
2010 * task, and the handle of the currently running task can be obtained by calling
2011 * xTaskGetCurrentTaskHandle().
2013 * @param pxHigherPriorityTaskWoken vTaskNotifyGiveFromISR() will set
2014 * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
2015 * task to which the notification was sent to leave the Blocked state, and the
2016 * unblocked task has a priority higher than the currently running task. If
2017 * vTaskNotifyGiveFromISR() sets this value to pdTRUE then a context switch
2018 * should be requested before the interrupt is exited. How a context switch is
2019 * requested from an ISR is dependent on the port - see the documentation page
2020 * for the port in use.
2022 * \ingroup TaskNotifications
2024 void vTaskNotifyGiveFromISR( TaskHandle_t xTaskToNotify, BaseType_t *pxHigherPriorityTaskWoken );
2027 * Simplified macro for receiving task notification.
2029 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
2030 * function to be available.
2032 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
2033 * "notification value", which is a 32-bit unsigned integer (uint32_t).
2035 * Events can be sent to a task using an intermediary object. Examples of such
2036 * objects are queues, semaphores, mutexes and event groups. Task notifications
2037 * are a method of sending an event directly to a task without the need for such
2038 * an intermediary object.
2040 * A notification sent to a task can optionally perform an action, such as
2041 * update, overwrite or increment the task's notification value. In that way
2042 * task notifications can be used to send data to a task, or be used as light
2043 * weight and fast binary or counting semaphores.
2045 * ulTaskNotifyTake() is intended for use when a task notification is used as a
2046 * faster and lighter weight binary or counting semaphore alternative. Actual
2047 * FreeRTOS semaphores are taken using the xSemaphoreTake() API function, the
2048 * equivalent action that instead uses a task notification is
2049 * ulTaskNotifyTake().
2051 * When a task is using its notification value as a binary or counting semaphore
2052 * other tasks should send notifications to it using the xTaskNotifyGive()
2053 * macro, or xTaskNotify() function with the eAction parameter set to
2056 * ulTaskNotifyTake() can either clear the task's notification value to
2057 * zero on exit, in which case the notification value acts like a binary
2058 * semaphore, or decrement the task's notification value on exit, in which case
2059 * the notification value acts like a counting semaphore.
2061 * A task can use ulTaskNotifyTake() to [optionally] block to wait for a
2062 * the task's notification value to be non-zero. The task does not consume any
2063 * CPU time while it is in the Blocked state.
2065 * Where as xTaskNotifyWait() will return when a notification is pending,
2066 * ulTaskNotifyTake() will return when the task's notification value is
2069 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
2071 * @param xClearCountOnExit if xClearCountOnExit is pdFALSE then the task's
2072 * notification value is decremented when the function exits. In this way the
2073 * notification value acts like a counting semaphore. If xClearCountOnExit is
2074 * not pdFALSE then the task's notification value is cleared to zero when the
2075 * function exits. In this way the notification value acts like a binary
2078 * @param xTicksToWait The maximum amount of time that the task should wait in
2079 * the Blocked state for the task's notification value to be greater than zero,
2080 * should the count not already be greater than zero when
2081 * ulTaskNotifyTake() was called. The task will not consume any processing
2082 * time while it is in the Blocked state. This is specified in kernel ticks,
2083 * the macro pdMS_TO_TICSK( value_in_ms ) can be used to convert a time
2084 * specified in milliseconds to a time specified in ticks.
2086 * @return The task's notification count before it is either cleared to zero or
2087 * decremented (see the xClearCountOnExit parameter).
2089 * \ingroup TaskNotifications
2091 uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait );
2093 /*-----------------------------------------------------------
2094 * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
2095 *----------------------------------------------------------*/
2098 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
2099 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
2100 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2102 * Called from the real time kernel tick (either preemptive or cooperative),
2103 * this increments the tick count and checks if any tasks that are blocked
2104 * for a finite period required removing from a blocked list and placing on
2105 * a ready list. If a non-zero value is returned then a context switch is
2106 * required because either:
2107 * + A task was removed from a blocked list because its timeout had expired,
2109 * + Time slicing is in use and there is a task of equal priority to the
2110 * currently running task.
2112 BaseType_t xTaskIncrementTick( void ) PRIVILEGED_FUNCTION;
2115 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
2116 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2118 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
2120 * Removes the calling task from the ready list and places it both
2121 * on the list of tasks waiting for a particular event, and the
2122 * list of delayed tasks. The task will be removed from both lists
2123 * and replaced on the ready list should either the event occur (and
2124 * there be no higher priority tasks waiting on the same event) or
2125 * the delay period expires.
2127 * The 'unordered' version replaces the event list item value with the
2128 * xItemValue value, and inserts the list item at the end of the list.
2130 * The 'ordered' version uses the existing event list item value (which is the
2131 * owning tasks priority) to insert the list item into the event list is task
2134 * @param pxEventList The list containing tasks that are blocked waiting
2135 * for the event to occur.
2137 * @param xItemValue The item value to use for the event list item when the
2138 * event list is not ordered by task priority.
2140 * @param xTicksToWait The maximum amount of time that the task should wait
2141 * for the event to occur. This is specified in kernel ticks,the constant
2142 * portTICK_PERIOD_MS can be used to convert kernel ticks into a real time
2145 void vTaskPlaceOnEventList( List_t * const pxEventList, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2146 void vTaskPlaceOnUnorderedEventList( List_t * pxEventList, const TickType_t xItemValue, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2149 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
2150 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2152 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
2154 * This function performs nearly the same function as vTaskPlaceOnEventList().
2155 * The difference being that this function does not permit tasks to block
2156 * indefinitely, whereas vTaskPlaceOnEventList() does.
2159 void vTaskPlaceOnEventListRestricted( List_t * const pxEventList, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2162 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
2163 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2165 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
2167 * Removes a task from both the specified event list and the list of blocked
2168 * tasks, and places it on a ready queue.
2170 * xTaskRemoveFromEventList()/xTaskRemoveFromUnorderedEventList() will be called
2171 * if either an event occurs to unblock a task, or the block timeout period
2174 * xTaskRemoveFromEventList() is used when the event list is in task priority
2175 * order. It removes the list item from the head of the event list as that will
2176 * have the highest priority owning task of all the tasks on the event list.
2177 * xTaskRemoveFromUnorderedEventList() is used when the event list is not
2178 * ordered and the event list items hold something other than the owning tasks
2179 * priority. In this case the event list item value is updated to the value
2180 * passed in the xItemValue parameter.
2182 * @return pdTRUE if the task being removed has a higher priority than the task
2183 * making the call, otherwise pdFALSE.
2185 BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList ) PRIVILEGED_FUNCTION;
2186 BaseType_t xTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem, const TickType_t xItemValue ) PRIVILEGED_FUNCTION;
2189 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
2190 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
2191 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2193 * Sets the pointer to the current TCB to the TCB of the highest priority task
2194 * that is ready to run.
2196 void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION;
2199 * THESE FUNCTIONS MUST NOT BE USED FROM APPLICATION CODE. THEY ARE USED BY
2200 * THE EVENT BITS MODULE.
2202 TickType_t uxTaskResetEventItemValue( void ) PRIVILEGED_FUNCTION;
2205 * Return the handle of the calling task.
2207 TaskHandle_t xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION;
2212 * Return the handle of the task running on a certain CPU. Because of
2213 * the nature of SMP processing, there is no guarantee that this
2214 * value will still be valid on return and should only be used for
2215 * debugging purposes.
2217 TaskHandle_t xTaskGetCurrentTaskHandleForCPU( BaseType_t cpuid );
2221 * Capture the current time status for future reference.
2223 void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
2226 * Compare the time status now with that previously captured to see if the
2227 * timeout has expired.
2229 BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait ) PRIVILEGED_FUNCTION;
2232 * Shortcut used by the queue implementation to prevent unnecessary call to
2235 void vTaskMissedYield( void ) PRIVILEGED_FUNCTION;
2238 * Returns the scheduler state as taskSCHEDULER_RUNNING,
2239 * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
2241 BaseType_t xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION;
2244 * Raises the priority of the mutex holder to that of the calling task should
2245 * the mutex holder have a priority less than the calling task.
2247 void vTaskPriorityInherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
2250 * Set the priority of a task back to its proper priority in the case that it
2251 * inherited a higher priority while it was holding a semaphore.
2253 BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
2256 * Get the uxTCBNumber assigned to the task referenced by the xTask parameter.
2258 UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
2262 * Get the current core affinity of a task
2264 BaseType_t xTaskGetAffinity( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
2267 * Set the uxTaskNumber of the task referenced by the xTask parameter to
2270 void vTaskSetTaskNumber( TaskHandle_t xTask, const UBaseType_t uxHandle ) PRIVILEGED_FUNCTION;
2273 * Only available when configUSE_TICKLESS_IDLE is set to 1.
2274 * If tickless mode is being used, or a low power mode is implemented, then
2275 * the tick interrupt will not execute during idle periods. When this is the
2276 * case, the tick count value maintained by the scheduler needs to be kept up
2277 * to date with the actual execution time by being skipped forward by a time
2278 * equal to the idle period.
2280 void vTaskStepTick( const TickType_t xTicksToJump ) PRIVILEGED_FUNCTION;
2283 * Only avilable when configUSE_TICKLESS_IDLE is set to 1.
2284 * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port
2285 * specific sleep function to determine if it is ok to proceed with the sleep,
2286 * and if it is ok to proceed, if it is ok to sleep indefinitely.
2288 * This function is necessary because portSUPPRESS_TICKS_AND_SLEEP() is only
2289 * called with the scheduler suspended, not from within a critical section. It
2290 * is therefore possible for an interrupt to request a context switch between
2291 * portSUPPRESS_TICKS_AND_SLEEP() and the low power mode actually being
2292 * entered. eTaskConfirmSleepModeStatus() should be called from a short
2293 * critical section between the timer being stopped and the sleep mode being
2294 * entered to ensure it is ok to proceed into the sleep mode.
2296 eSleepModeStatus eTaskConfirmSleepModeStatus( void ) PRIVILEGED_FUNCTION;
2299 * For internal use only. Increment the mutex held count when a mutex is
2300 * taken and return the handle of the task that has taken the mutex.
2302 void *pvTaskIncrementMutexHeldCount( void );
2305 * This function fills array with TaskSnapshot_t structures for every task in the system.
2306 * Used by core dump facility to get snapshots of all tasks in the system.
2307 * Only available when configENABLE_TASK_SNAPSHOT is set to 1.
2308 * @param pxTaskSnapshotArray Pointer to array of TaskSnapshot_t structures to store tasks snapshot data.
2309 * @param uxArraySize Size of tasks snapshots array.
2310 * @param pxTcbSz Pointer to store size of TCB.
2311 * @return Number of elements stored in array.
2313 UBaseType_t uxTaskGetSnapshotAll( TaskSnapshot_t * const pxTaskSnapshotArray, const UBaseType_t uxArraySize, UBaseType_t * const pxTcbSz );
2320 #endif /* INC_TASK_H */