在非抢先系统中执行ISR
在非抢先系统中,在ISR完成执行后,即使激活更高的优先任务,中断的任务也会继续执行吗?
in a non preemptive system, after an ISR finishes execution, will the interrupted task continue execution even if a higher priority task was activated?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该答案是特定于弗雷托斯的,可能与其他RTOS不相关。
默认情况下,弗雷托斯是先发制人的。但是,也可以将其配置为由 freertosconfig.h 的配置选项通常不归为首发,
通常,来自ISR的返回不会触发上下文开关。但是在抢先系统中通常是可取的,因此在大多数弗里托斯示例中,您会看到
portyield_from_isr(xhigherPriorityTaskWoken);
在ISR末尾,如果xhigherPriorityTaskWoken
是,则触发上下文开关。pdtrue
。xhigherPriorityTaskWoken
在ISR开头(用户手动手动)和可能导致上下文开关的操作(例如vtaskNotifygiveGiveGiveGiveFromisr()
pdfalse /code>,XqueuesendToBackFromisr()
等,将其作为参数,并将其设置为pdtrue
如果系统调用后需要上下文开关。在非首次配置中,您只需将
null
传递给此类系统调用,而不是xhigherPriorityTaskWoken
,然后do not call portyield_from_isr() 在ISR的末尾。在这种情况下,即使ISR唤醒了更高的优先级任务,执行将返回到当前运行的任务,并保留在那里,直到此任务产生或进行阻止系统调用为止。您可以将ISR屈服机制与先发制方法混合。例如,即使
configuse_preemption
为0,您也可以从ISR强制上下文开关(先发制人),但是如果中断/预先抢先任务不期望发生,这可能会导致问题,所以我不喜欢t推荐它。This answer is specific to FreeRTOS, and may not be relevant to other RTOS'es.
FreeRTOS is preemptive by default. However, it can also be configured to be non-preemptive by the config option in FreeRTOSConfig.h
Normally, a return from ISR does not trigger a context switch. But in preemptive systems it's often desirable, so in most FreeRTOS examples, you see
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
at the end of the ISR, which triggers a context switch ifxHigherPriorityTaskWoken
ispdTRUE
.xHigherPriorityTaskWoken
is initialized topdFALSE
at the start of the ISR (manually by the user), and operations which can cause a context switch, such asvTaskNotifyGiveFromISR()
,xQueueSendToBackFromISR()
etc. , take it as an argument and set it topdTRUE
if a context switch is required after the system call.In a non-preemptive configuration, you simply pass
NULL
to such system calls instead ofxHigherPriorityTaskWoken
, and do not callportYIELD_FROM_ISR()
at the end of the ISR. In this case, even if a higher priority task is awakened by the ISR, execution returns to the currently running task and remains there until this task yields or makes a blocking system call.You may mix ISR yield mechanism with preemption method. For example, you can force a context switch (preemption) from ISR even when
configUSE_PREEMPTION
is 0, but this may cause problems if the interrupted/preempted task doesn't expect it to happen, so I don't recommend it.