Updated Apr 2025

xTaskGetApplicationTaskTag, xTaskGetApplicationTaskTagFromISR

[Task Control]

task. h

1TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask );
2TaskHookFunction_t xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask );

configUSE_APPLICATION_TASK_TAG must be defined as 1 for these functions to be available. See the RTOS Configuration documentation for more information.

xTaskGetApplicationTaskTagFromISR() is a version of xTaskGetApplicationTaskTag() that can be called from an interrupt service routine (ISR).

Returns the 'tag' value associated with a task. The meaning and use of the tag value is defined by the application writer. The RTOS kernel itself will not normally access the tag value.

This function is intended for advanced users only.

Parameters:

  • xTask

    The handle of the task being queried. A task can query its own tag value by using NULL as the parameter value.

Returns:

The 'tag' value of the task being queried.

Example usage:

1/* In this example, an integer is set as the task tag value. */
2void vATask( void *pvParameters )
3{
4 /* Assign a tag value of 1 to the currently executing task.
5 The (void *) cast is used to prevent compiler warnings. */
6 vTaskSetApplicationTaskTag( NULL, ( void * ) 1 );
7
8 for( ;; )
9 {
10 /* Rest of task code goes here. */
11 }
12}
13
14void vAFunction( void )
15{
16TaskHandle_t xHandle;
17int iReturnedTaskHandle;
18
19 /* Create a task from the vATask() function, storing the handle to the
20 created task in the xTask variable. */
21
22 /* Create the task. */
23 if( xTaskCreate(
24 vATask, /* Pointer to the function that implements
25 the task. */
26 "Demo task", /* Text name given to the task. */
27 STACK_SIZE, /* The size of the stack that should be created
28 for the task. This is defined in words, not
29 bytes. */
30 NULL, /* The task does not use the parameter. */
31 TASK_PRIORITY, /* The priority to assign to the newly created
32 task. */
33 &xHandle /* The handle to the task being created will be
34 placed in xHandle. */
35 ) == pdPASS )
36 {
37 /* The task was created successfully. Delay for a short period to allow
38 the task to run. */
39 vTaskDelay( 100 );
40
41 /* What tag value is assigned to the task? The returned tag value is
42 stored in an integer, so cast to an integer to prevent compiler
43 warnings. */
44 iReturnedTaskHandle = ( int ) xTaskGetApplicationTaskTag( xHandle );
45 }
46}