问题是出在uCOS临界段的时候,进入临界段时正常,但退出临界段的时候就飞了.下面是代码:
OS_ENTER_CRITICAL();
OSTime = ticks;
OS_EXIT_CRITICAL();
我将上面三条反汇编如下:
OS_ENTER_CRITICAL();
[0xeb000b31] bl ARMDisableInt
OSTime = ticks;
[0xe59f0018] ldr r0,0x00004704 ; = #0x0c001800
[0xe5804000] str r4,[r0,#0]
OS_EXIT_CRITICAL();
[0xe8bd4010] ldmfd r13!,{r4,r14}
[0xea000b32] b ARMEnableInt
[0x0c0017f0] dcd 0x0c0017f0 ....
[0x0c001804] dcd 0x0c001804 ....
[0x0c0017d6] dcd 0x0c0017d6 ....
[0x0c002bcc] dcd 0x0c002bcc .+..
[0x0c001800] dcd 0x0c001800 ....
ARMDisableInt及ARMEnableInt代码在下面.
EXPORT ARMDisableInt
ARMDisableInt
MRS r0, cpsr
STMFD sp!, {r0} ; push current PSR (r0 = 0x60000013)
ORR r0, r0, #0xC0
MSR cpsr_c, r0 ; disable IRQ Int s
MOV pc, lr
EXPORT ARMEnableInt
ARMEnableInt
LDMFD sp!, {r0} ; pop current PSR (r0 = 0x0000494c)
MSR cpsr_c, r0 ; restore original cpsr
MOV pc, lr
我发现具体原因是在ARMEnableInt的
LDMFD sp!, {r0}
这一条语句.上面我用红色部分突出了,r0入栈的值也出栈的值不一样,这样就导致出错.
好几天了一直找不到为什么r0出栈值会与入栈不同.怀疑是堆栈深度不够,我又修改了堆栈
AREA RamData, DATA, READWRITE
^ (_ISR_STARTADDRESS-0x500)
;UserStack # 256 ;c1(c7)ffa00
;SVCStack # 256 ;c1(c7)ffb00
;UndefStack # 256 ;c1(c7)ffc00
;AbortStack # 256 ;c1(c7)ffd00
;IRQStack # 256 ;c1(c7)ffe00
;FIQStack # 0 ;c1(c7)fff00
UserStack # 512 ;c1(c7)ffa00
SVCStack # 512 ;c1(c7)ffb00
UndefStack # 512 ;c1(c7)ffc00
AbortStack # 512 ;c1(c7)ffd00
IRQStack # 512 ;c1(c7)ffe00
FIQStack # 0 ;c1(c7)fff00
但还是出现同样的问题(r0出栈值还是与入栈时不一样).
特来求助大家!先谢了 |