📄 os_cpu_a.s
字号:
##########################################################################################################
## uC/OS-II
## The Real-Time Kernel
##
## M.CORE Specific code
##
## File : OS_CPU_A.S
## By : Kerby Suhre
##########################################################################################################
.file "os_cpu_a.s"
.text
.import OSIntEnter
.import OSIntExit
.import OSTimeTick
.import OSTCBCur
.import OSTCBHighRdy
.import OSPrioCur
.import OSPrioHighRdy
.import OSTTaskSwHook
.import OSRunning
#######################################################################
#### Procedure : OSStartHighRdy ###
#### ###
#### The procedure gets the highest priority task then loads its ###
#### stack before restoring all of the registers and doing an RTE ###
#### to actually start the task. Called directly from uC/OS ###
#######################################################################
.export OSStartHighRdy
.align 4
OSStartHighRdy:
lrw r1,OSRunning ## Set OSRunning to (1)
movi r2,1
stb r2,(r1)
lrw r1,OSTCBHighRdy ## Get highest priority task and make
lrw r2,OSTCBCur ## it the current task
ldw r3,(r1)
stw r3,(r2)
br OSStartHighRdyReturn
#######################################################################
#### Procedure : OSCtxSw ###
#### ###
#### The procedure is installed as an interrupt handler and called ###
#### using a TRAP instruction within the uC/OS scheduler to swap ###
#### contexts at the task level. ###
#######################################################################
.export OSCtxSw
.align 4
OSCtxSw:
subi r0,32 ## Decrement SP to save registers
subi r0,28 ## Decrement SP to save registers
stm r1-r15,(r0) ## Save all registers to the stack
subi r0,8 ## Decrement SP to save PC and PSR
mfcr r1,EPC ## Save the PC for the current task
addi r1,2 ## Add 2 to PC to get past TRAP
## instruction when returning
stw r1,(r0,0)
mfcr r1,EPSR ## Save the PSR for the current task
stw r1,(r0,4)
OSIntCtxSwReturn:
lrw r1,OSPrioHighRdy ## Copy the highest priority to the
lrw r2,OSPrioCur ## current
ldb r3,(r1)
stb r3,(r2)
lrw r2,OSTCBCur ## Save the current task SP in the TCB
ldw r3,(r2)
stw r0,(r3)
lrw r1,OSTCBHighRdy ## Get highest priority task and make
ldw r3,(r1) ## it the current task
stw r3,(r2)
OSStartHighRdyReturn:
jbsr OSTaskSwHook ## Call task switch hook
ldw r0,(r3) ## Get current task stack pointer
ldw r1,(r0,0) ## Get the PC for the task
mtcr r1,EPC
ldw r1,(r0,4) ## Get the PSR for the task
mtcr r1,EPSR
addi r0,8 ## Increment SP past the PC and PSR
ldm r1-r15,(r0) ## Load all registers from the stack
addi r0,32 ## Increment SP past the registers
addi r0,28 ## Increment SP past the registers
rte ## Return to new task
#######################################################################
#### Procedure : OSIntCtxSw ###
#### ###
#### The procedure is called by when the uC/OS wants to return to ###
#### a different task at interrupt time. Used primarily within the ###
#### timer tick interrupt. ###
#######################################################################
.export OSIntCtxSw
.align 4
OSIntCtxSw:
addi r0,8 ## Stack adjustment for calls to
## OSIntExit, OSIntCtxSw and locals
## The interrupt context save and the full register set must
## be on the stack in the correct order prior to the OSIntExit call
br OSIntCtxSwReturn
#######################################################################
#### Procedure : OSTickISR ###
#### ###
#### The procedure is installed as the timer tick ISR. ###
#### It stores the current context before calling the uC/OS int ###
#### nesting logic and timer tick routine which can cause the ###
#### context to change. Use this as an example of how to write ###
#### ISRs in uC/OS. ###
#######################################################################
.export OSTickISR
.align 4
OSTickISR:
subi r0,32 ## Decrement SP to save registers
subi r0,28 ## Decrement SP to save registers
stm r1-r15,(r0) ## Save all registers to the stack
subi r0,8 ## Decrement SP to save PC and PSR
mfcr r1,EPC ## Save the PC for the current task
stw r1,(r0,0)
mfcr r1,EPSR ## Save the PSR for the current task
stw r1,(r0,4)
PCSR=0x00c80000 ## ITCSR=0x10001024
PCSR_PIF=0x2 ## ITCSR_ITIF=0x00000004
lrw r1,PCSR ## Acknowledge the PIT timer interrupt
ldw r2,(r1)
bseti r2,PCSR_PIF
stw r2,(r1)
jbsr OSIntEnter
jbsr OSTimeTick
jbsr OSIntExit
ldw r1,(r0,4) ## Get the PSR for the task
mtcr r1,EPSR
ldw r1,(r0,0) ## Get the PC for the task
mtcr r1,EPC
addi r0,8 ## Increment SP past the PC and PSR
ldm r1-r15,(r0) ## Load all registers from the stack
addi r0,28 ## Increment SP past the registers
addi r0,32 ## Increment SP past the registers
rte
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -