物联网嵌入式系统:FreeRTOS任务挂起和恢复

1.任务挂起和恢复

要使用着些API则需要使能宏定义:

INCLUDE_vTaskSuspend、INCLUDE_xTaskResumeFromISR

1.1任务挂起

任务挂起:将任务控制块、堆栈保存,然后将任务停止,当任务需要开始运行的时候,则继续之前的状态开始运行,无需重新创建。

任务删除:那么就是将当前的任务控制块、堆栈都释放掉,然后停止运行。如果需要再次运行则需要重新创建任务控制块等信息。

void vTaskSuspend( TaskHandle_t xTaskToSuspend ) PRIVILEGED_FUNCTION;

// Suspend ourselves.
vTaskSuspend( NULL );

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

1.2任务恢复

/*从普通任务中恢复某一个任务*/
void vTaskResume( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;

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


/*****************************************************
从中断函数服务中恢复某一个任务

返回值很重要:pdTRUE if resuming the task should result in a context switch, 
* otherwise pdFALSE. This is used by the ISR to determine if a context switch 
* may be required following the ISR。
*****************************************************/
BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;

 

 

猜你喜欢

转载自blog.csdn.net/yuupengsun/article/details/107574652