最近在整sep4020 sample代码中的核心代码,发现之前的关于中断返回的那段代码相当混乱,而且复杂,如下:
IRQ_DO
stmfd sp!, {r0,r1}
ldr r0, =0x0
str r1, [r0]
ldmfd sp!, {r0}
ldr r1, =0x0
str r0, [r1]
add r13, r13, #4 ; restore the sp_irq top to original irq top
sub r14, r14, #4
mov r0, r14
mrs r1, spsr
orr r1, r1, #0x80
msr cpsr_cxsf, r1 ; change irq mode into svc
;------------------------------------------------
bic r1, r1, #0x80 ; open the irq
stmfd sp!, {r0}
stmfd sp!, {r14}
stmfd sp!, {r1}
ldr r0, =0x0
ldr r1, [r0]
stmfd sp!, {r1}
ldr r1, =0x0
ldr r0, [r1]
stmfd sp!, {r0}
ldmfd sp!, {r0,r1}
stmfd sp!, {r0-r12} ; save the registers r0--r12
;----------------------------- ; search the irq vector and jump to isr
IMPORT IntVectorHandler
bl IntVectorHandler
;----------------------------- ; restore the register
ldmfd sp!, {r0-r12}
ldmfd sp!, {r14}
msr cpsr_cxsf, r14
ldmfd sp!, {r14}
ldmfd sp!, {pc}
它的本意可能想实现可重入的中断处理,但是在实际的代码中没有实现,反而将代码搞得复杂不堪,很多无谓的操作,以下是我修改过的不可重入的中断返回:
IRQ_DO
sub r14, r14, #4
stmfd sp!, {r14}
mrs r14, spsr
stmfd sp!, {r14}
stmfd sp!, {r0-r12}
;----------------------------- ; search the irq vector and jump to isr
IMPORT IntVectorHandler
bl IntVectorHandler
;----------------------------- ; restore the register
ldmfd sp!, {r0-r12}
ldmfd sp!, {r14}
msr spsr_csxf, r14
ldmfd sp!, {pc}^
哈哈,清晰多了,简单明了,经过简单的测试,么得问题,待会再来试试可重入中断返回。
阅读(853) | 评论(0) | 转发(0) |