blob: f77009c8fe2c65ac6958bbc724b5e018685e9bb1 [file] [log] [blame]
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001/*
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002 * FreeRTOS Kernel V10.2.1
3 * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08004 *
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 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +080022 * http://www.FreeRTOS.org
23 * http://aws.amazon.com/freertos
kelvin.zhang57fb6ae2021-10-15 10:19:42 +080024 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +080025 * 1 tab == 4 spaces!
kelvin.zhang57fb6ae2021-10-15 10:19:42 +080026 */
27
28
29#ifndef INC_TASK_H
30#define INC_TASK_H
31
32#ifndef INC_FREERTOS_H
xiaohu.huang4f321fb2024-03-22 14:50:29 +080033 #error "include FreeRTOS.h must appear in source files before include task.h"
kelvin.zhang57fb6ae2021-10-15 10:19:42 +080034#endif
35
36#include "list.h"
37
38#ifdef __cplusplus
xiaohu.huang4f321fb2024-03-22 14:50:29 +080039extern "C" {
kelvin.zhang57fb6ae2021-10-15 10:19:42 +080040#endif
41
42/*-----------------------------------------------------------
xiaohu.huang4f321fb2024-03-22 14:50:29 +080043 * MACROS AND DEFINITIONS
44 *----------------------------------------------------------*/
kelvin.zhang57fb6ae2021-10-15 10:19:42 +080045
xiaohu.huang4f321fb2024-03-22 14:50:29 +080046#define tskKERNEL_VERSION_NUMBER "V10.2.0"
47#define tskKERNEL_VERSION_MAJOR 10
48#define tskKERNEL_VERSION_MINOR 2
49#define tskKERNEL_VERSION_BUILD 0
kelvin.zhang57fb6ae2021-10-15 10:19:42 +080050
51/* MPU region parameters passed in ulParameters
52 * of MemoryRegion_t struct. */
xiaohu.huang4f321fb2024-03-22 14:50:29 +080053#define tskMPU_REGION_READ_ONLY ( 1UL << 0UL )
54#define tskMPU_REGION_READ_WRITE ( 1UL << 1UL )
55#define tskMPU_REGION_EXECUTE_NEVER ( 1UL << 2UL )
56#define tskMPU_REGION_NORMAL_MEMORY ( 1UL << 3UL )
57#define tskMPU_REGION_DEVICE_MEMORY ( 1UL << 4UL )
kelvin.zhang57fb6ae2021-10-15 10:19:42 +080058
59/**
60 * task. h
61 *
62 * Type by which tasks are referenced. For example, a call to xTaskCreate
63 * returns (via a pointer parameter) an TaskHandle_t variable that can then
64 * be used as a parameter to vTaskDelete to delete the task.
65 *
66 * \defgroup TaskHandle_t TaskHandle_t
67 * \ingroup Tasks
68 */
69struct tskTaskControlBlock; /* The old naming convention is used to prevent breaking kernel aware debuggers. */
xiaohu.huang4f321fb2024-03-22 14:50:29 +080070typedef struct tskTaskControlBlock* TaskHandle_t;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +080071
72/*
73 * Defines the prototype to which the application task hook function must
74 * conform.
75 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +080076typedef BaseType_t (*TaskHookFunction_t)( void * );
kelvin.zhang57fb6ae2021-10-15 10:19:42 +080077
78/* Task states returned by eTaskGetState. */
79typedef enum
80{
xiaohu.huang4f321fb2024-03-22 14:50:29 +080081 eRunning = 0, /* A task is querying the state of itself, so must be running. */
82 eReady, /* The task being queried is in a read or pending ready list. */
83 eBlocked, /* The task being queried is in the Blocked state. */
84 eSuspended, /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */
85 eDeleted, /* The task being queried has been deleted, but its TCB has not yet been freed. */
86 eInvalid /* Used as an 'invalid state' value. */
kelvin.zhang57fb6ae2021-10-15 10:19:42 +080087} eTaskState;
88
89/* Actions that can be performed when vTaskNotify() is called. */
90typedef enum
91{
xiaohu.huang4f321fb2024-03-22 14:50:29 +080092 eNoAction = 0, /* Notify the task without updating its notify value. */
93 eSetBits, /* Set bits in the task's notification value. */
94 eIncrement, /* Increment the task's notification value. */
95 eSetValueWithOverwrite, /* Set the task's notification value to a specific value even if the previous value has not yet been read by the task. */
96 eSetValueWithoutOverwrite /* Set the task's notification value if the previous value has been read by the task. */
kelvin.zhang57fb6ae2021-10-15 10:19:42 +080097} eNotifyAction;
98
99/*
100 * Used internally only.
101 */
102typedef struct xTIME_OUT
103{
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800104 BaseType_t xOverflowCount;
105 TickType_t xTimeOnEntering;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800106} TimeOut_t;
107
108/*
109 * Defines the memory ranges allocated to the task when an MPU is used.
110 */
111typedef struct xMEMORY_REGION
112{
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800113 void *pvBaseAddress;
114 uint32_t ulLengthInBytes;
115 uint32_t ulParameters;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800116} MemoryRegion_t;
117
118/*
119 * Parameters required to create an MPU protected task.
120 */
121typedef struct xTASK_PARAMETERS
122{
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800123 TaskFunction_t pvTaskCode;
124 const char * const pcName; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
125 configSTACK_DEPTH_TYPE usStackDepth;
126 void *pvParameters;
127 UBaseType_t uxPriority;
128 StackType_t *puxStackBuffer;
129 MemoryRegion_t xRegions[ portNUM_CONFIGURABLE_REGIONS ];
130 #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
131 StaticTask_t * const pxTaskBuffer;
132 #endif
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800133} TaskParameters_t;
134
135/* Used with the uxTaskGetSystemState() function to return the state of each task
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800136in the system. */
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800137typedef struct xTASK_STATUS
138{
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800139 TaskHandle_t xHandle; /* The handle of the task to which the rest of the information in the structure relates. */
140 const char *pcTaskName; /* A pointer to the task's name. This value will be invalid if the task was deleted since the structure was populated! */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
141 UBaseType_t xTaskNumber; /* A number unique to the task. */
142 eTaskState eCurrentState; /* The state in which the task existed when the structure was populated. */
143 UBaseType_t uxCurrentPriority; /* The priority at which the task was running (may be inherited) when the structure was populated. */
144 UBaseType_t uxBasePriority; /* The priority to which the task will return if the task's current priority has been inherited to avoid unbounded priority inversion when obtaining a mutex. Only valid if configUSE_MUTEXES is defined as 1 in FreeRTOSConfig.h. */
145 uint32_t ulRunTimeCounter; /* The total run time allocated to the task so far, as defined by the run time stats clock. See http://www.freertos.org/rtos-run-time-stats.html. Only valid when configGENERATE_RUN_TIME_STATS is defined as 1 in FreeRTOSConfig.h. */
146 StackType_t *pxStackBase; /* Points to the lowest address of the task's stack area. */
147 configSTACK_DEPTH_TYPE usStackHighWaterMark; /* The minimum amount of stack space that has remained for the task since the task was created. The closer this value is to zero the closer the task has come to overflowing its stack. */
148 StackType_t uStackTotal;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800149} TaskStatus_t;
150
151/* Possible return values for eTaskConfirmSleepModeStatus(). */
152typedef enum
153{
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800154 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. */
155 eStandardSleep, /* Enter a sleep mode that will not last any longer than the expected idle time. */
156 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. */
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800157} eSleepModeStatus;
158
159/**
160 * Defines the priority used by the idle task. This must not be modified.
161 *
162 * \ingroup TaskUtils
163 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800164#define tskIDLE_PRIORITY ( ( UBaseType_t ) 0U )
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800165
166/**
167 * task. h
168 *
169 * Macro for forcing a context switch.
170 *
171 * \defgroup taskYIELD taskYIELD
172 * \ingroup SchedulerControl
173 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800174#define taskYIELD() portYIELD()
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800175
176/**
177 * task. h
178 *
179 * Macro to mark the start of a critical code region. Preemptive context
180 * switches cannot occur when in a critical region.
181 *
182 * NOTE: This may alter the stack (depending on the portable implementation)
183 * so must be used with care!
184 *
185 * \defgroup taskENTER_CRITICAL taskENTER_CRITICAL
186 * \ingroup SchedulerControl
187 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800188#define taskENTER_CRITICAL() portENTER_CRITICAL()
189#define taskENTER_CRITICAL_FROM_ISR() portSET_INTERRUPT_MASK_FROM_ISR()
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800190
191/**
192 * task. h
193 *
194 * Macro to mark the end of a critical code region. Preemptive context
195 * switches cannot occur when in a critical region.
196 *
197 * NOTE: This may alter the stack (depending on the portable implementation)
198 * so must be used with care!
199 *
200 * \defgroup taskEXIT_CRITICAL taskEXIT_CRITICAL
201 * \ingroup SchedulerControl
202 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800203#define taskEXIT_CRITICAL() portEXIT_CRITICAL()
204#define taskEXIT_CRITICAL_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( x )
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800205/**
206 * task. h
207 *
208 * Macro to disable all maskable interrupts.
209 *
210 * \defgroup taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS
211 * \ingroup SchedulerControl
212 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800213#define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS()
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800214
215/**
216 * task. h
217 *
218 * Macro to enable microcontroller interrupts.
219 *
220 * \defgroup taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS
221 * \ingroup SchedulerControl
222 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800223#define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS()
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800224
225/* Definitions returned by xTaskGetSchedulerState(). taskSCHEDULER_SUSPENDED is
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002260 to generate more optimal code when configASSERT() is defined as the constant
227is used in assert() statements. */
228#define taskSCHEDULER_SUSPENDED ( ( BaseType_t ) 0 )
229#define taskSCHEDULER_NOT_STARTED ( ( BaseType_t ) 1 )
230#define taskSCHEDULER_RUNNING ( ( BaseType_t ) 2 )
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800231
232
233/*-----------------------------------------------------------
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800234 * TASK CREATION API
235 *----------------------------------------------------------*/
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800236
237/**
238 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800239 *<pre>
240 BaseType_t xTaskCreate(
241 TaskFunction_t pvTaskCode,
242 const char * const pcName,
243 configSTACK_DEPTH_TYPE usStackDepth,
244 void *pvParameters,
245 UBaseType_t uxPriority,
246 TaskHandle_t *pvCreatedTask
247 );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800248 *
249 * Create a new task and add it to the list of tasks that are ready to run.
250 *
251 * Internally, within the FreeRTOS implementation, tasks use two blocks of
252 * memory. The first block is used to hold the task's data structures. The
253 * second block is used by the task as its stack. If a task is created using
254 * xTaskCreate() then both blocks of memory are automatically dynamically
255 * allocated inside the xTaskCreate() function. (see
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800256 * http://www.freertos.org/a00111.html). If a task is created using
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800257 * xTaskCreateStatic() then the application writer must provide the required
258 * memory. xTaskCreateStatic() therefore allows a task to be created without
259 * using any dynamic memory allocation.
260 *
261 * See xTaskCreateStatic() for a version that does not use any dynamic memory
262 * allocation.
263 *
264 * xTaskCreate() can only be used to create a task that has unrestricted
265 * access to the entire microcontroller memory map. Systems that include MPU
266 * support can alternatively create an MPU constrained task using
267 * xTaskCreateRestricted().
268 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800269 * @param pvTaskCode Pointer to the task entry function. Tasks
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800270 * must be implemented to never return (i.e. continuous loop).
271 *
272 * @param pcName A descriptive name for the task. This is mainly used to
273 * facilitate debugging. Max length defined by configMAX_TASK_NAME_LEN - default
274 * is 16.
275 *
276 * @param usStackDepth The size of the task stack specified as the number of
277 * variables the stack can hold - not the number of bytes. For example, if
278 * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
279 * will be allocated for stack storage.
280 *
281 * @param pvParameters Pointer that will be used as the parameter for the task
282 * being created.
283 *
284 * @param uxPriority The priority at which the task should run. Systems that
285 * include MPU support can optionally create tasks in a privileged (system)
286 * mode by setting bit portPRIVILEGE_BIT of the priority parameter. For
287 * example, to create a privileged task at priority 2 the uxPriority parameter
288 * should be set to ( 2 | portPRIVILEGE_BIT ).
289 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800290 * @param pvCreatedTask Used to pass back a handle by which the created task
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800291 * can be referenced.
292 *
293 * @return pdPASS if the task was successfully created and added to a ready
294 * list, otherwise an error code defined in the file projdefs.h
295 *
296 * Example usage:
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800297 <pre>
298 // Task to be created.
299 void vTaskCode( void * pvParameters )
300 {
301 for( ;; )
302 {
303 // Task code goes here.
304 }
305 }
306
307 // Function that creates a task.
308 void vOtherFunction( void )
309 {
310 static uint8_t ucParameterToPass;
311 TaskHandle_t xHandle = NULL;
312
313 // Create the task, storing the handle. Note that the passed parameter ucParameterToPass
314 // must exist for the lifetime of the task, so in this case is declared static. If it was just an
315 // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
316 // the new task attempts to access it.
317 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
318 configASSERT( xHandle );
319
320 // Use the handle to delete the task.
321 if( xHandle != NULL )
322 {
323 vTaskDelete( xHandle );
324 }
325 }
326 </pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800327 * \defgroup xTaskCreate xTaskCreate
328 * \ingroup Tasks
329 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800330#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
331 BaseType_t xTaskCreate( TaskFunction_t pxTaskCode,
332 const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
333 const configSTACK_DEPTH_TYPE usStackDepth,
334 void * const pvParameters,
335 UBaseType_t uxPriority,
336 TaskHandle_t * const pxCreatedTask ) PRIVILEGED_FUNCTION;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800337#endif
338
339/**
340 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800341 *<pre>
342 TaskHandle_t xTaskCreateStatic( TaskFunction_t pvTaskCode,
343 const char * const pcName,
344 uint32_t ulStackDepth,
345 void *pvParameters,
346 UBaseType_t uxPriority,
347 StackType_t *pxStackBuffer,
348 StaticTask_t *pxTaskBuffer );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800349 *
350 * Create a new task and add it to the list of tasks that are ready to run.
351 *
352 * Internally, within the FreeRTOS implementation, tasks use two blocks of
353 * memory. The first block is used to hold the task's data structures. The
354 * second block is used by the task as its stack. If a task is created using
355 * xTaskCreate() then both blocks of memory are automatically dynamically
356 * allocated inside the xTaskCreate() function. (see
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800357 * http://www.freertos.org/a00111.html). If a task is created using
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800358 * xTaskCreateStatic() then the application writer must provide the required
359 * memory. xTaskCreateStatic() therefore allows a task to be created without
360 * using any dynamic memory allocation.
361 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800362 * @param pvTaskCode Pointer to the task entry function. Tasks
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800363 * must be implemented to never return (i.e. continuous loop).
364 *
365 * @param pcName A descriptive name for the task. This is mainly used to
366 * facilitate debugging. The maximum length of the string is defined by
367 * configMAX_TASK_NAME_LEN in FreeRTOSConfig.h.
368 *
369 * @param ulStackDepth The size of the task stack specified as the number of
370 * variables the stack can hold - not the number of bytes. For example, if
371 * the stack is 32-bits wide and ulStackDepth is defined as 100 then 400 bytes
372 * will be allocated for stack storage.
373 *
374 * @param pvParameters Pointer that will be used as the parameter for the task
375 * being created.
376 *
377 * @param uxPriority The priority at which the task will run.
378 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800379 * @param pxStackBuffer Must point to a StackType_t array that has at least
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800380 * ulStackDepth indexes - the array will then be used as the task's stack,
381 * removing the need for the stack to be allocated dynamically.
382 *
383 * @param pxTaskBuffer Must point to a variable of type StaticTask_t, which will
384 * then be used to hold the task's data structures, removing the need for the
385 * memory to be allocated dynamically.
386 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800387 * @return If neither pxStackBuffer or pxTaskBuffer are NULL, then the task will
388 * be created and a handle to the created task is returned. If either
389 * pxStackBuffer or pxTaskBuffer are NULL then the task will not be created and
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800390 * NULL is returned.
391 *
392 * Example usage:
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800393 <pre>
394
395 // Dimensions the buffer that the task being created will use as its stack.
396 // NOTE: This is the number of words the stack will hold, not the number of
397 // bytes. For example, if each stack item is 32-bits, and this is set to 100,
398 // then 400 bytes (100 * 32-bits) will be allocated.
399 #define STACK_SIZE 200
400
401 // Structure that will hold the TCB of the task being created.
402 StaticTask_t xTaskBuffer;
403
404 // Buffer that the task being created will use as its stack. Note this is
405 // an array of StackType_t variables. The size of StackType_t is dependent on
406 // the RTOS port.
407 StackType_t xStack[ STACK_SIZE ];
408
409 // Function that implements the task being created.
410 void vTaskCode( void * pvParameters )
411 {
412 // The parameter value is expected to be 1 as 1 is passed in the
413 // pvParameters value in the call to xTaskCreateStatic().
414 configASSERT( ( uint32_t ) pvParameters == 1UL );
415
416 for( ;; )
417 {
418 // Task code goes here.
419 }
420 }
421
422 // Function that creates a task.
423 void vOtherFunction( void )
424 {
425 TaskHandle_t xHandle = NULL;
426
427 // Create the task without using any dynamic memory allocation.
428 xHandle = xTaskCreateStatic(
429 vTaskCode, // Function that implements the task.
430 "NAME", // Text name for the task.
431 STACK_SIZE, // Stack size in words, not bytes.
432 ( void * ) 1, // Parameter passed into the task.
433 tskIDLE_PRIORITY,// Priority at which the task is created.
434 xStack, // Array to use as the task's stack.
435 &xTaskBuffer ); // Variable to hold the task's data structure.
436
437 // puxStackBuffer and pxTaskBuffer were not NULL, so the task will have
438 // been created, and xHandle will be the task's handle. Use the handle
439 // to suspend the task.
440 vTaskSuspend( xHandle );
441 }
442 </pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800443 * \defgroup xTaskCreateStatic xTaskCreateStatic
444 * \ingroup Tasks
445 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800446#if( configSUPPORT_STATIC_ALLOCATION == 1 )
447 TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,
448 const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
449 const uint32_t ulStackDepth,
450 void * const pvParameters,
451 UBaseType_t uxPriority,
452 StackType_t * const puxStackBuffer,
453 StaticTask_t * const pxTaskBuffer ) PRIVILEGED_FUNCTION;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800454#endif /* configSUPPORT_STATIC_ALLOCATION */
455
456/**
457 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800458 *<pre>
459 BaseType_t xTaskCreateRestricted( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800460 *
461 * Only available when configSUPPORT_DYNAMIC_ALLOCATION is set to 1.
462 *
463 * xTaskCreateRestricted() should only be used in systems that include an MPU
464 * implementation.
465 *
466 * Create a new task and add it to the list of tasks that are ready to run.
467 * The function parameters define the memory regions and associated access
468 * permissions allocated to the task.
469 *
470 * See xTaskCreateRestrictedStatic() for a version that does not use any
471 * dynamic memory allocation.
472 *
473 * @param pxTaskDefinition Pointer to a structure that contains a member
474 * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API
475 * documentation) plus an optional stack buffer and the memory region
476 * definitions.
477 *
478 * @param pxCreatedTask Used to pass back a handle by which the created task
479 * can be referenced.
480 *
481 * @return pdPASS if the task was successfully created and added to a ready
482 * list, otherwise an error code defined in the file projdefs.h
483 *
484 * Example usage:
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800485 <pre>
486// Create an TaskParameters_t structure that defines the task to be created.
487static const TaskParameters_t xCheckTaskParameters =
488{
489 vATask, // pvTaskCode - the function that implements the task.
490 "ATask", // pcName - just a text name for the task to assist debugging.
491 100, // usStackDepth - the stack size DEFINED IN WORDS.
492 NULL, // pvParameters - passed into the task function as the function parameters.
493 ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
494 cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
495
496 // xRegions - Allocate up to three separate memory regions for access by
497 // the task, with appropriate access permissions. Different processors have
498 // different memory alignment requirements - refer to the FreeRTOS documentation
499 // for full information.
500 {
501 // Base address Length Parameters
502 { cReadWriteArray, 32, portMPU_REGION_READ_WRITE },
503 { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY },
504 { cPrivilegedOnlyAccessArray, 128, portMPU_REGION_PRIVILEGED_READ_WRITE }
505 }
506};
507
508int main( void )
509{
510TaskHandle_t xHandle;
511
512 // Create a task from the const structure defined above. The task handle
513 // is requested (the second parameter is not NULL) but in this case just for
514 // demonstration purposes as its not actually used.
515 xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
516
517 // Start the scheduler.
518 vTaskStartScheduler();
519
520 // Will only get here if there was insufficient memory to create the idle
521 // and/or timer task.
522 for( ;; );
523}
524 </pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800525 * \defgroup xTaskCreateRestricted xTaskCreateRestricted
526 * \ingroup Tasks
527 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800528#if( portUSING_MPU_WRAPPERS == 1 )
529 BaseType_t xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ) PRIVILEGED_FUNCTION;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800530#endif
531
532/**
533 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800534 *<pre>
535 BaseType_t xTaskCreateRestrictedStatic( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800536 *
537 * Only available when configSUPPORT_STATIC_ALLOCATION is set to 1.
538 *
539 * xTaskCreateRestrictedStatic() should only be used in systems that include an
540 * MPU implementation.
541 *
542 * Internally, within the FreeRTOS implementation, tasks use two blocks of
543 * memory. The first block is used to hold the task's data structures. The
544 * second block is used by the task as its stack. If a task is created using
545 * xTaskCreateRestricted() then the stack is provided by the application writer,
546 * and the memory used to hold the task's data structure is automatically
547 * dynamically allocated inside the xTaskCreateRestricted() function. If a task
548 * is created using xTaskCreateRestrictedStatic() then the application writer
549 * must provide the memory used to hold the task's data structures too.
550 * xTaskCreateRestrictedStatic() therefore allows a memory protected task to be
551 * created without using any dynamic memory allocation.
552 *
553 * @param pxTaskDefinition Pointer to a structure that contains a member
554 * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API
555 * documentation) plus an optional stack buffer and the memory region
556 * definitions. If configSUPPORT_STATIC_ALLOCATION is set to 1 the structure
557 * contains an additional member, which is used to point to a variable of type
558 * StaticTask_t - which is then used to hold the task's data structure.
559 *
560 * @param pxCreatedTask Used to pass back a handle by which the created task
561 * can be referenced.
562 *
563 * @return pdPASS if the task was successfully created and added to a ready
564 * list, otherwise an error code defined in the file projdefs.h
565 *
566 * Example usage:
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800567 <pre>
568// Create an TaskParameters_t structure that defines the task to be created.
569// The StaticTask_t variable is only included in the structure when
570// configSUPPORT_STATIC_ALLOCATION is set to 1. The PRIVILEGED_DATA macro can
571// be used to force the variable into the RTOS kernel's privileged data area.
572static PRIVILEGED_DATA StaticTask_t xTaskBuffer;
573static const TaskParameters_t xCheckTaskParameters =
574{
575 vATask, // pvTaskCode - the function that implements the task.
576 "ATask", // pcName - just a text name for the task to assist debugging.
577 100, // usStackDepth - the stack size DEFINED IN WORDS.
578 NULL, // pvParameters - passed into the task function as the function parameters.
579 ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
580 cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
581
582 // xRegions - Allocate up to three separate memory regions for access by
583 // the task, with appropriate access permissions. Different processors have
584 // different memory alignment requirements - refer to the FreeRTOS documentation
585 // for full information.
586 {
587 // Base address Length Parameters
588 { cReadWriteArray, 32, portMPU_REGION_READ_WRITE },
589 { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY },
590 { cPrivilegedOnlyAccessArray, 128, portMPU_REGION_PRIVILEGED_READ_WRITE }
591 }
592
593 &xTaskBuffer; // Holds the task's data structure.
594};
595
596int main( void )
597{
598TaskHandle_t xHandle;
599
600 // Create a task from the const structure defined above. The task handle
601 // is requested (the second parameter is not NULL) but in this case just for
602 // demonstration purposes as its not actually used.
603 xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
604
605 // Start the scheduler.
606 vTaskStartScheduler();
607
608 // Will only get here if there was insufficient memory to create the idle
609 // and/or timer task.
610 for( ;; );
611}
612 </pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800613 * \defgroup xTaskCreateRestrictedStatic xTaskCreateRestrictedStatic
614 * \ingroup Tasks
615 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800616#if( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
617 BaseType_t xTaskCreateRestrictedStatic( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ) PRIVILEGED_FUNCTION;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800618#endif
619
620/**
621 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800622 *<pre>
623 void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800624 *
625 * Memory regions are assigned to a restricted task when the task is created by
626 * a call to xTaskCreateRestricted(). These regions can be redefined using
627 * vTaskAllocateMPURegions().
628 *
629 * @param xTask The handle of the task being updated.
630 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800631 * @param xRegions A pointer to an MemoryRegion_t structure that contains the
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800632 * new memory region definitions.
633 *
634 * Example usage:
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800635 <pre>
636// Define an array of MemoryRegion_t structures that configures an MPU region
637// allowing read/write access for 1024 bytes starting at the beginning of the
638// ucOneKByte array. The other two of the maximum 3 definable regions are
639// unused so set to zero.
640static const MemoryRegion_t xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] =
641{
642 // Base address Length Parameters
643 { ucOneKByte, 1024, portMPU_REGION_READ_WRITE },
644 { 0, 0, 0 },
645 { 0, 0, 0 }
646};
647
648void vATask( void *pvParameters )
649{
650 // This task was created such that it has access to certain regions of
651 // memory as defined by the MPU configuration. At some point it is
652 // desired that these MPU regions are replaced with that defined in the
653 // xAltRegions const struct above. Use a call to vTaskAllocateMPURegions()
654 // for this purpose. NULL is used as the task handle to indicate that this
655 // function should modify the MPU regions of the calling task.
656 vTaskAllocateMPURegions( NULL, xAltRegions );
657
658 // Now the task can continue its function, but from this point on can only
659 // access its stack and the ucOneKByte array (unless any other statically
660 // defined or shared regions have been declared elsewhere).
661}
662 </pre>
663 * \defgroup xTaskCreateRestricted xTaskCreateRestricted
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800664 * \ingroup Tasks
665 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800666void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions ) PRIVILEGED_FUNCTION;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800667
668/**
669 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800670 * <pre>void vTaskDelete( TaskHandle_t xTask );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800671 *
672 * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.
673 * See the configuration section for more information.
674 *
675 * Remove a task from the RTOS real time kernel's management. The task being
676 * deleted will be removed from all ready, blocked, suspended and event lists.
677 *
678 * NOTE: The idle task is responsible for freeing the kernel allocated
679 * memory from tasks that have been deleted. It is therefore important that
680 * the idle task is not starved of microcontroller processing time if your
681 * application makes any calls to vTaskDelete (). Memory allocated by the
682 * task code is not automatically freed, and should be freed before the task
683 * is deleted.
684 *
685 * See the demo application file death.c for sample code that utilises
686 * vTaskDelete ().
687 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800688 * @param xTask The handle of the task to be deleted. Passing NULL will
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800689 * cause the calling task to be deleted.
690 *
691 * Example usage:
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800692 <pre>
693 void vOtherFunction( void )
694 {
695 TaskHandle_t xHandle;
696
697 // Create the task, storing the handle.
698 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
699
700 // Use the handle to delete the task.
701 vTaskDelete( xHandle );
702 }
703 </pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800704 * \defgroup vTaskDelete vTaskDelete
705 * \ingroup Tasks
706 */
707void vTaskDelete( TaskHandle_t xTaskToDelete ) PRIVILEGED_FUNCTION;
708
709/*-----------------------------------------------------------
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800710 * TASK CONTROL API
711 *----------------------------------------------------------*/
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800712
713/**
714 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800715 * <pre>void vTaskDelay( const TickType_t xTicksToDelay );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800716 *
717 * Delay a task for a given number of ticks. The actual time that the
718 * task remains blocked depends on the tick rate. The constant
719 * portTICK_PERIOD_MS can be used to calculate real time from the tick
720 * rate - with the resolution of one tick period.
721 *
722 * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
723 * See the configuration section for more information.
724 *
725 *
726 * vTaskDelay() specifies a time at which the task wishes to unblock relative to
727 * the time at which vTaskDelay() is called. For example, specifying a block
728 * period of 100 ticks will cause the task to unblock 100 ticks after
729 * vTaskDelay() is called. vTaskDelay() does not therefore provide a good method
730 * of controlling the frequency of a periodic task as the path taken through the
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800731 * code, as well as other task and interrupt activity, will effect the frequency
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800732 * at which vTaskDelay() gets called and therefore the time at which the task
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800733 * next executes. See vTaskDelayUntil() for an alternative API function designed
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800734 * to facilitate fixed frequency execution. It does this by specifying an
735 * absolute time (rather than a relative time) at which the calling task should
736 * unblock.
737 *
738 * @param xTicksToDelay The amount of time, in tick periods, that
739 * the calling task should block.
740 *
741 * Example usage:
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800742
743 void vTaskFunction( void * pvParameters )
744 {
745 // Block for 500ms.
746 const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
747
748 for( ;; )
749 {
750 // Simply toggle the LED every 500ms, blocking between each toggle.
751 vToggleLED();
752 vTaskDelay( xDelay );
753 }
754 }
755
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800756 * \defgroup vTaskDelay vTaskDelay
757 * \ingroup TaskCtrl
758 */
759void vTaskDelay( const TickType_t xTicksToDelay ) PRIVILEGED_FUNCTION;
760
761/**
762 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800763 * <pre>void vTaskDelayUntil( TickType_t *pxPreviousWakeTime, const TickType_t xTimeIncrement );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800764 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800765 * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800766 * See the configuration section for more information.
767 *
768 * Delay a task until a specified time. This function can be used by periodic
769 * tasks to ensure a constant execution frequency.
770 *
771 * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will
772 * cause a task to block for the specified number of ticks from the time vTaskDelay () is
773 * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed
774 * execution frequency as the time between a task starting to execute and that task
775 * calling vTaskDelay () may not be fixed [the task may take a different path though the
776 * code between calls, or may get interrupted or preempted a different number of times
777 * each time it executes].
778 *
779 * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800780 * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800781 * unblock.
782 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800783 * The constant portTICK_PERIOD_MS can be used to calculate real time from the tick
784 * rate - with the resolution of one tick period.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800785 *
786 * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
787 * task was last unblocked. The variable must be initialised with the current time
788 * prior to its first use (see the example below). Following this the variable is
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800789 * automatically updated within vTaskDelayUntil ().
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800790 *
791 * @param xTimeIncrement The cycle time period. The task will be unblocked at
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800792 * time *pxPreviousWakeTime + xTimeIncrement. Calling vTaskDelayUntil with the
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800793 * same xTimeIncrement parameter value will cause the task to execute with
794 * a fixed interface period.
795 *
796 * Example usage:
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800797 <pre>
798 // Perform an action every 10 ticks.
799 void vTaskFunction( void * pvParameters )
800 {
801 TickType_t xLastWakeTime;
802 const TickType_t xFrequency = 10;
803
804 // Initialise the xLastWakeTime variable with the current time.
805 xLastWakeTime = xTaskGetTickCount ();
806 for( ;; )
807 {
808 // Wait for the next cycle.
809 vTaskDelayUntil( &xLastWakeTime, xFrequency );
810
811 // Perform action here.
812 }
813 }
814 </pre>
815 * \defgroup vTaskDelayUntil vTaskDelayUntil
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800816 * \ingroup TaskCtrl
817 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800818void vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, const TickType_t xTimeIncrement ) PRIVILEGED_FUNCTION;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800819
820/**
821 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800822 * <pre>BaseType_t xTaskAbortDelay( TaskHandle_t xTask );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800823 *
824 * INCLUDE_xTaskAbortDelay must be defined as 1 in FreeRTOSConfig.h for this
825 * function to be available.
826 *
827 * A task will enter the Blocked state when it is waiting for an event. The
828 * event it is waiting for can be a temporal event (waiting for a time), such
829 * as when vTaskDelay() is called, or an event on an object, such as when
830 * xQueueReceive() or ulTaskNotifyTake() is called. If the handle of a task
831 * that is in the Blocked state is used in a call to xTaskAbortDelay() then the
832 * task will leave the Blocked state, and return from whichever function call
833 * placed the task into the Blocked state.
834 *
835 * @param xTask The handle of the task to remove from the Blocked state.
836 *
837 * @return If the task referenced by xTask was not in the Blocked state then
838 * pdFAIL is returned. Otherwise pdPASS is returned.
839 *
840 * \defgroup xTaskAbortDelay xTaskAbortDelay
841 * \ingroup TaskCtrl
842 */
843BaseType_t xTaskAbortDelay( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
844
845/**
846 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800847 * <pre>UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800848 *
849 * INCLUDE_uxTaskPriorityGet must be defined as 1 for this function to be available.
850 * See the configuration section for more information.
851 *
852 * Obtain the priority of any task.
853 *
854 * @param xTask Handle of the task to be queried. Passing a NULL
855 * handle results in the priority of the calling task being returned.
856 *
857 * @return The priority of xTask.
858 *
859 * Example usage:
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800860 <pre>
861 void vAFunction( void )
862 {
863 TaskHandle_t xHandle;
864
865 // Create a task, storing the handle.
866 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
867
868 // ...
869
870 // Use the handle to obtain the priority of the created task.
871 // It was created with tskIDLE_PRIORITY, but may have changed
872 // it itself.
873 if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
874 {
875 // The task has changed it's priority.
876 }
877
878 // ...
879
880 // Is our priority higher than the created task?
881 if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
882 {
883 // Our priority (obtained using NULL handle) is higher.
884 }
885 }
886 </pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800887 * \defgroup uxTaskPriorityGet uxTaskPriorityGet
888 * \ingroup TaskCtrl
889 */
890UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
891
892/**
893 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800894 * <pre>UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800895 *
896 * A version of uxTaskPriorityGet() that can be used from an ISR.
897 */
898UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
899
900/**
901 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800902 * <pre>eTaskState eTaskGetState( TaskHandle_t xTask );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800903 *
904 * INCLUDE_eTaskGetState must be defined as 1 for this function to be available.
905 * See the configuration section for more information.
906 *
907 * Obtain the state of any task. States are encoded by the eTaskState
908 * enumerated type.
909 *
910 * @param xTask Handle of the task to be queried.
911 *
912 * @return The state of xTask at the time the function was called. Note the
913 * state of the task might change between the function being called, and the
914 * functions return value being tested by the calling task.
915 */
916eTaskState eTaskGetState( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
917
918/**
919 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800920 * <pre>void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800921 *
922 * configUSE_TRACE_FACILITY must be defined as 1 for this function to be
923 * available. See the configuration section for more information.
924 *
925 * Populates a TaskStatus_t structure with information about a task.
926 *
927 * @param xTask Handle of the task being queried. If xTask is NULL then
928 * information will be returned about the calling task.
929 *
930 * @param pxTaskStatus A pointer to the TaskStatus_t structure that will be
931 * filled with information about the task referenced by the handle passed using
932 * the xTask parameter.
933 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800934 * @xGetFreeStackSpace The TaskStatus_t structure contains a member to report
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800935 * the stack high water mark of the task being queried. Calculating the stack
936 * high water mark takes a relatively long time, and can make the system
937 * temporarily unresponsive - so the xGetFreeStackSpace parameter is provided to
938 * allow the high water mark checking to be skipped. The high watermark value
939 * will only be written to the TaskStatus_t structure if xGetFreeStackSpace is
940 * not set to pdFALSE;
941 *
942 * @param eState The TaskStatus_t structure contains a member to report the
943 * state of the task being queried. Obtaining the task state is not as fast as
944 * a simple assignment - so the eState parameter is provided to allow the state
945 * information to be omitted from the TaskStatus_t structure. To obtain state
946 * information then set eState to eInvalid - otherwise the value passed in
947 * eState will be reported as the task state in the TaskStatus_t structure.
948 *
949 * Example usage:
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800950 <pre>
951 void vAFunction( void )
952 {
953 TaskHandle_t xHandle;
954 TaskStatus_t xTaskDetails;
955
956 // Obtain the handle of a task from its name.
957 xHandle = xTaskGetHandle( "Task_Name" );
958
959 // Check the handle is not NULL.
960 configASSERT( xHandle );
961
962 // Use the handle to obtain further information about the task.
963 vTaskGetInfo( xHandle,
964 &xTaskDetails,
965 pdTRUE, // Include the high water mark in xTaskDetails.
966 eInvalid ); // Include the task state in xTaskDetails.
967 }
968 </pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800969 * \defgroup vTaskGetInfo vTaskGetInfo
970 * \ingroup TaskCtrl
971 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800972void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState ) PRIVILEGED_FUNCTION;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800973
974/**
975 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800976 * <pre>void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +0800977 *
978 * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
979 * See the configuration section for more information.
980 *
981 * Set the priority of any task.
982 *
983 * A context switch will occur before the function returns if the priority
984 * being set is higher than the currently executing task.
985 *
986 * @param xTask Handle to the task for which the priority is being set.
987 * Passing a NULL handle results in the priority of the calling task being set.
988 *
989 * @param uxNewPriority The priority to which the task will be set.
990 *
991 * Example usage:
xiaohu.huang4f321fb2024-03-22 14:50:29 +0800992 <pre>
993 void vAFunction( void )
994 {
995 TaskHandle_t xHandle;
996
997 // Create a task, storing the handle.
998 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
999
1000 // ...
1001
1002 // Use the handle to raise the priority of the created task.
1003 vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
1004
1005 // ...
1006
1007 // Use a NULL handle to raise our priority to the same value.
1008 vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
1009 }
1010 </pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001011 * \defgroup vTaskPrioritySet vTaskPrioritySet
1012 * \ingroup TaskCtrl
1013 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001014void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority ) PRIVILEGED_FUNCTION;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001015
1016/**
1017 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001018 * <pre>void vTaskSuspend( TaskHandle_t xTaskToSuspend );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001019 *
1020 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
1021 * See the configuration section for more information.
1022 *
1023 * Suspend any task. When suspended a task will never get any microcontroller
1024 * processing time, no matter what its priority.
1025 *
1026 * Calls to vTaskSuspend are not accumulative -
1027 * i.e. calling vTaskSuspend () twice on the same task still only requires one
1028 * call to vTaskResume () to ready the suspended task.
1029 *
1030 * @param xTaskToSuspend Handle to the task being suspended. Passing a NULL
1031 * handle will cause the calling task to be suspended.
1032 *
1033 * Example usage:
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001034 <pre>
1035 void vAFunction( void )
1036 {
1037 TaskHandle_t xHandle;
1038
1039 // Create a task, storing the handle.
1040 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
1041
1042 // ...
1043
1044 // Use the handle to suspend the created task.
1045 vTaskSuspend( xHandle );
1046
1047 // ...
1048
1049 // The created task will not run during this period, unless
1050 // another task calls vTaskResume( xHandle ).
1051
1052 //...
1053
1054
1055 // Suspend ourselves.
1056 vTaskSuspend( NULL );
1057
1058 // We cannot get here unless another task calls vTaskResume
1059 // with our handle as the parameter.
1060 }
1061 </pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001062 * \defgroup vTaskSuspend vTaskSuspend
1063 * \ingroup TaskCtrl
1064 */
1065void vTaskSuspend( TaskHandle_t xTaskToSuspend ) PRIVILEGED_FUNCTION;
1066
1067/**
1068 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001069 * <pre>void vTaskResume( TaskHandle_t xTaskToResume );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001070 *
1071 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
1072 * See the configuration section for more information.
1073 *
1074 * Resumes a suspended task.
1075 *
1076 * A task that has been suspended by one or more calls to vTaskSuspend ()
1077 * will be made available for running again by a single call to
1078 * vTaskResume ().
1079 *
1080 * @param xTaskToResume Handle to the task being readied.
1081 *
1082 * Example usage:
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001083 <pre>
1084 void vAFunction( void )
1085 {
1086 TaskHandle_t xHandle;
1087
1088 // Create a task, storing the handle.
1089 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
1090
1091 // ...
1092
1093 // Use the handle to suspend the created task.
1094 vTaskSuspend( xHandle );
1095
1096 // ...
1097
1098 // The created task will not run during this period, unless
1099 // another task calls vTaskResume( xHandle ).
1100
1101 //...
1102
1103
1104 // Resume the suspended task ourselves.
1105 vTaskResume( xHandle );
1106
1107 // The created task will once again get microcontroller processing
1108 // time in accordance with its priority within the system.
1109 }
1110 </pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001111 * \defgroup vTaskResume vTaskResume
1112 * \ingroup TaskCtrl
1113 */
1114void vTaskResume( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
1115
1116/**
1117 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001118 * <pre>void xTaskResumeFromISR( TaskHandle_t xTaskToResume );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001119 *
1120 * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
1121 * available. See the configuration section for more information.
1122 *
1123 * An implementation of vTaskResume() that can be called from within an ISR.
1124 *
1125 * A task that has been suspended by one or more calls to vTaskSuspend ()
1126 * will be made available for running again by a single call to
1127 * xTaskResumeFromISR ().
1128 *
1129 * xTaskResumeFromISR() should not be used to synchronise a task with an
1130 * interrupt if there is a chance that the interrupt could arrive prior to the
1131 * task being suspended - as this can lead to interrupts being missed. Use of a
1132 * semaphore as a synchronisation mechanism would avoid this eventuality.
1133 *
1134 * @param xTaskToResume Handle to the task being readied.
1135 *
1136 * @return pdTRUE if resuming the task should result in a context switch,
1137 * otherwise pdFALSE. This is used by the ISR to determine if a context switch
1138 * may be required following the ISR.
1139 *
1140 * \defgroup vTaskResumeFromISR vTaskResumeFromISR
1141 * \ingroup TaskCtrl
1142 */
1143BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
1144
1145/*-----------------------------------------------------------
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001146 * SCHEDULER CONTROL
1147 *----------------------------------------------------------*/
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001148
1149/**
1150 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001151 * <pre>void vTaskStartScheduler( void );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001152 *
1153 * Starts the real time kernel tick processing. After calling the kernel
1154 * has control over which tasks are executed and when.
1155 *
1156 * See the demo application file main.c for an example of creating
1157 * tasks and starting the kernel.
1158 *
1159 * Example usage:
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001160 <pre>
1161 void vAFunction( void )
1162 {
1163 // Create at least one task before starting the kernel.
1164 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
1165
1166 // Start the real time kernel with preemption.
1167 vTaskStartScheduler ();
1168
1169 // Will not get here unless a task calls vTaskEndScheduler ()
1170 }
1171 </pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001172 *
1173 * \defgroup vTaskStartScheduler vTaskStartScheduler
1174 * \ingroup SchedulerControl
1175 */
1176void vTaskStartScheduler( void ) PRIVILEGED_FUNCTION;
1177
1178/**
1179 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001180 * <pre>void vTaskEndScheduler( void );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001181 *
1182 * NOTE: At the time of writing only the x86 real mode port, which runs on a PC
1183 * in place of DOS, implements this function.
1184 *
1185 * Stops the real time kernel tick. All created tasks will be automatically
1186 * deleted and multitasking (either preemptive or cooperative) will
1187 * stop. Execution then resumes from the point where vTaskStartScheduler ()
1188 * was called, as if vTaskStartScheduler () had just returned.
1189 *
1190 * See the demo application file main. c in the demo/PC directory for an
1191 * example that uses vTaskEndScheduler ().
1192 *
1193 * vTaskEndScheduler () requires an exit function to be defined within the
1194 * portable layer (see vPortEndScheduler () in port. c for the PC port). This
1195 * performs hardware specific operations such as stopping the kernel tick.
1196 *
1197 * vTaskEndScheduler () will cause all of the resources allocated by the
1198 * kernel to be freed - but will not free resources allocated by application
1199 * tasks.
1200 *
1201 * Example usage:
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001202 <pre>
1203 void vTaskCode( void * pvParameters )
1204 {
1205 for( ;; )
1206 {
1207 // Task code goes here.
1208
1209 // At some point we want to end the real time kernel processing
1210 // so call ...
1211 vTaskEndScheduler ();
1212 }
1213 }
1214
1215 void vAFunction( void )
1216 {
1217 // Create at least one task before starting the kernel.
1218 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
1219
1220 // Start the real time kernel with preemption.
1221 vTaskStartScheduler ();
1222
1223 // Will only get here when the vTaskCode () task has called
1224 // vTaskEndScheduler (). When we get here we are back to single task
1225 // execution.
1226 }
1227 </pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001228 *
1229 * \defgroup vTaskEndScheduler vTaskEndScheduler
1230 * \ingroup SchedulerControl
1231 */
1232void vTaskEndScheduler( void ) PRIVILEGED_FUNCTION;
1233
1234/**
1235 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001236 * <pre>void vTaskSuspendAll( void );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001237 *
1238 * Suspends the scheduler without disabling interrupts. Context switches will
1239 * not occur while the scheduler is suspended.
1240 *
1241 * After calling vTaskSuspendAll () the calling task will continue to execute
1242 * without risk of being swapped out until a call to xTaskResumeAll () has been
1243 * made.
1244 *
1245 * API functions that have the potential to cause a context switch (for example,
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001246 * vTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001247 * is suspended.
1248 *
1249 * Example usage:
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001250 <pre>
1251 void vTask1( void * pvParameters )
1252 {
1253 for( ;; )
1254 {
1255 // Task code goes here.
1256
1257 // ...
1258
1259 // At some point the task wants to perform a long operation during
1260 // which it does not want to get swapped out. It cannot use
1261 // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
1262 // operation may cause interrupts to be missed - including the
1263 // ticks.
1264
1265 // Prevent the real time kernel swapping out the task.
1266 vTaskSuspendAll ();
1267
1268 // Perform the operation here. There is no need to use critical
1269 // sections as we have all the microcontroller processing time.
1270 // During this time interrupts will still operate and the kernel
1271 // tick count will be maintained.
1272
1273 // ...
1274
1275 // The operation is complete. Restart the kernel.
1276 xTaskResumeAll ();
1277 }
1278 }
1279 </pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001280 * \defgroup vTaskSuspendAll vTaskSuspendAll
1281 * \ingroup SchedulerControl
1282 */
1283void vTaskSuspendAll( void ) PRIVILEGED_FUNCTION;
1284
1285/**
1286 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001287 * <pre>BaseType_t xTaskResumeAll( void );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001288 *
1289 * Resumes scheduler activity after it was suspended by a call to
1290 * vTaskSuspendAll().
1291 *
1292 * xTaskResumeAll() only resumes the scheduler. It does not unsuspend tasks
1293 * that were previously suspended by a call to vTaskSuspend().
1294 *
1295 * @return If resuming the scheduler caused a context switch then pdTRUE is
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001296 * returned, otherwise pdFALSE is returned.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001297 *
1298 * Example usage:
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001299 <pre>
1300 void vTask1( void * pvParameters )
1301 {
1302 for( ;; )
1303 {
1304 // Task code goes here.
1305
1306 // ...
1307
1308 // At some point the task wants to perform a long operation during
1309 // which it does not want to get swapped out. It cannot use
1310 // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
1311 // operation may cause interrupts to be missed - including the
1312 // ticks.
1313
1314 // Prevent the real time kernel swapping out the task.
1315 vTaskSuspendAll ();
1316
1317 // Perform the operation here. There is no need to use critical
1318 // sections as we have all the microcontroller processing time.
1319 // During this time interrupts will still operate and the real
1320 // time kernel tick count will be maintained.
1321
1322 // ...
1323
1324 // The operation is complete. Restart the kernel. We want to force
1325 // a context switch - but there is no point if resuming the scheduler
1326 // caused a context switch already.
1327 if( !xTaskResumeAll () )
1328 {
1329 taskYIELD ();
1330 }
1331 }
1332 }
1333 </pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001334 * \defgroup xTaskResumeAll xTaskResumeAll
1335 * \ingroup SchedulerControl
1336 */
1337BaseType_t xTaskResumeAll( void ) PRIVILEGED_FUNCTION;
1338
1339/*-----------------------------------------------------------
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001340 * TASK UTILITIES
1341 *----------------------------------------------------------*/
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001342
1343/**
1344 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001345 * <PRE>TickType_t xTaskGetTickCount( void );</PRE>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001346 *
1347 * @return The count of ticks since vTaskStartScheduler was called.
1348 *
1349 * \defgroup xTaskGetTickCount xTaskGetTickCount
1350 * \ingroup TaskUtils
1351 */
1352TickType_t xTaskGetTickCount( void ) PRIVILEGED_FUNCTION;
1353
1354/**
1355 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001356 * <PRE>TickType_t xTaskGetTickCountFromISR( void );</PRE>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001357 *
1358 * @return The count of ticks since vTaskStartScheduler was called.
1359 *
1360 * This is a version of xTaskGetTickCount() that is safe to be called from an
1361 * ISR - provided that TickType_t is the natural word size of the
1362 * microcontroller being used or interrupt nesting is either not supported or
1363 * not being used.
1364 *
1365 * \defgroup xTaskGetTickCountFromISR xTaskGetTickCountFromISR
1366 * \ingroup TaskUtils
1367 */
1368TickType_t xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION;
1369
1370/**
1371 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001372 * <PRE>uint16_t uxTaskGetNumberOfTasks( void );</PRE>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001373 *
1374 * @return The number of tasks that the real time kernel is currently managing.
1375 * This includes all ready, blocked and suspended tasks. A task that
1376 * has been deleted but not yet freed by the idle task will also be
1377 * included in the count.
1378 *
1379 * \defgroup uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
1380 * \ingroup TaskUtils
1381 */
1382UBaseType_t uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION;
1383
1384/**
1385 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001386 * <PRE>char *pcTaskGetName( TaskHandle_t xTaskToQuery );</PRE>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001387 *
1388 * @return The text (human readable) name of the task referenced by the handle
1389 * xTaskToQuery. A task can query its own name by either passing in its own
1390 * handle, or by setting xTaskToQuery to NULL.
1391 *
1392 * \defgroup pcTaskGetName pcTaskGetName
1393 * \ingroup TaskUtils
1394 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001395char *pcTaskGetName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001396
1397/**
1398 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001399 * <PRE>TaskHandle_t xTaskGetHandle( const char *pcNameToQuery );</PRE>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001400 *
1401 * NOTE: This function takes a relatively long time to complete and should be
1402 * used sparingly.
1403 *
1404 * @return The handle of the task that has the human readable name pcNameToQuery.
1405 * NULL is returned if no matching name is found. INCLUDE_xTaskGetHandle
1406 * must be set to 1 in FreeRTOSConfig.h for pcTaskGetHandle() to be available.
1407 *
1408 * \defgroup pcTaskGetHandle pcTaskGetHandle
1409 * \ingroup TaskUtils
1410 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001411TaskHandle_t xTaskGetHandle( const char *pcNameToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001412
1413/**
1414 * task.h
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001415 * <PRE>UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask );</PRE>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001416 *
1417 * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
1418 * this function to be available.
1419 *
1420 * Returns the high water mark of the stack associated with xTask. That is,
1421 * the minimum free stack space there has been (in words, so on a 32 bit machine
1422 * a value of 1 means 4 bytes) since the task started. The smaller the returned
1423 * number the closer the task has come to overflowing its stack.
1424 *
1425 * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
1426 * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
1427 * user to determine the return type. It gets around the problem of the value
1428 * overflowing on 8-bit types without breaking backward compatibility for
1429 * applications that expect an 8-bit return type.
1430 *
1431 * @param xTask Handle of the task associated with the stack to be checked.
1432 * Set xTask to NULL to check the stack of the calling task.
1433 *
1434 * @return The smallest amount of free stack space there has been (in words, so
1435 * actual spaces on the stack rather than bytes) since the task referenced by
1436 * xTask was created.
1437 */
1438UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1439
1440/**
1441 * task.h
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001442 * <PRE>configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask );</PRE>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001443 *
1444 * INCLUDE_uxTaskGetStackHighWaterMark2 must be set to 1 in FreeRTOSConfig.h for
1445 * this function to be available.
1446 *
1447 * Returns the high water mark of the stack associated with xTask. That is,
1448 * the minimum free stack space there has been (in words, so on a 32 bit machine
1449 * a value of 1 means 4 bytes) since the task started. The smaller the returned
1450 * number the closer the task has come to overflowing its stack.
1451 *
1452 * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
1453 * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
1454 * user to determine the return type. It gets around the problem of the value
1455 * overflowing on 8-bit types without breaking backward compatibility for
1456 * applications that expect an 8-bit return type.
1457 *
1458 * @param xTask Handle of the task associated with the stack to be checked.
1459 * Set xTask to NULL to check the stack of the calling task.
1460 *
1461 * @return The smallest amount of free stack space there has been (in words, so
1462 * actual spaces on the stack rather than bytes) since the task referenced by
1463 * xTask was created.
1464 */
1465configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1466
1467/* When using trace macros it is sometimes necessary to include task.h before
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001468FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined,
1469so the following two prototypes will cause a compilation error. This can be
1470fixed by simply guarding against the inclusion of these two prototypes unless
1471they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration
1472constant. */
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001473#ifdef configUSE_APPLICATION_TASK_TAG
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001474 #if configUSE_APPLICATION_TASK_TAG == 1
1475 /**
1476 * task.h
1477 * <pre>void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction );</pre>
1478 *
1479 * Sets pxHookFunction to be the task hook function used by the task xTask.
1480 * Passing xTask as NULL has the effect of setting the calling tasks hook
1481 * function.
1482 */
1483 void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction ) PRIVILEGED_FUNCTION;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001484
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001485 /**
1486 * task.h
1487 * <pre>void xTaskGetApplicationTaskTag( TaskHandle_t xTask );</pre>
1488 *
1489 * Returns the pxHookFunction value assigned to the task xTask. Do not
1490 * call from an interrupt service routine - call
1491 * xTaskGetApplicationTaskTagFromISR() instead.
1492 */
1493 TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001494
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001495 /**
1496 * task.h
1497 * <pre>void xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask );</pre>
1498 *
1499 * Returns the pxHookFunction value assigned to the task xTask. Can
1500 * be called from an interrupt service routine.
1501 */
1502 TaskHookFunction_t xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1503 #endif /* configUSE_APPLICATION_TASK_TAG ==1 */
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001504#endif /* ifdef configUSE_APPLICATION_TASK_TAG */
1505
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001506#if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001507
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001508 /* Each task contains an array of pointers that is dimensioned by the
1509 configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h. The
1510 kernel does not use the pointers itself, so the application writer can use
1511 the pointers for any purpose they wish. The following two functions are
1512 used to set and query a pointer respectively. */
1513 void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue ) PRIVILEGED_FUNCTION;
1514 void *pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, BaseType_t xIndex ) PRIVILEGED_FUNCTION;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001515
1516#endif
1517
1518/**
1519 * task.h
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001520 * <pre>BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001521 *
1522 * Calls the hook function associated with xTask. Passing xTask as NULL has
1523 * the effect of calling the Running tasks (the calling task) hook function.
1524 *
1525 * pvParameter is passed to the hook function for the task to interpret as it
1526 * wants. The return value is the value returned by the task hook function
1527 * registered by the user.
1528 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001529BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter ) PRIVILEGED_FUNCTION;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001530
1531/**
1532 * xTaskGetIdleTaskHandle() is only available if
1533 * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.
1534 *
1535 * Simply returns the handle of the idle task. It is not valid to call
1536 * xTaskGetIdleTaskHandle() before the scheduler has been started.
1537 */
1538TaskHandle_t xTaskGetIdleTaskHandle( void ) PRIVILEGED_FUNCTION;
1539
1540/**
1541 * configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for
1542 * uxTaskGetSystemState() to be available.
1543 *
1544 * uxTaskGetSystemState() populates an TaskStatus_t structure for each task in
1545 * the system. TaskStatus_t structures contain, among other things, members
1546 * for the task handle, task name, task priority, task state, and total amount
1547 * of run time consumed by the task. See the TaskStatus_t structure
1548 * definition in this file for the full member list.
1549 *
1550 * NOTE: This function is intended for debugging use only as its use results in
1551 * the scheduler remaining suspended for an extended period.
1552 *
1553 * @param pxTaskStatusArray A pointer to an array of TaskStatus_t structures.
1554 * The array must contain at least one TaskStatus_t structure for each task
1555 * that is under the control of the RTOS. The number of tasks under the control
1556 * of the RTOS can be determined using the uxTaskGetNumberOfTasks() API function.
1557 *
1558 * @param uxArraySize The size of the array pointed to by the pxTaskStatusArray
1559 * parameter. The size is specified as the number of indexes in the array, or
1560 * the number of TaskStatus_t structures contained in the array, not by the
1561 * number of bytes in the array.
1562 *
1563 * @param pulTotalRunTime If configGENERATE_RUN_TIME_STATS is set to 1 in
1564 * FreeRTOSConfig.h then *pulTotalRunTime is set by uxTaskGetSystemState() to the
1565 * total run time (as defined by the run time stats clock, see
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001566 * http://www.freertos.org/rtos-run-time-stats.html) since the target booted.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001567 * pulTotalRunTime can be set to NULL to omit the total run time information.
1568 *
1569 * @return The number of TaskStatus_t structures that were populated by
1570 * uxTaskGetSystemState(). This should equal the number returned by the
1571 * uxTaskGetNumberOfTasks() API function, but will be zero if the value passed
1572 * in the uxArraySize parameter was too small.
1573 *
1574 * Example usage:
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001575 <pre>
1576 // This example demonstrates how a human readable table of run time stats
1577 // information is generated from raw data provided by uxTaskGetSystemState().
1578 // The human readable table is written to pcWriteBuffer
1579 void vTaskGetRunTimeStats( char *pcWriteBuffer )
1580 {
1581 TaskStatus_t *pxTaskStatusArray;
1582 volatile UBaseType_t uxArraySize, x;
1583 uint32_t ulTotalRunTime, ulStatsAsPercentage;
1584
1585 // Make sure the write buffer does not contain a string.
1586 *pcWriteBuffer = 0x00;
1587
1588 // Take a snapshot of the number of tasks in case it changes while this
1589 // function is executing.
1590 uxArraySize = uxTaskGetNumberOfTasks();
1591
1592 // Allocate a TaskStatus_t structure for each task. An array could be
1593 // allocated statically at compile time.
1594 pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
1595
1596 if( pxTaskStatusArray != NULL )
1597 {
1598 // Generate raw status information about each task.
1599 uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );
1600
1601 // For percentage calculations.
1602 ulTotalRunTime /= 100UL;
1603
1604 // Avoid divide by zero errors.
1605 if( ulTotalRunTime > 0 )
1606 {
1607 // For each populated position in the pxTaskStatusArray array,
1608 // format the raw data as human readable ASCII data
1609 for( x = 0; x < uxArraySize; x++ )
1610 {
1611 // What percentage of the total run time has the task used?
1612 // This will always be rounded down to the nearest integer.
1613 // ulTotalRunTimeDiv100 has already been divided by 100.
1614 ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;
1615
1616 if( ulStatsAsPercentage > 0UL )
1617 {
1618 sprintf( pcWriteBuffer, "%s\t\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );
1619 }
1620 else
1621 {
1622 // If the percentage is zero here then the task has
1623 // consumed less than 1% of the total run time.
1624 sprintf( pcWriteBuffer, "%s\t\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter );
1625 }
1626
1627 pcWriteBuffer += strlen( ( char * ) pcWriteBuffer );
1628 }
1629 }
1630
1631 // The array is no longer needed, free the memory it consumes.
1632 vPortFree( pxTaskStatusArray );
1633 }
1634 }
1635 </pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001636 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001637UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime ) PRIVILEGED_FUNCTION;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001638
1639/**
1640 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001641 * <PRE>void vTaskList( char *pcWriteBuffer );</PRE>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001642 *
1643 * configUSE_TRACE_FACILITY and configUSE_STATS_FORMATTING_FUNCTIONS must
1644 * both be defined as 1 for this function to be available. See the
1645 * configuration section of the FreeRTOS.org website for more information.
1646 *
1647 * NOTE 1: This function will disable interrupts for its duration. It is
1648 * not intended for normal application runtime use but as a debug aid.
1649 *
1650 * Lists all the current tasks, along with their current state and stack
1651 * usage high water mark.
1652 *
1653 * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or
1654 * suspended ('S').
1655 *
1656 * PLEASE NOTE:
1657 *
1658 * This function is provided for convenience only, and is used by many of the
1659 * demo applications. Do not consider it to be part of the scheduler.
1660 *
1661 * vTaskList() calls uxTaskGetSystemState(), then formats part of the
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001662 * uxTaskGetSystemState() output into a human readable table that displays task
1663 * names, states and stack usage.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001664 *
1665 * vTaskList() has a dependency on the sprintf() C library function that might
1666 * bloat the code size, use a lot of stack, and provide different results on
1667 * different platforms. An alternative, tiny, third party, and limited
1668 * functionality implementation of sprintf() is provided in many of the
1669 * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
1670 * printf-stdarg.c does not provide a full snprintf() implementation!).
1671 *
1672 * It is recommended that production systems call uxTaskGetSystemState()
1673 * directly to get access to raw stats data, rather than indirectly through a
1674 * call to vTaskList().
1675 *
1676 * @param pcWriteBuffer A buffer into which the above mentioned details
1677 * will be written, in ASCII form. This buffer is assumed to be large
1678 * enough to contain the generated report. Approximately 40 bytes per
1679 * task should be sufficient.
1680 *
1681 * \defgroup vTaskList vTaskList
1682 * \ingroup TaskUtils
1683 */
1684void vTaskList( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1685
1686/**
1687 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001688 * <PRE>void vTaskGetRunTimeStats( char *pcWriteBuffer );</PRE>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001689 *
1690 * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS
1691 * must both be defined as 1 for this function to be available. The application
1692 * must also then provide definitions for
1693 * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()
1694 * to configure a peripheral timer/counter and return the timers current count
1695 * value respectively. The counter should be at least 10 times the frequency of
1696 * the tick count.
1697 *
1698 * NOTE 1: This function will disable interrupts for its duration. It is
1699 * not intended for normal application runtime use but as a debug aid.
1700 *
1701 * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
1702 * accumulated execution time being stored for each task. The resolution
1703 * of the accumulated time value depends on the frequency of the timer
1704 * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
1705 * Calling vTaskGetRunTimeStats() writes the total execution time of each
1706 * task into a buffer, both as an absolute count value and as a percentage
1707 * of the total system execution time.
1708 *
1709 * NOTE 2:
1710 *
1711 * This function is provided for convenience only, and is used by many of the
1712 * demo applications. Do not consider it to be part of the scheduler.
1713 *
1714 * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part of the
1715 * uxTaskGetSystemState() output into a human readable table that displays the
1716 * amount of time each task has spent in the Running state in both absolute and
1717 * percentage terms.
1718 *
1719 * vTaskGetRunTimeStats() has a dependency on the sprintf() C library function
1720 * that might bloat the code size, use a lot of stack, and provide different
1721 * results on different platforms. An alternative, tiny, third party, and
1722 * limited functionality implementation of sprintf() is provided in many of the
1723 * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
1724 * printf-stdarg.c does not provide a full snprintf() implementation!).
1725 *
1726 * It is recommended that production systems call uxTaskGetSystemState() directly
1727 * to get access to raw stats data, rather than indirectly through a call to
1728 * vTaskGetRunTimeStats().
1729 *
1730 * @param pcWriteBuffer A buffer into which the execution times will be
1731 * written, in ASCII form. This buffer is assumed to be large enough to
1732 * contain the generated report. Approximately 40 bytes per task should
1733 * be sufficient.
1734 *
1735 * \defgroup vTaskGetRunTimeStats vTaskGetRunTimeStats
1736 * \ingroup TaskUtils
1737 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001738void vTaskGetRunTimeStats( char *pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1739
1740/**
1741* task. h
1742* <PRE>TickType_t xTaskGetIdleRunTimeCounter( void );</PRE>
1743*
1744* configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS
1745* must both be defined as 1 for this function to be available. The application
1746* must also then provide definitions for
1747* portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()
1748* to configure a peripheral timer/counter and return the timers current count
1749* value respectively. The counter should be at least 10 times the frequency of
1750* the tick count.
1751*
1752* Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
1753* accumulated execution time being stored for each task. The resolution
1754* of the accumulated time value depends on the frequency of the timer
1755* configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
1756* While uxTaskGetSystemState() and vTaskGetRunTimeStats() writes the total
1757* execution time of each task into a buffer, xTaskGetIdleRunTimeCounter()
1758* returns the total execution time of just the idle task.
1759*
1760* @return The total run time of the idle task. This is the amount of time the
1761* idle task has actually been executing. The unit of time is dependent on the
1762* frequency configured using the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and
1763* portGET_RUN_TIME_COUNTER_VALUE() macros.
1764*
1765* \defgroup xTaskGetIdleRunTimeCounter xTaskGetIdleRunTimeCounter
1766* \ingroup TaskUtils
1767*/
1768TickType_t xTaskGetIdleRunTimeCounter( void ) PRIVILEGED_FUNCTION;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001769
1770/**
1771 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001772 * <PRE>BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction );</PRE>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001773 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001774 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
1775 * function to be available.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001776 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001777 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
1778 * "notification value", which is a 32-bit unsigned integer (uint32_t).
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001779 *
1780 * Events can be sent to a task using an intermediary object. Examples of such
1781 * objects are queues, semaphores, mutexes and event groups. Task notifications
1782 * are a method of sending an event directly to a task without the need for such
1783 * an intermediary object.
1784 *
1785 * A notification sent to a task can optionally perform an action, such as
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001786 * update, overwrite or increment the task's notification value. In that way
1787 * task notifications can be used to send data to a task, or be used as light
1788 * weight and fast binary or counting semaphores.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001789 *
xiaohu.huang58292b32024-01-03 14:09:51 +08001790 * A notification sent to a task will remain pending until it is cleared by the
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001791 * task calling xTaskNotifyWait() or ulTaskNotifyTake(). If the task was
1792 * already in the Blocked state to wait for a notification when the notification
1793 * arrives then the task will automatically be removed from the Blocked state
1794 * (unblocked) and the notification cleared.
xiaohu.huang58292b32024-01-03 14:09:51 +08001795 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001796 * A task can use xTaskNotifyWait() to [optionally] block to wait for a
1797 * notification to be pending, or ulTaskNotifyTake() to [optionally] block
1798 * to wait for its notification value to have a non-zero value. The task does
1799 * not consume any CPU time while it is in the Blocked state.
xiaohu.huang58292b32024-01-03 14:09:51 +08001800 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001801 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001802 *
1803 * @param xTaskToNotify The handle of the task being notified. The handle to a
1804 * task can be returned from the xTaskCreate() API function used to create the
1805 * task, and the handle of the currently running task can be obtained by calling
1806 * xTaskGetCurrentTaskHandle().
1807 *
1808 * @param ulValue Data that can be sent with the notification. How the data is
1809 * used depends on the value of the eAction parameter.
1810 *
1811 * @param eAction Specifies how the notification updates the task's notification
1812 * value, if at all. Valid values for eAction are as follows:
1813 *
1814 * eSetBits -
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001815 * The task's notification value is bitwise ORed with ulValue. xTaskNofify()
1816 * always returns pdPASS in this case.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001817 *
1818 * eIncrement -
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001819 * The task's notification value is incremented. ulValue is not used and
1820 * xTaskNotify() always returns pdPASS in this case.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001821 *
1822 * eSetValueWithOverwrite -
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001823 * The task's notification value is set to the value of ulValue, even if the
1824 * task being notified had not yet processed the previous notification (the
1825 * task already had a notification pending). xTaskNotify() always returns
1826 * pdPASS in this case.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001827 *
1828 * eSetValueWithoutOverwrite -
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001829 * If the task being notified did not already have a notification pending then
1830 * the task's notification value is set to ulValue and xTaskNotify() will
1831 * return pdPASS. If the task being notified already had a notification
1832 * pending then no action is performed and pdFAIL is returned.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001833 *
1834 * eNoAction -
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001835 * The task receives a notification without its notification value being
1836 * updated. ulValue is not used and xTaskNotify() always returns pdPASS in
1837 * this case.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001838 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001839 * pulPreviousNotificationValue -
1840 * Can be used to pass out the subject task's notification value before any
1841 * bits are modified by the notify function.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001842 *
1843 * @return Dependent on the value of eAction. See the description of the
1844 * eAction parameter.
1845 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001846 * \defgroup xTaskNotify xTaskNotify
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001847 * \ingroup TaskNotifications
1848 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001849BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue ) PRIVILEGED_FUNCTION;
1850#define xTaskNotify( xTaskToNotify, ulValue, eAction ) xTaskGenericNotify( ( xTaskToNotify ), ( ulValue ), ( eAction ), NULL )
1851#define xTaskNotifyAndQuery( xTaskToNotify, ulValue, eAction, pulPreviousNotifyValue ) xTaskGenericNotify( ( xTaskToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) )
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001852
1853/**
1854 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001855 * <PRE>BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001856 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001857 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
1858 * function to be available.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001859 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001860 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
1861 * "notification value", which is a 32-bit unsigned integer (uint32_t).
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001862 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001863 * A version of xTaskNotify() that can be used from an interrupt service routine
1864 * (ISR).
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001865 *
1866 * Events can be sent to a task using an intermediary object. Examples of such
1867 * objects are queues, semaphores, mutexes and event groups. Task notifications
1868 * are a method of sending an event directly to a task without the need for such
1869 * an intermediary object.
1870 *
1871 * A notification sent to a task can optionally perform an action, such as
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001872 * update, overwrite or increment the task's notification value. In that way
1873 * task notifications can be used to send data to a task, or be used as light
1874 * weight and fast binary or counting semaphores.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001875 *
xiaohu.huang58292b32024-01-03 14:09:51 +08001876 * A notification sent to a task will remain pending until it is cleared by the
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001877 * task calling xTaskNotifyWait() or ulTaskNotifyTake(). If the task was
1878 * already in the Blocked state to wait for a notification when the notification
1879 * arrives then the task will automatically be removed from the Blocked state
1880 * (unblocked) and the notification cleared.
xiaohu.huang58292b32024-01-03 14:09:51 +08001881 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001882 * A task can use xTaskNotifyWait() to [optionally] block to wait for a
1883 * notification to be pending, or ulTaskNotifyTake() to [optionally] block
1884 * to wait for its notification value to have a non-zero value. The task does
1885 * not consume any CPU time while it is in the Blocked state.
xiaohu.huang58292b32024-01-03 14:09:51 +08001886 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001887 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001888 *
1889 * @param xTaskToNotify The handle of the task being notified. The handle to a
1890 * task can be returned from the xTaskCreate() API function used to create the
1891 * task, and the handle of the currently running task can be obtained by calling
1892 * xTaskGetCurrentTaskHandle().
1893 *
1894 * @param ulValue Data that can be sent with the notification. How the data is
1895 * used depends on the value of the eAction parameter.
1896 *
1897 * @param eAction Specifies how the notification updates the task's notification
1898 * value, if at all. Valid values for eAction are as follows:
1899 *
1900 * eSetBits -
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001901 * The task's notification value is bitwise ORed with ulValue. xTaskNofify()
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001902 * always returns pdPASS in this case.
1903 *
1904 * eIncrement -
1905 * The task's notification value is incremented. ulValue is not used and
1906 * xTaskNotify() always returns pdPASS in this case.
1907 *
1908 * eSetValueWithOverwrite -
1909 * The task's notification value is set to the value of ulValue, even if the
1910 * task being notified had not yet processed the previous notification (the
1911 * task already had a notification pending). xTaskNotify() always returns
1912 * pdPASS in this case.
1913 *
1914 * eSetValueWithoutOverwrite -
1915 * If the task being notified did not already have a notification pending then
1916 * the task's notification value is set to ulValue and xTaskNotify() will
1917 * return pdPASS. If the task being notified already had a notification
1918 * pending then no action is performed and pdFAIL is returned.
1919 *
1920 * eNoAction -
1921 * The task receives a notification without its notification value being
1922 * updated. ulValue is not used and xTaskNotify() always returns pdPASS in
1923 * this case.
1924 *
1925 * @param pxHigherPriorityTaskWoken xTaskNotifyFromISR() will set
1926 * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
1927 * task to which the notification was sent to leave the Blocked state, and the
1928 * unblocked task has a priority higher than the currently running task. If
1929 * xTaskNotifyFromISR() sets this value to pdTRUE then a context switch should
1930 * be requested before the interrupt is exited. How a context switch is
1931 * requested from an ISR is dependent on the port - see the documentation page
1932 * for the port in use.
1933 *
1934 * @return Dependent on the value of eAction. See the description of the
1935 * eAction parameter.
1936 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001937 * \defgroup xTaskNotify xTaskNotify
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001938 * \ingroup TaskNotifications
1939 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001940BaseType_t xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1941#define xTaskNotifyFromISR( xTaskToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) )
1942#define xTaskNotifyAndQueryFromISR( xTaskToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) )
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001943
1944/**
1945 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001946 * <PRE>BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001947 *
1948 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
1949 * function to be available.
1950 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001951 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
1952 * "notification value", which is a 32-bit unsigned integer (uint32_t).
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001953 *
1954 * Events can be sent to a task using an intermediary object. Examples of such
1955 * objects are queues, semaphores, mutexes and event groups. Task notifications
1956 * are a method of sending an event directly to a task without the need for such
1957 * an intermediary object.
1958 *
1959 * A notification sent to a task can optionally perform an action, such as
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001960 * update, overwrite or increment the task's notification value. In that way
1961 * task notifications can be used to send data to a task, or be used as light
1962 * weight and fast binary or counting semaphores.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001963 *
1964 * A notification sent to a task will remain pending until it is cleared by the
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001965 * task calling xTaskNotifyWait() or ulTaskNotifyTake(). If the task was
1966 * already in the Blocked state to wait for a notification when the notification
1967 * arrives then the task will automatically be removed from the Blocked state
1968 * (unblocked) and the notification cleared.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001969 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001970 * A task can use xTaskNotifyWait() to [optionally] block to wait for a
1971 * notification to be pending, or ulTaskNotifyTake() to [optionally] block
1972 * to wait for its notification value to have a non-zero value. The task does
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001973 * not consume any CPU time while it is in the Blocked state.
1974 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08001975 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08001976 *
1977 * @param ulBitsToClearOnEntry Bits that are set in ulBitsToClearOnEntry value
1978 * will be cleared in the calling task's notification value before the task
1979 * checks to see if any notifications are pending, and optionally blocks if no
1980 * notifications are pending. Setting ulBitsToClearOnEntry to ULONG_MAX (if
1981 * limits.h is included) or 0xffffffffUL (if limits.h is not included) will have
1982 * the effect of resetting the task's notification value to 0. Setting
1983 * ulBitsToClearOnEntry to 0 will leave the task's notification value unchanged.
1984 *
1985 * @param ulBitsToClearOnExit If a notification is pending or received before
1986 * the calling task exits the xTaskNotifyWait() function then the task's
1987 * notification value (see the xTaskNotify() API function) is passed out using
1988 * the pulNotificationValue parameter. Then any bits that are set in
1989 * ulBitsToClearOnExit will be cleared in the task's notification value (note
1990 * *pulNotificationValue is set before any bits are cleared). Setting
1991 * ulBitsToClearOnExit to ULONG_MAX (if limits.h is included) or 0xffffffffUL
1992 * (if limits.h is not included) will have the effect of resetting the task's
1993 * notification value to 0 before the function exits. Setting
1994 * ulBitsToClearOnExit to 0 will leave the task's notification value unchanged
1995 * when the function exits (in which case the value passed out in
1996 * pulNotificationValue will match the task's notification value).
1997 *
1998 * @param pulNotificationValue Used to pass the task's notification value out
1999 * of the function. Note the value passed out will not be effected by the
2000 * clearing of any bits caused by ulBitsToClearOnExit being non-zero.
2001 *
2002 * @param xTicksToWait The maximum amount of time that the task should wait in
2003 * the Blocked state for a notification to be received, should a notification
2004 * not already be pending when xTaskNotifyWait() was called. The task
2005 * will not consume any processing time while it is in the Blocked state. This
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002006 * is specified in kernel ticks, the macro pdMS_TO_TICSK( value_in_ms ) can be
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002007 * used to convert a time specified in milliseconds to a time specified in
2008 * ticks.
2009 *
2010 * @return If a notification was received (including notifications that were
2011 * already pending when xTaskNotifyWait was called) then pdPASS is
2012 * returned. Otherwise pdFAIL is returned.
2013 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002014 * \defgroup xTaskNotifyWait xTaskNotifyWait
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002015 * \ingroup TaskNotifications
2016 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002017BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002018
2019/**
2020 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002021 * <PRE>BaseType_t xTaskNotifyGive( TaskHandle_t xTaskToNotify );</PRE>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002022 *
2023 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
2024 * to be available.
2025 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002026 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
2027 * "notification value", which is a 32-bit unsigned integer (uint32_t).
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002028 *
2029 * Events can be sent to a task using an intermediary object. Examples of such
2030 * objects are queues, semaphores, mutexes and event groups. Task notifications
2031 * are a method of sending an event directly to a task without the need for such
2032 * an intermediary object.
2033 *
2034 * A notification sent to a task can optionally perform an action, such as
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002035 * update, overwrite or increment the task's notification value. In that way
2036 * task notifications can be used to send data to a task, or be used as light
2037 * weight and fast binary or counting semaphores.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002038 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002039 * xTaskNotifyGive() is a helper macro intended for use when task notifications
xiaohu.huang58292b32024-01-03 14:09:51 +08002040 * are used as light weight and faster binary or counting semaphore equivalents.
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002041 * Actual FreeRTOS semaphores are given using the xSemaphoreGive() API function,
2042 * the equivalent action that instead uses a task notification is
2043 * xTaskNotifyGive().
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002044 *
2045 * When task notifications are being used as a binary or counting semaphore
2046 * equivalent then the task being notified should wait for the notification
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002047 * using the ulTaskNotificationTake() API function rather than the
2048 * xTaskNotifyWait() API function.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002049 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002050 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002051 *
2052 * @param xTaskToNotify The handle of the task being notified. The handle to a
2053 * task can be returned from the xTaskCreate() API function used to create the
2054 * task, and the handle of the currently running task can be obtained by calling
2055 * xTaskGetCurrentTaskHandle().
2056 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002057 * @return xTaskNotifyGive() is a macro that calls xTaskNotify() with the
2058 * eAction parameter set to eIncrement - so pdPASS is always returned.
2059 *
2060 * \defgroup xTaskNotifyGive xTaskNotifyGive
2061 * \ingroup TaskNotifications
2062 */
2063#define xTaskNotifyGive( xTaskToNotify ) xTaskGenericNotify( ( xTaskToNotify ), ( 0 ), eIncrement, NULL )
2064
2065/**
2066 * task. h
2067 * <PRE>void vTaskNotifyGiveFromISR( TaskHandle_t xTaskHandle, BaseType_t *pxHigherPriorityTaskWoken );
2068 *
2069 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
2070 * to be available.
2071 *
2072 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
2073 * "notification value", which is a 32-bit unsigned integer (uint32_t).
2074 *
2075 * A version of xTaskNotifyGive() that can be called from an interrupt service
2076 * routine (ISR).
2077 *
2078 * Events can be sent to a task using an intermediary object. Examples of such
2079 * objects are queues, semaphores, mutexes and event groups. Task notifications
2080 * are a method of sending an event directly to a task without the need for such
2081 * an intermediary object.
2082 *
2083 * A notification sent to a task can optionally perform an action, such as
2084 * update, overwrite or increment the task's notification value. In that way
2085 * task notifications can be used to send data to a task, or be used as light
2086 * weight and fast binary or counting semaphores.
2087 *
2088 * vTaskNotifyGiveFromISR() is intended for use when task notifications are
2089 * used as light weight and faster binary or counting semaphore equivalents.
2090 * Actual FreeRTOS semaphores are given from an ISR using the
2091 * xSemaphoreGiveFromISR() API function, the equivalent action that instead uses
2092 * a task notification is vTaskNotifyGiveFromISR().
2093 *
2094 * When task notifications are being used as a binary or counting semaphore
2095 * equivalent then the task being notified should wait for the notification
2096 * using the ulTaskNotificationTake() API function rather than the
2097 * xTaskNotifyWait() API function.
2098 *
2099 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
2100 *
2101 * @param xTaskToNotify The handle of the task being notified. The handle to a
2102 * task can be returned from the xTaskCreate() API function used to create the
2103 * task, and the handle of the currently running task can be obtained by calling
2104 * xTaskGetCurrentTaskHandle().
xiaohu.huang58292b32024-01-03 14:09:51 +08002105 *
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002106 * @param pxHigherPriorityTaskWoken vTaskNotifyGiveFromISR() will set
2107 * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
2108 * task to which the notification was sent to leave the Blocked state, and the
2109 * unblocked task has a priority higher than the currently running task. If
2110 * vTaskNotifyGiveFromISR() sets this value to pdTRUE then a context switch
2111 * should be requested before the interrupt is exited. How a context switch is
2112 * requested from an ISR is dependent on the port - see the documentation page
2113 * for the port in use.
2114 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002115 * \defgroup xTaskNotifyWait xTaskNotifyWait
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002116 * \ingroup TaskNotifications
2117 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002118void vTaskNotifyGiveFromISR( TaskHandle_t xTaskToNotify, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002119
2120/**
2121 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002122 * <PRE>uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002123 *
2124 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
2125 * function to be available.
2126 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002127 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
2128 * "notification value", which is a 32-bit unsigned integer (uint32_t).
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002129 *
2130 * Events can be sent to a task using an intermediary object. Examples of such
2131 * objects are queues, semaphores, mutexes and event groups. Task notifications
2132 * are a method of sending an event directly to a task without the need for such
2133 * an intermediary object.
2134 *
2135 * A notification sent to a task can optionally perform an action, such as
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002136 * update, overwrite or increment the task's notification value. In that way
2137 * task notifications can be used to send data to a task, or be used as light
2138 * weight and fast binary or counting semaphores.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002139 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002140 * ulTaskNotifyTake() is intended for use when a task notification is used as a
2141 * faster and lighter weight binary or counting semaphore alternative. Actual
2142 * FreeRTOS semaphores are taken using the xSemaphoreTake() API function, the
2143 * equivalent action that instead uses a task notification is
2144 * ulTaskNotifyTake().
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002145 *
2146 * When a task is using its notification value as a binary or counting semaphore
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002147 * other tasks should send notifications to it using the xTaskNotifyGive()
2148 * macro, or xTaskNotify() function with the eAction parameter set to
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002149 * eIncrement.
2150 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002151 * ulTaskNotifyTake() can either clear the task's notification value to
2152 * zero on exit, in which case the notification value acts like a binary
2153 * semaphore, or decrement the task's notification value on exit, in which case
2154 * the notification value acts like a counting semaphore.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002155 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002156 * A task can use ulTaskNotifyTake() to [optionally] block to wait for a
2157 * the task's notification value to be non-zero. The task does not consume any
2158 * CPU time while it is in the Blocked state.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002159 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002160 * Where as xTaskNotifyWait() will return when a notification is pending,
2161 * ulTaskNotifyTake() will return when the task's notification value is
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002162 * not zero.
2163 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002164 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002165 *
2166 * @param xClearCountOnExit if xClearCountOnExit is pdFALSE then the task's
2167 * notification value is decremented when the function exits. In this way the
2168 * notification value acts like a counting semaphore. If xClearCountOnExit is
2169 * not pdFALSE then the task's notification value is cleared to zero when the
2170 * function exits. In this way the notification value acts like a binary
2171 * semaphore.
2172 *
2173 * @param xTicksToWait The maximum amount of time that the task should wait in
2174 * the Blocked state for the task's notification value to be greater than zero,
2175 * should the count not already be greater than zero when
2176 * ulTaskNotifyTake() was called. The task will not consume any processing
2177 * time while it is in the Blocked state. This is specified in kernel ticks,
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002178 * the macro pdMS_TO_TICSK( value_in_ms ) can be used to convert a time
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002179 * specified in milliseconds to a time specified in ticks.
2180 *
2181 * @return The task's notification count before it is either cleared to zero or
2182 * decremented (see the xClearCountOnExit parameter).
2183 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002184 * \defgroup ulTaskNotifyTake ulTaskNotifyTake
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002185 * \ingroup TaskNotifications
2186 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002187uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002188
2189/**
2190 * task. h
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002191 * <PRE>BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask );</pre>
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002192 *
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002193 * If the notification state of the task referenced by the handle xTask is
2194 * eNotified, then set the task's notification state to eNotWaitingNotification.
2195 * The task's notification value is not altered. Set xTask to NULL to clear the
2196 * notification state of the calling task.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002197 *
2198 * @return pdTRUE if the task's notification state was set to
2199 * eNotWaitingNotification, otherwise pdFALSE.
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002200 * \defgroup xTaskNotifyStateClear xTaskNotifyStateClear
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002201 * \ingroup TaskNotifications
2202 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002203BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask );
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002204
2205/*-----------------------------------------------------------
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002206 * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
2207 *----------------------------------------------------------*/
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002208
2209/*
2210 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
2211 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
2212 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2213 *
2214 * Called from the real time kernel tick (either preemptive or cooperative),
2215 * this increments the tick count and checks if any tasks that are blocked
2216 * for a finite period required removing from a blocked list and placing on
2217 * a ready list. If a non-zero value is returned then a context switch is
2218 * required because either:
2219 * + A task was removed from a blocked list because its timeout had expired,
2220 * or
2221 * + Time slicing is in use and there is a task of equal priority to the
2222 * currently running task.
2223 */
2224BaseType_t xTaskIncrementTick( void ) PRIVILEGED_FUNCTION;
2225
2226/*
2227 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
2228 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2229 *
2230 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
2231 *
2232 * Removes the calling task from the ready list and places it both
2233 * on the list of tasks waiting for a particular event, and the
2234 * list of delayed tasks. The task will be removed from both lists
2235 * and replaced on the ready list should either the event occur (and
2236 * there be no higher priority tasks waiting on the same event) or
2237 * the delay period expires.
2238 *
2239 * The 'unordered' version replaces the event list item value with the
2240 * xItemValue value, and inserts the list item at the end of the list.
2241 *
2242 * The 'ordered' version uses the existing event list item value (which is the
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002243 * owning tasks priority) to insert the list item into the event list is task
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002244 * priority order.
2245 *
2246 * @param pxEventList The list containing tasks that are blocked waiting
2247 * for the event to occur.
2248 *
2249 * @param xItemValue The item value to use for the event list item when the
2250 * event list is not ordered by task priority.
2251 *
2252 * @param xTicksToWait The maximum amount of time that the task should wait
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002253 * for the event to occur. This is specified in kernel ticks,the constant
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002254 * portTICK_PERIOD_MS can be used to convert kernel ticks into a real time
2255 * period.
2256 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002257void vTaskPlaceOnEventList( List_t * const pxEventList, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2258void vTaskPlaceOnUnorderedEventList( List_t * pxEventList, const TickType_t xItemValue, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002259
2260/*
2261 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
2262 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2263 *
2264 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
2265 *
2266 * This function performs nearly the same function as vTaskPlaceOnEventList().
2267 * The difference being that this function does not permit tasks to block
2268 * indefinitely, whereas vTaskPlaceOnEventList() does.
2269 *
2270 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002271void vTaskPlaceOnEventListRestricted( List_t * const pxEventList, TickType_t xTicksToWait, const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002272
2273/*
2274 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
2275 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2276 *
2277 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
2278 *
2279 * Removes a task from both the specified event list and the list of blocked
2280 * tasks, and places it on a ready queue.
2281 *
2282 * xTaskRemoveFromEventList()/vTaskRemoveFromUnorderedEventList() will be called
2283 * if either an event occurs to unblock a task, or the block timeout period
2284 * expires.
2285 *
2286 * xTaskRemoveFromEventList() is used when the event list is in task priority
2287 * order. It removes the list item from the head of the event list as that will
2288 * have the highest priority owning task of all the tasks on the event list.
2289 * vTaskRemoveFromUnorderedEventList() is used when the event list is not
2290 * ordered and the event list items hold something other than the owning tasks
2291 * priority. In this case the event list item value is updated to the value
2292 * passed in the xItemValue parameter.
2293 *
2294 * @return pdTRUE if the task being removed has a higher priority than the task
2295 * making the call, otherwise pdFALSE.
2296 */
2297BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList ) PRIVILEGED_FUNCTION;
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002298void vTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem, const TickType_t xItemValue ) PRIVILEGED_FUNCTION;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002299
2300/*
2301 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
2302 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
2303 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2304 *
2305 * Sets the pointer to the current TCB to the TCB of the highest priority task
2306 * that is ready to run.
2307 */
2308portDONT_DISCARD void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION;
2309
2310/*
2311 * THESE FUNCTIONS MUST NOT BE USED FROM APPLICATION CODE. THEY ARE USED BY
2312 * THE EVENT BITS MODULE.
2313 */
2314TickType_t uxTaskResetEventItemValue( void ) PRIVILEGED_FUNCTION;
2315
2316/*
2317 * Return the handle of the calling task.
2318 */
2319TaskHandle_t xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION;
2320
2321/*
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002322 * Capture the current time status for future reference.
2323 */
2324void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
2325
2326/*
2327 * Compare the time status now with that previously captured to see if the
2328 * timeout has expired.
2329 */
2330BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait ) PRIVILEGED_FUNCTION;
2331
2332/*
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002333 * Shortcut used by the queue implementation to prevent unnecessary call to
2334 * taskYIELD();
2335 */
2336void vTaskMissedYield( void ) PRIVILEGED_FUNCTION;
2337
2338/*
2339 * Returns the scheduler state as taskSCHEDULER_RUNNING,
2340 * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
2341 */
2342BaseType_t xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION;
2343
2344/*
2345 * Raises the priority of the mutex holder to that of the calling task should
2346 * the mutex holder have a priority less than the calling task.
2347 */
2348BaseType_t xTaskPriorityInherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
2349
2350/*
2351 * Set the priority of a task back to its proper priority in the case that it
2352 * inherited a higher priority while it was holding a semaphore.
2353 */
2354BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
2355
2356/*
2357 * If a higher priority task attempting to obtain a mutex caused a lower
2358 * priority task to inherit the higher priority task's priority - but the higher
2359 * priority task then timed out without obtaining the mutex, then the lower
2360 * priority task will disinherit the priority again - but only down as far as
2361 * the highest priority task that is still waiting for the mutex (if there were
2362 * more than one task waiting for the mutex).
2363 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002364void vTaskPriorityDisinheritAfterTimeout( TaskHandle_t const pxMutexHolder, UBaseType_t uxHighestPriorityWaitingTask ) PRIVILEGED_FUNCTION;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002365
2366/*
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002367 * Get the uxTCBNumber assigned to the task referenced by the xTask parameter.
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002368 */
2369UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
2370
2371/*
2372 * Set the uxTaskNumber of the task referenced by the xTask parameter to
2373 * uxHandle.
2374 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002375void vTaskSetTaskNumber( TaskHandle_t xTask, const UBaseType_t uxHandle ) PRIVILEGED_FUNCTION;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002376
2377/*
2378 * Only available when configUSE_TICKLESS_IDLE is set to 1.
2379 * If tickless mode is being used, or a low power mode is implemented, then
2380 * the tick interrupt will not execute during idle periods. When this is the
2381 * case, the tick count value maintained by the scheduler needs to be kept up
2382 * to date with the actual execution time by being skipped forward by a time
2383 * equal to the idle period.
2384 */
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002385void vTaskStepTick( const TickType_t xTicksToJump ) PRIVILEGED_FUNCTION;
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002386
2387/*
2388 * Only available when configUSE_TICKLESS_IDLE is set to 1.
2389 * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port
2390 * specific sleep function to determine if it is ok to proceed with the sleep,
2391 * and if it is ok to proceed, if it is ok to sleep indefinitely.
2392 *
2393 * This function is necessary because portSUPPRESS_TICKS_AND_SLEEP() is only
2394 * called with the scheduler suspended, not from within a critical section. It
2395 * is therefore possible for an interrupt to request a context switch between
2396 * portSUPPRESS_TICKS_AND_SLEEP() and the low power mode actually being
2397 * entered. eTaskConfirmSleepModeStatus() should be called from a short
2398 * critical section between the timer being stopped and the sleep mode being
2399 * entered to ensure it is ok to proceed into the sleep mode.
2400 */
2401eSleepModeStatus eTaskConfirmSleepModeStatus( void ) PRIVILEGED_FUNCTION;
2402
2403/*
2404 * For internal use only. Increment the mutex held count when a mutex is
2405 * taken and return the handle of the task that has taken the mutex.
2406 */
2407TaskHandle_t pvTaskIncrementMutexHeldCount( void ) PRIVILEGED_FUNCTION;
2408
2409/*
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002410 * For internal use only. Same as vTaskSetTimeOutState(), but without a critial
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002411 * section.
2412 */
2413void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
2414
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002415BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void * pvParameter ) PRIVILEGED_FUNCTION;
xiaohu.huang58292b32024-01-03 14:09:51 +08002416
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002417void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
2418 StackType_t ** ppxIdleTaskStackBuffer,
2419 configSTACK_DEPTH_TYPE * pulIdleTaskStackSize );
2420
2421void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer,
2422 configSTACK_DEPTH_TYPE *pulTimerTaskStackSize );
2423
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002424#ifdef __cplusplus
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002425}
kelvin.zhang57fb6ae2021-10-15 10:19:42 +08002426#endif
2427#endif /* INC_TASK_H */
xiaohu.huang4f321fb2024-03-22 14:50:29 +08002428
2429
2430