自己试了一次,很多问题,没成功。
那位在real view下成功过,请发一份代码到checkcode@126.com
我想参考一下,第一次接触ucos,有点吃力。
5月份时好像就有人发过,
建议用freertos,功能基本相同,但freertos是开源软件,
想用freertos的话,可以去我空间看看,(EDN的空间),那讲过如何移植,
我在IAR下面成功过
直接用例子不要修改,下载下去看一下是否能成功,
re
官方的例子不太好,不能中断嵌套,所有中断必须在同一优先级别,官方例子都是0,主要是在双堆栈指针使用上有问题
用下面两段代码替换就没问题了,也不存在原来有人说使用不同优化级别编译会死机的问题
OSStartHighRdy
LDR R0, =NVIC_SYSPRI2 ; Set the PendSV exception priority
LDR R1, =NVIC_PENDSV_PRI
STRB R1, [R0]
;MOVS R0, #0 ; Set the PSP to 0 for initial context switch call
;MSR PSP, R0
MRS R0, MSP
MSR PSP, R0
MRS R0, CONTROL
ORR R0, R0, #0x02
MSR CONTROL, R0
LDR R1, __OS_TCBCur
MRS R0, PSP
SUBS R0, R0, #0x24
STR R0, [R1]
LDR R0, __OS_Running ; OSRunning = TRUE
MOVS R1, #1
STRB R1, [R0]
LDR R0, =NVIC_INT_CTRL ; Trigger the PendSV exception (causes context switch)
LDR R1, =NVIC_PENDSVSET
STR R1, [R0]
CPSIE I ; Enable interrupts at processor level
OSStartHang
NOP
B OSStartHang ;Should never get here
OSPendSV
MRS R0, PSP ; PSP is process stack pointer
;CBZ R0, OSPendSV_nosave ; skip register save the first time
SUBS R0, R0, #0x20 ; save remaining regs r4-11 on process stack
STM R0, {R4-R11}
LDR R1, __OS_TCBCur ; OSTCBCur->OSTCBStkPtr = SP;
LDR R1, [R1]
STR R0, [R1] ; R0 is SP of process being switched out
; at this point, entire context of process has been saved
OSPendSV_nosave
PUSH {R14} ; need to save LR exc_return value
LDR R0, __OS_TaskSwHook ; OSTaskSwHook();
BLX R0
POP {R14}
LDR R0, __OS_PrioCur ; OSPrioCur = OSPrioHighRdy;
LDR R1, __OS_PrioHighRdy
LDRB R2, [R1]
STRB R2, [R0]
LDR R0, __OS_TCBCur ; OSTCBCur = OSTCBHighRdy;
LDR R1, __OS_TCBHighRdy
LDR R2, [R1]
STR R2, [R0]
LDR R0, [R2] ; R0 is new process SP; SP = OSTCBHighRdy->OSTCBStkPtr;
LDM R0, {R4-R11} ; restore r4-11 from new process stack
ADDS R0, R0, #0x20
MSR PSP, R0 ; load PSP with new process SP
;ORR LR, LR, #0x04 ; ensure exception return uses process stack
BX LR
在realview上下载了一个例子
例子例说明用2.85的ucos,我把ucos拷进去,可是还是有错误,
哪位高手帮着看一下,郁闷,
..osos_core.c(592): error: #136: struct "os_tcb" has no field "OSTCBStatPend"
..osos_core.c(592): error: #20: identifier "OS_STAT_PEND_TO" is undefined
..osos_core.c(594): error: #136: struct "os_tcb" has no field "OSTCBStatPend"
..osos_core.c(594): error: #20: identifier "OS_STAT_PEND_OK" is undefined
..osos_core.c(677): error: #147-D: declaration is incompatible with "INT8U OS_EventTaskRdy(OS_EVENT *, void *, INT8U)" (declared at line 1155 of "..osucos_ii.h")
..osos_core.c(728): error: #136: struct "os_tcb" has no field "OSTCBStatPend"
..osos_core.c(794): error: #136: struct "os_tcb" has no field "OSTCBStatPend"
..osos_core.c(794): error: #20: identifier "OS_STAT_PEND_OK" is undefined
..osos_core.c(1554): error: #136: struct "os_tcb" has no field "OSTCBStatPend"
..osos_core.c(1554): error: #20: identifier "OS_STAT_PEND_OK" is undefined
..osos_core.c(1628): error: #20: identifier "OS_ERR_NONE" is undefined
..osos_core.c(1631): error: #20: identifier "OS_ERR_TASK_NO_MORE_TCB" is undefined
..osos_mbox.c(201): error: #20: identifier "OS_ERR_NONE" is undefined
..osos_mbox.c(212): error: #20: identifier "OS_STAT_PEND_OK" is undefined
..osos_mbox.c(226): error: #20: identifier "OS_ERR_NONE" is undefined
..osos_mbox.c(310): error: #20: identifier "OS_ERR_NONE" is undefined
..osos_mbox.c(314): error: #136: struct "os_tcb" has no field "OSTCBStatPend"
..osos_mbox.c(314): error: #20: identifier "OS_STAT_PEND_OK" is undefined
..osos_mbox.c(320): error: #136: struct "os_tcb" has no field "OSTCBStatPend"
..osos_mbox.c(321): error: #136: struct "os_tcb" has no field "OSTCBStatPend"
..osos_mbox.c(325): error: #20: identifier "OS_STAT_PEND_TO" is undefined
..osos_mbox.c(327): error: #20: identifier "OS_ERR_TIMEOUT" is undefined
..osos_mbox.c(330): error: #20: identifier "OS_STAT_PEND_ABORT" is undefined
..osos_mbox.c(331): error: #20: identifier "OS_ERR_PEND_ABORT" is undefined
..osos_mbox.c(341): error: #20: identifier "OS_ERR_NONE" is undefined
..osos_mbox.c(474): error: #20: identifier "OS_STAT_PEND_OK" is undefined
..osos_mbox.c(477): error: #20: identifier "OS_ERR_NONE" is undefined
..osos_mbox.c(481): error: #20: identifier "OS_ERR_MBOX_FULL" is undefined
..osos_mbox.c(485): error: #20: identifier "OS_ERR_NONE" is undefined
..osos_mbox.c(546): error: #20: identifier "OS_STAT_PEND_OK" is undefined
程序开始挺好使
我的代码变大以后就不行了,
Program Size: Code=37618 RO-data=18154 RW-data=348 ZI-data=8132
程序死了,跑到这里
HardFault_Handler
PROC
EXPORT HardFault_Handler [WEAK]
B .
ENDP
这时有问题的asm文件
OS_CPU_PendSVHandler_nosave
PUSH {R14} ; Save LR exc_return value
LDR R0, =OSTaskSwHook ; OSTaskSwHook();
BLX R0
POP {R14}
LDR R0, =OSPrioCur ; OSPrioCur = OSPrioHighRdy;
LDR R1, =OSPrioHighRdy
LDRB R2, [R1]
STRB R2, [R0]
LDR R0, =OSTCBCur ; OSTCBCur = OSTCBHighRdy;
LDR R1, =OSTCBHighRdy
LDR R2, [R1]
STR R2, [R0]
LDR R0, [R2] ; R0 is new process SP; SP = OSTCBHighRdy->OSTCBStkPtr;
;在这里出的错
LDM R0, {R4-R11} ; Restore r4-11 from new process stack
ADDS R0, R0, #0x20
MSR PSP, R0 ; Load PSP with new process SP
ORR LR, LR, #0x04 ; Ensure exception return uses process stack
CPSIE I
BX LR ; Exception return will restore remaining context
END
neaphy:我的系统也是不能设置不同的优先级,只能都设为0 。我按照你给的代码作了修改,还是不行,直接就fault.能不能把你完整的代码发给我?谢谢
我的邮箱是
shenmon@tom.com