FreeRTOS(四)——任务挂起与恢复

1 任务挂起与恢复API函数

函数 描述
vTaskSuspend() 挂起一个任务
vTaskResume() 恢复一个任务的运行
vTaskResumeFromeISR() 中断服务函数中恢复一个任务的运行

vTaskSuspend()

此函数用于将某个任务设置为挂起态,进入挂起态的任务永远都不会进入运行态。退出挂起态的唯一方法就是调用任务恢复函数vTaskResume()vTaskResumeFromISR()
vTaskSuspend(TaskHandle_t xTaskToSuspend)

参数 描述
xTaskToSuspend 要挂起的任务的任务句柄,创建任务的时候会为每一个任务分配一个任务句柄。使用vTaskCreate()时的参数pxCretedTask为该任务句柄,使用vTaskCreateStatic()时的返回值为任务句柄。也可以使用xTaskGetHandle()来根据任务名字来获取某个任务的任务句柄。注意!如果参数为NULL的话表示挂起任务自己
返回值 描述

vTaskResume()

将一个任务从挂起态恢复到就绪态,只有通过函数vTaskSuspend设置为挂起态的任务才可以使用vTaskResume()恢复!
vTaskResume(TaskHandle_t xTaskToResume)

参数 描述
xTaskToResume 要恢复的任务句柄
返回值 描述

源码中的例子如下:

* Example usage:
   <pre>
 void vAFunction( void )
 {
 TaskHandle_t xHandle;

     // Create a task, storing the handle.
     xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );

     // ...

     // Use the handle to suspend the created task.
     vTaskSuspend( xHandle );

     // ...

     // The created task will not run during this period, unless
     // another task calls vTaskResume( xHandle ).

     //...


     // Resume the suspended task ourselves.
     vTaskResume( xHandle );

     // The created task will once again get microcontroller processing
     // time in accordance with its priority within the system.
 }
   </pre>
 * \defgroup vTaskResume vTaskResume
 * \ingroup TaskCtrl
 */

猜你喜欢

转载自blog.csdn.net/qq_30650153/article/details/80883240