在非抢先系统中执行ISR

发布于 2025-01-19 12:15:46 字数 50 浏览 4 评论 0原文

在非抢先系统中,在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素罗衫 2025-01-26 12:15:46

该答案是特定于弗雷托斯的,可能与其他RTOS不相关。

默认情况下,弗雷托斯是先发制人的。但是,也可以将其配置为由 freertosconfig.h 的配置选项通常不归为首发,

#define configUSE_PREEMPTION 0

通常,来自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

#define configUSE_PREEMPTION 0

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 if xHigherPriorityTaskWoken is pdTRUE.

xHigherPriorityTaskWoken is initialized to pdFALSE at the start of the ISR (manually by the user), and operations which can cause a context switch, such as vTaskNotifyGiveFromISR() , xQueueSendToBackFromISR() etc. , take it as an argument and set it to pdTRUE if a context switch is required after the system call.

In a non-preemptive configuration, you simply pass NULL to such system calls instead of xHigherPriorityTaskWoken, and do not call portYIELD_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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文