下载 FreeRTOS
 

出色的 RTOS & 嵌入式软件

内核
最新资讯
简化任何设备的身份验证云连接。
利用 CoAP 设计节能型云连接 IoT 解决方案。
11.0.0 版 FreeRTOS 内核简介:
FreeRTOS 路线图和代码贡献流程。
使用 FreeRTOS 实现 OPC-UA over TSN。

vTaskGetInfo()
[任务实用程序]

task.h
void vTaskGetInfo( TaskHandle_t xTask,
                   TaskStatus_t *pxTaskStatus,
                   BaseType_t xGetFreeStackSpace,
                   eTaskState eState );

configUSE_TRACE_FACILITY 必须在 FreeRTOSConfig.h 中定义为 1, vTaskGetInfo() 才可用。

uxTaskGetSystemState() 会为系统中的每个任务填充 TaskStatus_t 结构体,而 vTaskGetInfo() 仅为单个任务填充 TaskStatus_t 结构体。 TaskStatus_t 结构体包含 任务句柄的成员、任务名称、任务优先级、任务状态、 以及任务消耗的总运行时间等。

注意: 使用此函数会导致调度器长时间挂起, 因此此函数仅用于调试目的。

参数:
xTask    正在查询的任务的句柄。 将 xTask 设置为 NULL 将返回有关调用任务的信息。
pxTaskStatus   由 pxTaskStatus 指向的 TaskStatus_t 结构体将 填充有关 xTask 参数中传递的句柄所引用的任务的信息。
xGetFreeStackSpace   TaskStatus_t 结构体包含 用于报告被查询任务的堆栈高水位线的成员。 堆栈 高水位线是指堆栈空间历史剩余最小值, 该值越接近于零, 说明任务越接近堆栈溢出。 计算堆栈高水位线需要的时间相对较长,并且可能导致系统 暂时无响应,因此提供了 xGetFreeStackSpace 参数, 以允许跳过高水位线检查。 如果 xGetFreeStackSpace 未设置为 pdFALSE,高水位线值将仅写入 TaskStatus_t 结构体。
eState   TaskStatus_t 结构体包含 用于报告被查询任务的状态的成员。 获取任务状态并不像 简单的赋值那么快,因此提供了 eState 参数,以允许 TaskStatus_t 结构体省略状态信息。 要获取状态信息, 请将 eState 设置为 eInvalid,否则 eState 中传递的值将被报告为 TaskStatus_t 结构体中的任务状态。
用法示例:
void vAFunction( void )
{
TaskHandle_t xHandle;
TaskStatus_t xTaskDetails;

    /* Obtain the handle of a task from its name. */
    xHandle = xTaskGetHandle( "Task_Name" );

    /* Check the handle is not NULL. */
    configASSERT( xHandle );

    /* Use the handle to obtain further information about the task. */
    vTaskGetInfo( /* The handle of the task being queried. */
                  xHandle,
                  /* The TaskStatus_t structure to complete with information
                  on xTask. */
                  &xTaskDetails,
                  /* Include the stack high water mark value in the
                  TaskStatus_t structure. */
                  pdTRUE,
                  /* Include the task state in the TaskStatus_t structure. */
                  eInvalid );
}


TaskStatus_t 定义

typedef struct xTASK_STATUS
{
   /* The handle of the task to which the rest of the information in the
   structure relates. */
   TaskHandle_t xHandle;

   /* A pointer to the task's name.  This value will be invalid if the task was
   deleted since the structure was populated! */
   const signed char *pcTaskName;

   /* A number unique to the task. */
   UBaseType_t xTaskNumber;

   /* The state in which the task existed when the structure was populated. */
   eTaskState eCurrentState;

   /* The priority at which the task was running (may be inherited) when the
   structure was populated. */
   UBaseType_t uxCurrentPriority;

   /* 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. */
   UBaseType_t uxBasePriority;

   /* The total run time allocated to the task so far, as defined by the run
   time stats clock.  Only valid when configGENERATE_RUN_TIME_STATS is
   defined as 1 in FreeRTOSConfig.h. */
   unsigned long ulRunTimeCounter;

   /* Points to the lowest address of the task's stack area. */
   StackType_t *pxStackBase;

   /* 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. */
   configSTACK_DEPTH_TYPE usStackHighWaterMark;
} TaskStatus_t;





Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.