根据UCOS网站上的移植代码改编的,其中具体的使用可以参考邵贝贝翻译的UCOS教材.这个是Os_cpu_a.s
;/*
;*********************************************************************************************************
;* uC/OS-II
;* The Real-Time Kernel
;*
;*
;* (c) Copyright 1992-2005, Micrium, Weston, FL
;* All Rights Reserved
;*
;* Generic ARM Port
;*
;* File : Os_cpu_a.s
;* By : Junxiao Gao
;*
;* For : ARM7
;* Mode : ARM
;*********************************************************************************************************
;*/
EXTERN OSRunning &POSTuser_saveblog.aspHTTP/1.0p; ; External references
EXTERN OSPrioCur
EXTERN OSPrioHighRdy
EXTERN OSTCBCur
EXTERN OSTCBHighRdy
EXTERN OSIntNesting
EXTERN OSIntExit
EXTERN OSTaskSwHook
GLOBAL OSEnterInt
GLOBAL OSExitInt
GLOBAL OS_CPU_SR_Save ; Functions declared in this file
GLOBAL OS_CPU_SR_Restore
GLOBAL OSStartHighRdy
GLOBAL OSCtxSw
GLOBAL OSIntCtxSw
;定义系统模式堆栈的大小
SVC_STACK_LEGTH EQU 32
NoInt EQU 0x80
USR32Mode EQU 0x10
SVC32Mode EQU 0x13
SYS32Mode EQU 0x1f
IRQ32Mode EQU 0x12
FIQ32Mode EQU 0x11
CODE32
AREA |subr|, CODE, READONLY
OSEnterInt
MRS R0, CPSR ;get current CPU mode
ORR R0, R0, #NoInt ;set the interrupt disable mode bit
MSR CPSR_c, R0
BX LR
OSExitInt
MRS R0, CPSR ;move current processor status into reg 12
BIC R0, R0, #NoInt ;clear the interrupt disable bit
MSR CPSR_c, R0
BX LR
OS_CPU_SR_Save
MRS R0,CPSR ; Set IRQ and FIQ bits in CPSR to disable all interrupts
ORR R1,R0,#NoInt
MSR CPSR_c,R1
BX LR ; Disabled, return the original CPSR contents in R0
OS_CPU_SR_Restore
MSR CPSR_c,R0
BX LR
;/*********************************************************************************************************
;** 函数名称: OSStartHighRdy
;** 功能描述: uC/OS-II启动时使用OSStartHighRdy运行第一个任务,
;********************************************************************************************************/
OSStartHighRdy
MSR CPSR_c, #(NoInt | SYS32Mode)
;OSRunning = TRUE
LDR R4, =OSRunning
MOV R5, #1
STRB R5, [R4]
BL OSTaskSwHook
LDR R4, =OSTCBHighRdy
LDR R4, [R4]
LDR SP, [R4] ;switch to the new stack
LDR R4, [SP], #4 ;pop new task's CPSR
MSR SPSR_cxsf,R4
LDMFD SP!, {R0-R12,LR,PC}^ ;pop new task's context
;/*********************************************************************************************************
;** 函数名称: OSCtxSw
;** 功能描述: 任务切换
;********************************************************************************************************/
OSCtxSw
; SAVE CURRENT TASK CONTEXT
STMFD SP!, {LR} ; Push return address
STMFD SP!, {LR}
STMFD SP!, {R0-R12} ; Push registers
MRS R4, CPSR ; Push current CPSR
STMFD SP!, {R4}
LDR R4, =OSTCBCur ; OSTCBCur->OSTCBStkPtr = SP;
LDR R5, [R4]
STR SP, [R5]
LDR R0, =OSTaskSwHook ; OSTaskSwHook();
MOV LR, PC
BX R0
LDR R4, =OSPrioCur ; OSPrioCur = OSPrioHighRdy
LDR R5, =OSPrioHighRdy
LDRB R6, [R5]
STRB R6, [R4]
LDR R4, =OSTCBCur ; OSTCBCur = OSTCBHighRdy;
LDR R6, =OSTCBHighRdy
LDR R6, [R6]
STR R6, [R4]
LDR SP, [R6] ; SP = OSTCBHighRdy->OSTCBStkPtr;
; RESTORE NEW TASK CONTEXT
LDMFD SP!, {R4} ; Pop new task CPSR
MSR SPSR_cxsf, R4
LDMFD SP!, {R0-R12,LR,PC}^ ; Pop new task context
;/*********************************************************************************************************
;** 函数名称: OSCtxSw
;** 功能描述: 中断任务切换
;********************************************************************************************************/
OSIntCtxSw
LDR R0, =OSTaskSwHook ; OSTaskSwHook();
MOV LR, PC
BX R0
LDR R4,=OSPrioCur ; OSPrioCur = OSPrioHighRdy
LDR R5,=OSPrioHighRdy
LDRB R6,[R5]
STRB R6,[R4]
LDR R4,=OSTCBCur ; OSTCBCur = OSTCBHighRdy;
LDR R6,=OSTCBHighRdy
LDR R6,[R6]
STR R6,[R4]
LDR SP,[R6] ; SP = OSTCBHighRdy->OSTCBStkPtr;
; RESTORE NEW TASK CONTEXT
LDMFD SP!, {R4} ; Pop new task CPSR
MSR SPSR_cxsf, R4
LDMFD SP!, {R0-R12,LR,PC}^ ; Pop new task context
;/*********************************************************************************************************
;** 定义IRQ汇编接口代码宏
;********************************************************************************************************/
CODE32
AREA IRQ,CODE,READONLY
MACRO
$IRQ_Label HANDLER $OSIntNestingFlag
EXPORT $IRQ_Label ; 输出的标号
$IRQ_Label
STMFD SP!, {R1-R3} ; PUSH WORKING REGISTERS ONTO IRQ STACK
MOV R1, SP ; Save IRQ stack pointer
ADD SP, SP,#12 ; Adjust IRQ stack pointer
SUB R2, LR,#4 ; Adjust PC for return address to task
MRS R3, SPSR ; Copy SPSR (i.e. interrupted task's CPSR) to R3
MSR CPSR_c, #(NoInt | SYS32Mode) ; Change to SYS mode
; SAVE TASK'S CONTEXT ONTO TASK'S STACK
STMFD SP!, {R2} ; Push task's Return PC
STMFD SP!, {LR} ; Push task's LR
STMFD SP!, {R4-R12} ; Push task's R12-R4
LDMFD R1!, {R4-R6} ; Move task's R1-R3 from IRQ stack to SVC stack
STMFD SP!, {R4-R6}
STMFD SP!, {R0} ; Push task's R0 onto task's stack
STMFD SP!, {R3} ; Push task's CPSR (i.e. IRQ's SPSR)
; HANDLE NESTING COUNTER
LDR R0, =OSIntNesting ; OSIntNesting++;
LDRB R1, [R0]
ADD R1, R1,#1
STRB R1, [R0]
CMP R1, #1 ; if (OSIntNesting == 1) {
BNE $OSIntNestingFlag
LDR R4, =OSTCBCur ; OSTCBCur->OSTCBStkPtr = SP
LDR R5, [R4]
STR SP, [R5] ; }
MEND
MACRO
$OSIntNestingFlagLabel HANDLER1 $IRQ_Exception_Function
IMPORT $IRQ_Exception_Function ; 引用的外部标号
$OSIntNestingFlagLabel
MSR CPSR_c, #(NoInt | IRQ32Mode) ; Change to IRQ mode (to use the IRQ stack to handle interrupt)
LDR R0, =$IRQ_Exception_Function ; OS_CPU_IRQ_ISR_Handler();
MOV LR, PC
BX R0
MSR CPSR_c, #(NoInt | SYS32Mode) ; Change to SYS mode
LDR R0, =OSIntExit ; OSIntExit();
MOV LR, PC
BX R0
; RESTORE NEW TASK'S CONTEXT
LDMFD SP!, {R4} ; Pop new task's CPSR
MSR SPSR_cxsf, R4
LDMFD SP!, {R0-R12,LR,PC}^ ; Pop new task's context
MEND
;/*********************************************************************************************************
;** 定义中断句柄
;********************************************************************************************************/
CODE32
AREA IRQ,CODE,READONLY
;/* 以下添加中断句柄,用户根据实际情况改变 */
;/* Add interrupt handler here,user could change it as needed */
;/*中断*/
;/*Interrupt*/
IRQ_Handler HANDLER OSIntNestingFlag1
OSIntNestingFlag1 HANDLER1 IRQ_Exception
;/*定时器0中断*/
Timer0_Handler HANDLER OSIntNestingFlag2
OSIntNestingFlag2 HANDLER1 Timer0_Exception
;/*通用串行口0中断,使用查询,去掉中断句柄*/
;UART0_Handler HANDLER OSIntNestingFlag3
;OSIntNestingFlag3 HANDLER1 UART0_Exception
;/*通用串行口1中断*/
;UART1_Handler HANDLER OSIntNestingFlag4
;OSIntNestingFlag4 HANDLER1 UART1_Exception
END