📄 os_cpu_a.src
字号:
MOV R2,[R5] ; Get "current" IP
MOV R4,DPP1 ; Get "current" DPP1
EXTP R7,#02h ; Save this task's interrupt context in task user stack
MOV [R6+#02h],R1 ; Task CSP
MOV [R6+#04h],R2 ; Task IP
EXTP R7,#03h
MOV [R6+#06h],R3 ; Task STATUS
MOV [R6+#08h],R4 ; Task DPP1
MOV [R6+#0Ah],R0 ; Task R0
MOV R9,#SOF _ADDR02 ; Call user defined task switch hook
MOV [-R0],R9
MOV R9,#SEG _ADDR02
MOV [-R0],R9
JMPS SEG( _OSTaskSwHook),SOF( _OSTaskSwHook)
_ADDR02:
EXTP #PAG (_OSTCBHighRdy),#02h ; OSTCBCur = OSTCBHighRdy
MOV R8,POF (_OSTCBHighRdy)
MOV R9,POF (_OSTCBHighRdy+2)
EXTP #PAG (_OSTCBCur),#02h
MOV POF (_OSTCBCur),R8
MOV POF (_OSTCBCur+2),R9
EXTP #PAG _OSPrioHighRdy,#01h ; OSPrioCur = OSPrioHighRdy;
MOVB RL1,POF _OSPrioHighRdy
EXTP #PAG _OSPrioCur,#01h
MOVB POF _OSPrioCur,RL1
EXTP R9,#02h ; Get the stack pointer of the task to resume
MOV R6,[R8+] ; R7:R6 = OSTCBHighRdy->OSTCBStkPtr
MOV R7,[R8]
EXTP R7,#02h ; Get & Initialise task's context from TCB
MOV R1,[R6+#02h] ; Task CSP
MOV R2,[R6+#04h] ; Task IP
EXTP R7,#03h
MOV R3,[R6+#06h] ; Task STATUS
MOV R4,[R6+#08h] ; Task DPP1
MOV R0,[R6+#0Ah] ; Task R0
MOV DPP1,R4
MOV [R5+#04h],R3 ; Load "saved" PSW
MOV [R5+#02h],R1 ; Load "saved" CSP
MOV [R5],R2 ; Load "saved" IP
MOV R1,[R0+] ; Restore MDL
MOV MDL,R1 ;
MOV R1,[R0+] ; Restore MDH
MOV MDH,R1 ;
MOV R1,[R0+] ; Restore MDC
MOV MDC,R1 ;
MOV R1,[R0+] ; Restore DPP0
MOV DPP0,R1 ;
MOV R1,[R0+] ; Restore DPP2
MOV DPP2,R1 ;
MOV R1,[R0+] ; Restore DPP3
MOV DPP3,R1 ;
MOV R1,[R0+] ; Restore CP
MOV CP,R1 ;
NOP
MOV R15,[R0+] ; Restore R15
MOV R14,[R0+] ; Restore R14
MOV R13,[R0+] ; Restore R13
MOV R12,[R0+] ; Restore R12
MOV R11,[R0+] ; Restore R11
MOV R10,[R0+] ; Restore R10
MOV R9,[R0+] ; Restore R9
MOV R8,[R0+] ; Restore R8
MOV R7,[R0+] ; Restore R7
MOV R6,[R0+] ; Restore R6
MOV R5,[R0+] ; Restore R5
MOV R4,[R0+] ; Restore R4
MOV R3,[R0+] ; Restore R3
MOV R2,[R0+] ; Restore R2
MOV R1,[R0+] ; Restore R1; Restore all processor registers from the new task's stack
RETI
_OSIntCtxSw ENDP
UCOS_C16X ENDS
;********************************************************************************************************
; HANDLE TICK ISR
; void OSTickISR (void)
;
; Description: This function is called every 10ms
;
; Arguments : none
;
; Returns : none
;
; Note(s) : The following C-like pseudo-code describe the operation being performed in the code below.
;
; Disable interrupts;
; Save all registers on the current task's stack;
; OSIntEnter();
; OSTimeTick(); Notify uC/OS-II that a tick has occured
; Clear RTC or Timer Interrupt Response Bit
; OSIntExit(); Notify uC/OS-II about end of ISR
; Restore all registers that were save on the current task's stack;
; Enable interrupts;
; Return from Interrupt;
;********************************************************************************************************
UCOS_C16X SECTION CODE
_OSTickISR PROC TASK UCOS_OSTickISR INTNO=23h
BCLR IEN ; Disable interrupts
; Total execution time : xx states.
MOV [-R0],R1 ; Save R1
MOV [-R0],R2 ; Save R2
MOV [-R0],R3 ; Save R3
MOV [-R0],R4 ; Save R4
MOV [-R0],R5 ; Save R5
MOV [-R0],R6 ; Save R6
MOV [-R0],R7 ; Save R7
MOV [-R0],R8 ; Save R8
MOV [-R0],R9 ; Save R9
MOV [-R0],R10 ; Save R10
MOV [-R0],R11 ; Save R11
MOV [-R0],R12 ; Save R12
MOV [-R0],R13 ; Save R13
MOV [-R0],R14 ; Save R14
MOV [-R0],R15 ; Save R15
MOV R4,CP ; Get Context Pointer (CP)
MOV [-R0],R4 ; Put it on the user stack
MOV R4,DPP3 ; Get Data Page Pointer 3 (DPP3)
MOV [-R0],R4 ; Put it on the user stack
MOV R4,DPP2 ; Get Data Page Pointer 2 (DPP2)
MOV [-R0],R4 ; Put it on the user stack
MOV R4,DPP0 ; Get Data Page Pointer 0 (DPP0)
MOV [-R0],R4 ; Put it on the user stack
MOV R4,MDC ; Get Multiply/Divide Control (MDC)
MOV [-R0],R4 ; Put it on the user stack
MOV R4,MDH ; Get Multiply/Divide High (MDH)
MOV [-R0],R4 ; Put it on the user stack
MOV R4,MDL ; Get Multiply/Divide Low (MDL)
MOV [-R0],R4 ; Put it on the user stack; Save current task's context
MOV R9,#SOF _ADDR03 ; call OSIntEnter();
MOV [-R0],R9
MOV R9,#SEG _ADDR03
MOV [-R0],R9
JMPS SEG (_OSIntEnter), SOF(_OSIntEnter)
_ADDR03: MOV R9,#SOF _ADDR04 ; call OSTimeTick();
MOV [-R0],R9
MOV R9,#SEG _ADDR04
MOV [-R0],R9
JMPS SEG (_OSTimeTick), SOF(_OSTimeTick)
_ADDR04: EXTR #1
MOV R9,#SOF _ADDR05 ; call OSIntExit();
MOV [-R0],R9
MOV R9,#SEG _ADDR05
MOV [-R0],R9
JMPS SEG (_OSIntExit), SOF(_OSIntExit)
_ADDR05: MOV R1,[R0+] ; Restore MDL
MOV MDL,R1 ;
MOV R1,[R0+] ; Restore MDH
MOV MDH,R1 ;
MOV R1,[R0+] ; Restore MDC
MOV MDC,R1 ;
MOV R1,[R0+] ; Restore DPP0
MOV DPP0,R1 ;
MOV R1,[R0+] ; Restore DPP2
MOV DPP2,R1 ;
MOV R1,[R0+] ; Restore DPP3
MOV DPP3,R1 ;
MOV R1,[R0+] ; Restore CP
MOV CP,R1 ;
NOP
MOV R15,[R0+] ; Restore R15
MOV R14,[R0+] ; Restore R14
MOV R13,[R0+] ; Restore R13
MOV R12,[R0+] ; Restore R12
MOV R11,[R0+] ; Restore R11
MOV R10,[R0+] ; Restore R10
MOV R9,[R0+] ; Restore R9
MOV R8,[R0+] ; Restore R8
MOV R7,[R0+] ; Restore R7
MOV R6,[R0+] ; Restore R6
MOV R5,[R0+] ; Restore R5
MOV R4,[R0+] ; Restore R4
MOV R3,[R0+] ; Restore R3
MOV R2,[R0+] ; Restore R2
MOV R1,[R0+] ; Restore R1; Restore new task's context
BSET IEN ; Enable interrupts
RETI ; Return to interrupted task
_OSTickISR ENDP
UCOS_C16X ENDS
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -