📄 os_cpu_a.s
字号:
;********************************************************************************************************
; uC/OS-II
; The Real-Time Kernel
;
; (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
; All Rights Reserved
;
; File : OS_CPU_A.ASM
; By : Jean J. Labrosse
;********************************************************************************************************
;********************************************************************************************************
; ARM7 Port
;
; Target : ARM7 (Includes ARM7TDMI, ARM710T, ARM720T, ARM740T)
; Ported by : Michael Anburaj
; URL : http://geocities.com/michaelanburaj/ Email : michaelanburaj@hotmail.com
;
;********************************************************************************************************
AREA UCOS_ARM, CODE, READONLY
INCLUDE s3c4510b.s
;*********************************************************************************************************
; START MULTITASKING
; void OSStartHighRdy(void)
;
; Note : OSStartHighRdy() MUST:
; a) Call OSTaskSwHook() then,
; b) Set OSRunning to TRUE,
; c) Switch to the highest priority task.
;*********************************************************************************************************
IMPORT OSTaskSwHook
IMPORT OSRunning
IMPORT OSTCBHighRdy
IMPORT OSTCBCur
EXPORT OSStartHighRdy
OSStartHighRdy
;Call OSTaskswHook
bl OSTaskSwHook ; Call user defined task switch hook
; Get current task TCB address
ldr r4, =OSTCBCur ;point to current tcb
; Get highest priority task TCB address
ldr r5,=OSTCBHighRdy ; Get highest priority task TCB address
ldr r5,[r5] ; get stack pointer
ldr sp,[r5] ; switch to the new stack
str r5,[r4] ; set current tcb = highrdy tcb
; Set OSRunning == TRUE
ldr r4,=OSRunning ; Indicate that multitasking has started
mov r5,#1
strb r5,[r4]
ldmfd sp!,{r4} ; pop new tasks spsr
msr SPSR_cxsf,r4
ldmfd sp!,{r4} ; pop new tasks psr
msr CPSR_cxsf,r4
ldmfd sp!,{r0-r12,lr,pc} ; pop new tasks r0-r12,lr & pc
;******************************************************************************************
;******************************************************************************************
EXPORT OSIntCtxSw
OSIntCtxSw
; Interrupt Exit if higher priority task ready to run
; New Task Context switch
ldmfd sp!,{r4} ;pop tass spsr
msr SPSR_cxsf,r4
ldmfd sp!,{r4} ; pop new tasks psr
msr CPSR_cxsf,r4
LDMFD sp!,{r0-r12,lr}
LDMFD sp!,{r0-r12,lr}
SUB lr, lr, #4
mrs lr,spsr
msr cpsr_cxsf,lr
b _OSCtxSw ; perform the context switch
;*********************************************************************************************************
; PERFORM A CONTEXT SWITCH (From task level)
; void OSCtxSw(void)
;
; Note(s): Upon entry,
; OSTCBCur points to the OS_TCB of the task to suspend
; OSTCBHighRdy points to the OS_TCB of the task to resume
;
;*********************************************************************************************************
IMPORT OSTCBCur
IMPORT OSTaskSwHook
IMPORT OSTCBHighRdy
IMPORT OSPrioCur
IMPORT OSPrioHighRdy
EXPORT OSCtxSw
OSCtxSw
; Special optimised code below:
;Save Register of cpu
stmfd sp!,{lr} ; push pc (lr should be pushed in place of PC)
_OSCtxSw
stmfd sp!,{lr} ;push lr
stmfd sp!,{r0-r12} ; push register file
mrs r4,cpsr
stmfd sp!,{r4} ; push current psr
mrs r4,spsr
stmfd sp!,{r4} ; push current spsr
; OSPrioCur = OSPrioHighRdy
ldr r4,=OSPrioCur
ldr r5,=OSPrioHighRdy
ldrb r6,[r5]
strb r6,[r4]
; Get current task TCB address
ldr r4,=OSTCBCur
ldr r5,[r4]
str sp,[r5] ;存堆栈 store sp in preempted taskss TCB
bl OSTaskSwHook ; call Task Switch Hook
; Get highest priority task TCB address
ldr r6,=OSTCBHighRdy
ldr r6,[r6]
ldr sp,[r6] ;新堆栈 get new tasks stack pointer
; OSTCBCur = OSTCBHighRdy
str r6,[r4] ; set new current task TCB address
ldmfd sp!,{r4} ;弹出堆栈 pop new tasks spsr
msr SPSR_cxsf,r4
ldmfd sp!,{r4} ; pop new tasks psr
msr CPSR_cxsf,r4
IMPORT ARMEnableInt
BL ARMEnableInt
ldmfd sp!,{r0-r12,lr,pc} ; pop new tasks r0-r12,lr & pc
;--------------------------------------------------------------------------------------
;*******************************************************************************************
; OSTickISR()
;*******************************************************************************************
IMPORT OSIntEnter
IMPORT OSTimeTick
IMPORT OSIntExit
EXPORT OSTickISR
OSTickISR
STMFD sp!,{r0-r12,lr}
mrs r4,cpsr
stmfd sp!,{r4} ; push current psr
mrs r4,spsr
stmfd sp!,{r4}
bl OSIntEnter
bl OSTimeTick
bl OSIntExit
ldmfd sp!,{r4} ;pop tass spsr
msr SPSR_cxsf,r4
ldmfd sp!,{r4} ; pop new tasks psr
msr CPSR_cxsf,r4
LDMFD sp!,{r0-r12,lr}
bx lr
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -