REX的interrupt机制(RTOS)

本文详细介绍了ARM处理器中IRQ中断的处理流程。从IRQ_Handler函数入手,探讨了进入和退出中断时的操作,包括保存寄存器状态、切换模式、调用中断跳板函数等关键步骤。此外还讨论了任务切换的条件及过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 The actions performed by REX on entering and leaving an interrupt are discussed in this chapter. 
The ARM has two interrupts, FIQ and IRQ. The discussion in this chapter pertains to handling the 
IRQ interrupt on ARM. The handling of the FIQ interrupt is much simpler, since currently context 
switches are not allowed in a handler that services an FIQ interrupt. 


A function programmed into the exception vector table—IRQ_Handler(), written in ARM 
assembly—gets control as soon as the interrupt is asserted. This function then invokes the interrupt 
trampoline function. The trampoline function, which is defined outside of REX, typically detects 
which interrupt source has asserted an interrupt and calls the corresponding service routine. It is 
installed using rex_set_interrupt_vector() (see Section 8.19 for a detailed description). When 
an interrupt occurs, the ARM processor changes mode to IRQ and switches to a different bank of 
registers. The following actions are performed in IRQ_Handler: 
1. Some registers will be trashed by the interrupt trampoline function. Save the registers that might 
be overwritten by the trampoline function on the interrupt stack. Since this function is a C routine, 
the registers saved are r0-r3, r10, r12, and r14. Save the SPSR as well since this register 
may be trashed by a subsequent nested interrupt. 
2. Increment the interrupt nesting level counter. 
3. Switch to System mode and save the System mode link register, which gets overwritten later. 
4. Call the registered trampoline function. 
5. On return from the trampoline function, restore the System mode link register and switch back to 
IRQ mode. 
6. Decrement the interrupt nesting level counter. 
7. Determine whether a task swap is required. A swap is needed only if the nesting level counter is 
zero and rex_best_task is not the same as rex_curr_task. 
8. If a task swap is required, do the following: 
a. Restore the SPSR and saved registers from the IRQ mode stack. 
b. Switch to Supervisor mode. 
c. Save the context of the current task on its stack.  27 Interrupt Handling  Real-Time Executive (REX)
d. Save the Supervisor mode stack pointer in the task’s TCB. 
e. Set rex_curr_task to rex_best_task. 
f. Restore the context of rex_curr_task. 
9. If a task swap is not required, restore the SPSR from the interrupt stack, restore the other registers 
saved on the interrupt stack, and return, switching back to Supervisor mode in the process.  

NOTE  In some versions of IRQ_Handler, there is no switch to System mode before calling the trampoline
function. Versions of IRQ_Handler that do not support nested interrupts do not keep track of the
interrupt nesting level. 

This sequence of actions achieves preemption since control is returned to the highest priority ready  8
task rather than the task that was running when the interrupt occurred.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值