xTaskResumeFromISR
[任务控制]
task. h BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume );
必须将 include_vTaskSuspend 和 INCLUDE_xTaskResumeFromISR 定义为 1 才能使用此函数。有关详细信息,请参阅 RTOS 配置文档。
可从 ISR 内调用的恢复挂起任务的函数。
由多次调用 vTaskSuspend() 中的一次调用挂起的任务可通过单次调用 xTaskResumeFromISR() 重新运行。
xTaskResumeFromISR() 通常被视为危险函数,因为其
操作未被锁定。 因此,如果中断可能在任务被挂起之前到达,
从而中断丢失,
则绝对不应使用该函数
来同步任务与中断。 可使用信号量,
或者最好是直达任务通知,来避免这种可能性。
提供了一个使用直达到任务通知的有效示例
。
- 参数:
-
- 返回:
-
如果恢复任务导致上下文切换,则返回 pdTRUE,否则返回 pdFALSE。 ISR 使用此信息来确定 ISR 之后是否需要上下文切换。 |
示例用法:
TaskHandle_t xHandle;
void vAFunction( void )
{
// Create a task, storing the handle.
xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
// ... Rest of code.
}
void vTaskCode( void *pvParameters )
{
// The task being suspended and resumed.
for( ;; )
{
// ... Perform some function here.
// The task suspends itself.
vTaskSuspend( NULL );
// The task is now suspended, so will not reach here until the ISR resumes it.
}
}
void vAnExampleISR( void )
{
BaseType_t xYieldRequired;
// Resume the suspended task.
xYieldRequired = xTaskResumeFromISR( xHandle );
// We should switch context so the ISR returns to a different task.
// NOTE: How this is done depends on the port you are using. Check
// the documentation and examples for your port.
portYIELD_FROM_ISR( xYieldRequired );
}
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|