中断处理过程中并不执行线程切换,只是通过函数rt_hw_context_switch_interrupt设置相关的全局变量。当中断处理完毕后,检查rt_thread_switch_interrupt_flag变量,若值不为1则正常返回;若值为1,则进行线程切换,实际的切换工作由中断入口函数中rt_hw_context_switch_interrupt_do
LDR r1, =rt_interrupt_to_thread STR r0, [r1] ; STR: 寄存器 =》 内存 ; 设置 rt_interrupt_from_thread 的值为 0,表示第一次线程切换 LDR r1, =rt_interrupt_from_thread MOV r0, #0x0 STR r0, [r1] ; 设置 rt_thread_switch_interrupt_flag 的值为1 LDR r1, =rt_thread_switch_interrupt_f...
.global rt_hw_context_switch_to.type rt_hw_context_switch_to,%functionrt_hw_context_switch_to:LDR R1,=rt_interrupt_to_thread STR R0,[R1]/* set from thread to 0 */LDR R1,=rt_interrupt_from_thread MOV R0,#0STR R0,[R1]/* set interrupt flag to 1 */LDR R1,=rt_thread_switch_in...
PendSV_Handler:/* disable interrupt to protect context switch */MRS R2,PRIMASK//移动特殊寄存器到普通的寄存器 是一种寄存器到寄存器之间的传送指令CPSID I/* get rt_thread_switch_interrupt_flag */LDR R0,=rt_thread_switch_interrupt_flag LDR R1,[R0]CBZ R1,pendsv_exit/* pendsv aLReady handled *...
rt_hw_context_switch_interrupt()接口实现 void rt_hw_context_switch_interrupt(rt_ubase_t from, rt_ubase_t to) { if(rt_thread_switch_interrupt_flag == 0) { /* 将from和to线程保存到对应的全局变量中,以便于后续线程切换 */ rt_interrupt_from_thread = (*( (unsigned long *)from )); ...
rt_hw_context_switch_interrupt不进行实际的上下文切换,它仅仅是设置相关变量,保存切换信息,在实际的中断中,根据这些信息进行上下文切换,相关代码如下: /** r0 --> rt_thread_switch_interrupt_flag *ARM当前处于IRQ工作模式,sp_irq指向的内存中保存了被中断线程的上下文r0-r12,lr*/rt_hw_context_switch_interrupt...
99行-105行,rt_thread_switch_interrupt_flag清0,判断rt_interrupt_from_thread的值,为0表示OS第一次进行最高优先级就绪状态线程的运行,无需恢复psp,直接跳转到switch_to_thread;为1表示从from线程切换至to线程,需要恢复psp。Debug到此处,rt_interrupt_from_thread的值为0,是第一次进行线程运行。
在ARM9 等平台,rt_hw_context_switch() 和 rt_hw_context_switch_interrupt() 的实现并不一样。在中断处理程序里如果触发了线程的调度,调度函数里会调用 rt_hw_context_switch_interrupt() 触发上下文切换。中断处理程序里处理完中断事务之后,中断退出之前,检查 rt_thread_switch_interrupt_flag 变量,如果该变量的...
rt_thread_switch_interrupt_flag 变量是指示 上下文切换动作 是否在PendSV中断中执行过,如果等于1,表示需要切换,需要在PendSV中断中执行,也就是还没有执行,那么也就不需要再更新rt_interrupt_from_thread变量,(在上一次调用过rt_hw_context_switch/rt_hw_context_switch_interrupt 函数之后还没来得及切换线程,即rt...
19 ; set interrupt flag to 1 20 ; 进行线程切换,把线程切换标志变量rt_thread_switch_interrupt_flag设置为1 21 LDR r1, =rt_thread_switch_interrupt_flag 22 MOV r0, #1 23 STR r0, [r1] 24 25 ; set the PendSV exception priority 26 ; 设置pendsv软件中断的优先级为最低 ...