我试图理解为什么用户必须调用该taskYIELD_FROM_ISR()
方法以及为什么该方法中的 RTOS 不自动调用它xStreamBufferSendFromISR
。
我的问题是指FreeRTOS_Manual p。369.
/* A stream buffer that has already been created. */
StreamBufferHandle_t xStreamBuffer;
void vAnInterruptServiceRoutine( void ) {
size_t xBytesSent;
char *pcStringToSend = "String to send";
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
/* Attempt to send the string to the stream buffer. */
xBytesSent = xStreamBufferSendFromISR(xStreamBuffer,(void *) pcStringToSend,strlen( pcStringToSend),&xHigherPriorityTaskWoken);
if(xBytesSent != strlen(pcStringToSend)){
/* There was not enough free space in the stream buffer for the entire string to be written, ut xBytesSent bytes were written. */
}
/*
If xHigherPriorityTaskWoken was set to pdTRUE inside xStreamBufferSendFromISR() then a
task that has a priority above the priority of the currently executing task was unblocked
and a context switch should be performed to ensure the ISR returns to the unblocked task.
In most FreeRTOS ports this is done by simply passing xHigherPriorityTaskWoken into
taskYIELD_FROM_ISR(), which will test the variables value, and perform the context switch
if necessary. Check the documentation for the port in use for port specific instructions.
*/
taskYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
我对场景的理解
前提条件
- 有两个任务
- Task1(高优先级)和 Task2(低优先级)
- Task1 处于阻塞状态,等待 streamBuffer 输入
- Task2 处于运行状态并从
vAnInterruptServiceRoutine
在 ISR 内
- ISR 方法调用
xStreamBufferSendFromISR()
- 这个调用意味着,Task1 的 Blocked-State 变为 Ready-State
案例 A 如果 ISR 方法现在正在返回,则不会调用调度程序,并且 Task2 会一直运行,直到时间片周期结束,然后调度程序会切换到高优先级 Task1。
案例 B
如果 ISR 方法taskYIELD_FROM_ISR(xHigherPriorityTaskWoken);
最后调用,调度程序将被调用,返回 ISR 后,Task1 将运行而不是 Task2。
问题
- 是不是,Task2 将一直执行到一个时间片周期结束,或者任务切换是否还有另一个触发器?
- 为什么
taskYIELD_FROM_ISR()
调用时 RTOS 不自动调用该方法xStreamBufferSendFromISR()
?