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