已更新 2025年7月
uxTaskPriorityGet()
[任务控制]
task. h
1UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask );
INCLUDE_uxTaskPriorityGet
获取任意任务的优先级。
参数:
-
xTask
待查询任务的句柄。传递 NULL 句柄会返回调用任务的优先级。
返回:
- 的优先级。xTask
用法示例:
1void vATaskFunction( void * pvParams )2{3 TaskHandle_t xHandle;45 ( void ) pvParams;67 // Create a task, storing the handle.8 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );910 // ...1112 // Use the handle to obtain the priority of the created task.13 // It was created with tskIDLE_PRIORITY, but may have changed14 // it itself.15 if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )16 {17 // The task has changed its priority.18 }1920 // ...2122 // Is our priority higher than the created task?23 if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )24 {25 // Our priority (obtained using NULL handle) is higher.26 }27}