uxTaskPriorityGet():查询某个任务的优先级
vTaskPrioritySet():改变某个任务的任务优先级
uxTaskGetSystemState():获取系统中任务状态
vTaskGetInfo():获取某个任务信息
xTaskGetApplicationTaskTag():获取某个任务的标签(Tag)值
xTaskGetCurrentTaskHandle():获取当前正在运行的任务的任务句柄
xTaskGetHandle():根据任务名字查找某个任务的句柄
xTaskGetIdleTaskHandle():获取空闲任务的任务句柄
uxTaskGetStackHighWaterMark():获取任务的堆栈的历史剩余最小值,FreeRTOS 中叫做“高水位线”
eTaskGetState():获取某个任务的壮态,这个壮态是 eTaskState 类型
pcTaskGetName():获取某个任务的任务名字
xTaskGetTickCount():获取系统时间计数器值
xTaskGetTickCountFromISR():在中断服务函数中获取时间计数器值
xTaskGetSchedulerState():获取任务调度器的壮态,开启或未开启
uxTaskGetNumberOfTasks():获取当前系统中存在的任务数量
vTaskList():以一种表格的形式输出当前系统中所有任务的详细信息
vTaskGetRunTimeStats():获取每个任务的运行时间
vTaskSetApplicationTaskTag():设置任务标签(Tag)值
SetThreadLocalStoragePointer():设置线程本地存储指针
GetThreadLocalStoragePointer():获取线程本地存储指针
使用举例
/*
* UBaseType_t uxTaskGetNumberOfTasks( void )
* UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray,
* const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime )
*/
TaskStatus_t *StatusArray;
UBaseType_t task_num;
task_num=uxTaskGetNumberOfTasks(); //获取系统任务数量
printf("uxTaskGetNumberOfTasks %d
", task_num);
StatusArray=pvPortMalloc(task_num*sizeof(TaskStatus_t));//申请内存
if(StatusArray!=NULL) //内存申请成功
{
ArraySize=uxTaskGetSystemState((TaskStatus_t* )StatusArray, //任务信息存储数组
(UBaseType_t )task_num, //任务信息存储数组大小
(uint32_t* )&TotalRunTime);//保存系统总的运行时间
printf("TaskName Priority TaskNumber
");
for(x=0;x<task_num;x++)
{
printf("%s %d %d
",
StatusArray[x].pcTaskName, //任务名称
(int)StatusArray[x].uxCurrentPriority, //任务优先级
(int)StatusArray[x].xTaskNumber); //任务编号
}
}
vPortFree(StatusArray); //释放内存
实验现象
uxTaskGetNumberOfTasks 5
TaskName Priority TaskNumber
query_task 3 5
led0_task 2 4
IDLE 0 2
start_task 1 1
Tmr Svc 31 3
使用举例
/*
* TaskHandle_t xTaskGetHandle( const char *pcNameToQuery )
* void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus,
* BaseType_t xGetFreeStackSpace, eTaskState eState )
*/
TaskHandle_t TaskHandle;
TaskStatus_t TaskStatus;
TaskHandle=xTaskGetHandle("led0_task"); //根据任务名获取任务句柄
//获取LED0_Task的任务信息
vTaskGetInfo((TaskHandle_t )TaskHandle, //任务句柄
(TaskStatus_t* )&TaskStatus, //任务信息结构体
(BaseType_t )pdTRUE, //允许统计任务堆栈历史最小剩余大小
(eTaskState )eInvalid); //函数自己获取任务运行壮态
printf("任务名: %s
",TaskStatus.pcTaskName);
printf("任务编号: %d
",(int)TaskStatus.xTaskNumber);
printf("任务壮态: %d
",TaskStatus.eCurrentState);
printf("任务当前优先级: %d
",(int)TaskStatus.uxCurrentPriority);
printf("任务基优先级: %d
",(int)TaskStatus.uxBasePriority);
printf("任务堆栈基地址: %#x
",(int)TaskStatus.pxStackBase);
printf("任务堆栈历史剩余最小值: %d
",TaskStatus.usStackHighWaterMark);
实验现象
任务名: led0_task
任务编号: 4
任务壮态: 2
任务当前优先级: 2
任务基优先级: 2
任务堆栈基地址: 0x200012e8
任务堆栈历史剩余最小值: 108
使用举例
/*
* eTaskState eTaskGetState( TaskHandle_t xTask )
*/
typedef enum
{
eRunning = 0, /* A task is querying the state of itself, so must be running. */
eReady, /* The task being queried is in a read or pending ready list. */
eBlocked, /* The task being queried is in the Blocked state. */
eSuspended, /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */
eDeleted, /* The task being queried has been deleted, but its TCB has not yet been freed. */
eInvalid /* Used as an 'invalid state' value. */
} eTaskState;
TaskHandle=xTaskGetHandle("query_task"); //根据任务名获取任务句柄
TaskState=eTaskGetState(TaskHandle); //获取query_task任务的任务壮态
switch((int)TaskState)
{
case eRunning:
sprintf(TaskInfo,"Running");
break;
case eReady:
sprintf(TaskInfo,"Ready");
break;
case eSuspended:
sprintf(TaskInfo,"Suspended");
break;
case eDeleted:
sprintf(TaskInfo,"Deleted");
break;
case eInvalid:
sprintf(TaskInfo,"Invalid");
break;
}
printf("任务壮态值:%d,对应的壮态为:%s
",TaskState,TaskInfo);
实验现象
任务壮态值:0,对应的壮态为:Running
使用举例
/*
* void vTaskList( char * pcWriteBuffer )
*/
vTaskList(InfoBuffer); //获取所有任务的信息
printf("%s
",InfoBuffer);
实验现象
query_task R 3 192 5
IDLE R 0 108 2
led0_task B 2 108 4
Tmr Svc S 31 236 3