📄 os_cpu_a.txt
字号:
;********************************************************************************************************
; uC/OS-II
; The Real-Time Kernel
;
; 68HC08 Specific code
;
; File : OS_CPU_A.S
; By : Kerby Suhre
;********************************************************************************************************
;********************************************************************************************************
; PUBLIC DECLARATIONS
;********************************************************************************************************
xdef _OSStartHighRdy
xdef _OSCtxSw
xdef _OSIntCtxSw
;********************************************************************************************************
; EXTERNAL DECLARATIONS
;********************************************************************************************************
xref _OSIntExit
xref _OSIntNesting
xref _OSPrioCur
xref _OSPrioHighRdy
xref _OSRunning
xref _OSTaskSwHook
xref _OSTCBCur
xref _OSTCBHighRdy
xref _OSTimeTick
;********************************************************************************************************
; START HIGHEST PRIORITY TASK READY-TO-RUN
;
; Description : This function is called by OSStart() to start the highest priority task that was created
; by your application before calling OSStart().
;
; Arguments : none
;
; Note(s) : 1) The stack frame is assumed to look as follows:
;
; OSTCBHighRdy->OSTCBStkPtr + 0 -->
; + 1 H
; + 2 CCR
; + 3 A
; + 4 X
; + 5 PC(H)
; + 6 PC(L)
;
; 2) OSStartHighRdy() MUST:
; a) Call OSTaskSwHook() then,
; b) Set OSRunning to TRUE,
; c) Switch to the highest priority task.
;********************************************************************************************************
_OSStartHighRdy:
jsr _OSTaskSwHook ; Invoke user defined context switch hook
lda _OSRunning ; Indicate that we are multitasking
inca
sta _OSRunning
ldx _OSTCBHighRdy ; Point to TCB of highest priority task ready to run
stx _OSTCBCur
pshx
ldx _OSTCBHighRdy+1
stx _OSTCBCur+1
pulh
lda 0,x ; Load SP
psha
ldx 1,x
pulh
txs
pulh ; Restore the H reg before RTI
rti ; Run task
;********************************************************************************************************
; INTERRUPT LEVEL CONTEXT SWITCH
;
; Description : This function is called by OSIntExit() to perform a context switch to a task that has
; been made ready-to-run by an ISR.
;
; Arguments : none
;
; Note(s) :
; 1) Stack frame upon entry:
;
; --- SP + 0 ->
; | + 1 -> PC(H) \ Return address from call to OSIntCtxSw()
; Stack pointer adjustment | + 2 -> PC(L) /
; (+4) | + 3 -> PC(H) \ Return address from call to OSIntExit()
; --> + 4 -> PC(L) /
; + 1 H \
; + 2 CCR | Stack frame from interrupt stacking.
; + 3 A |
; + 4 X |
; + 5 PC(H) |
; + 6 PC(L)/
;********************************************************************************************************
_OSIntCtxSw:
ais #11 ; Ignore return address to OSIntCtxSw() and
bra _OSIntCtxSwRtn ; return address from call to OSIntExit()
;********************************************************************************************************
; TASK LEVEL CONTEXT SWITCH
;
; Description : This function is called when a task makes a higher priority task ready-to-run.
;
; Arguments : none
;
; Note(s) : 1) Upon entry,
; OSTCBCur points to the OS_TCB of the task to suspend
; OSTCBHighRdy points to the OS_TCB of the task to resume
;
; 2) The stack frame of the task to suspend looks as follows:
;
; SP + 0 -->
; + 1 CCR
; + 2 A
; + 3 X
; + 4 PC(H)
; + 5 PC(L)
;
; 3) The stack frame of the task to resume looks as follows:
;
; OSTCBHighRdy->OSTCBStkPtr + 0 -->
; + 1 H
; + 2 CCR
; + 3 A
; + 4 X
; + 5 PC(H)
; + 6 PC(L)
;********************************************************************************************************
_OSCtxSw:
pshh ; Save H register (doesn't get save upon interrupt)
_OSIntCtxSwRtn:
tsx
pshx
pshh
ldx _OSTCBCur ; Point to current task's TCB
pshx
ldx _OSTCBCur+1 ; Point to current task's TCB
pulh
pula
sta 0,x ; Save stack pointer in preempted task's TCB
pula
sta 1,x
jsr _OSTaskSwHook ; Call user task switch hook
lda _OSPrioHighRdy ; OSPrioCur = OSPrioHighRdy
sta _OSPrioCur
ldx _OSTCBHighRdy ; Point to TCB of highest priority task ready to run
stx _OSTCBCur
pshx
ldx _OSTCBHighRdy+1
stx _OSTCBCur+1
pulh
lda 0,x ; Load SP
psha
ldx 1,x
pulh
txs
pulh ; Restore the H reg before RTI
rti ; Run task
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -