是否立即引发PendSV/SVC异常? [英] Are the PendSV / SVC exceptions raised immediately?
问题描述
我正在研究Cortex-M4上的上下文保存和还原机制,以便可以实现简单的多任务处理.我使用 arm-none-eabi-g ++
来编译此代码.暂时不考虑可移植性.
I'm working on a context saving and restoring mechanism on the Cortex-M4 so that I can implement simple multitasking. I use arm-none-eabi-g++
for compiling this code. Portability is not a concern for now.
当任务可以调用 yield
函数时,我将其用于协作式多任务处理,这将通过引发 PendSV
异常使执行返回到内核.(然后,内核可以安排另一个任务运行,并最终返回到当前任务.)
I use this for a form of cooperative multitasking when a task can call a yield
function which will make execution return to the kernel by raising a PendSV
exception. (The kernel can then schedule another task for running and eventually return to the current one.)
void Task::yield() {
// ...
// ... (Context saving code goes here) ...
// ...
// Set the PENDSVSET to trigger a PendSV exception
SCB->ICSR |= SCB_ICSR_PENDSVSET_Msk;
}
我希望执行立即返回内核.
问题是,在我将 ICSR
中的 PENDSVSET
位置1后,是否可以保证立即执行到 PendSV_Handler
?它会在 yield
函数之后继续执行指令吗?
The question is, after I set the PENDSVSET
bit in the ICSR
, is it guaranteed that execution goes to PendSV_Handler
immediately, or does it continue executing instructions after the yield
function?
为此,我最好使用 SVC
指令吗?
Would I better off using the SVC
instruction for this?
void Task::yield() {
// ...
// SVC has an 8-bit immediate constant argument, which
// can be used by the kernel for determining what kind
// of system call this is.
asm volatile("SVC 0");
}
推荐答案
从体系结构手册中的描述来看,PendSV真正用于更高优先级的异常处理程序说哦,我中断的线程是因此,现在需要在自己的上下文中进行系统调用."如果只希望线程在其正常执行过程中进行同步系统调用,则这是 svc
指令的唯一目的.
From the description in the architecture manual, PendSV is really intended for when for a higher-priority exception handler to say "oh, the thread I've interrupted is now going to need to make a system call in its own context because of this". If you simply want the thread to make a synchronous system call in the process of its normal execution, that's the sole purpose of the svc
instruction.
这篇关于是否立即引发PendSV/SVC异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!