📄 os_cpu_a.exp
字号:
; then, moving the CCR to the reserved memory location 'after' pushing all the other
; registers.
;*********************************************************************************************************
_OSCtxSw:
PUSH R0 ; Reserve space to store CCR (see below)
; PUSHALL ; Save processor registers R0 to R6
PUSH R0
PUSH R1
PUSH R2
PUSH R3
PUSH R4
PUSH R5
PUSH R6
;
STC CCR,R0L ; Save CCR onto stack ...
MOV.B R0L,R0H
MOV.W R0,@(14,SP) ; ... into reserved location
;
MOV.W @_OSTCBCur, R6 ; Save current task's SP into its TCB
MOV.W SP, @R6
;
JSR @_OSTaskSwHook ; Execute task switch hook
;
MOV.B @_OSPrioHighRdy, R1L ; OSPrioCur = OSPrioHighRdy
MOV.B R1L, @_OSPrioCur
;
MOV.W @_OSTCBHighRdy, R6 ; Get new task's SP from its TCB
MOV.W R6, @_OSTCBCur ; OSTCBCur = OSTCBHighRdy
MOV.W @R6, SP ; SP = OSTCBHighRdy->OSTCBStkPtr
;
; POPALL ; Restore processor registers R0 to R6
POP R6
POP R5
POP R4
POP R3
POP R2
POP R1
POP R0
;
RTE ; Return to task
;/*$PAGE*/
;*********************************************************************************************************
; PERFORM A CONTEXT SWITCH (From an ISR)
;
; Description : This function is called when an ISR 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.
;
; LOW MEMORY
; SP + 0 ----> R6
; + 2 R5
; + 4 R4
; + 8 R3
; + 10 R2
; + 12 R1
; + 14 R0
; + 16 CCR
; + 18 PC of task
; HIGH MEMORY
;
; 3) The stack frame of the task to resume looks as follows:
;
; LOW MEMORY
; OSTCBHighRdy->OSTCBStkPtr + 0 ----> R6
; + 2 R5
; + 4 R4
; + 8 R3
; + 10 R2
; + 12 R1
; + 14 R0
; + 16 CCR
; + 18 PC of task
; HIGH MEMORY
;*********************************************************************************************************
_OSIntCtxSw:
JSR @_OSTaskSwHook ; Execute task switch hook
;
MOV.W @_OSTCBHighRdy, R6 ; OSTCBCur = OSTCBHighRdy
MOV.W R6, @_OSTCBCur
MOV.B @_OSPrioHighRdy, R1L ; OSPrioCur = OSPrioHighRdy
MOV.B R1L, @_OSPrioCur
;
MOV.W @R6, SP ; SP = OSTCBCur->OSTCBStkPtr
;
; POPALL
POP R6
POP R5
POP R4
POP R3
POP R2
POP R1
POP R0
;
RTE
;/*$PAGE*/
;*********************************************************************************************************
; TICK ISR
;
; Note(s) : The following C-like pseudo-code describe the operation being performed in the code below.
;
; Save all registers on the current task's stack;
; OSIntNesting++;
; if (OSIntNesting == 1) {
; OSTCBCur->OSTCBStkPtr = SP
; }
; Clear the interrupt; Not needed for the timer we used.
; OSTimeTick(); Notify uC/OS-II that a tick has occured
; OSIntExit(); Notify uC/OS-II about end of ISR
; Restore all registers that were save on the current task's stack;
; Return from Interrupt;
;*********************************************************************************************************
_OSTickISR:
; PUSHALL ; Save registers of interrupted task
PUSH R0
PUSH R1
PUSH R2
PUSH R3
PUSH R4
PUSH R5
PUSH R6
;
MOV.B @_OSIntNesting, R6L ; OSIntNesting++;
INC.B R6L
MOV.B R6L, @_OSIntNesting
;
CMP.B #1,R6L ; if (OSIntNesting == 1) {
BNE _OSTickISR_1
MOV.W @_OSTCBCur, R6 ; Save current task's SP into its TCB
MOV.W SP, @R6 ;
; ; }
;
_OSTickISR_1:
; Clear interrupt! ... Not needed for the Timer we used.
;
JSR @_OSTimeTick ; Tick occurred, call kernel functions
;
JSR @_OSIntExit
_OSTickISR_2:
; POPALL
POP R6
POP R5
POP R4
POP R3
POP R2
POP R1
POP R0
;
RTE
_OSIntCOMM:
; PUSHALL
PUSH R0
PUSH R1
PUSH R2
PUSH R3
PUSH R4
PUSH R5
PUSH R6
MOV.B @_OSIntNesting, R6L ; OSIntNesting++;
INC.B R6L
MOV.B R6L, @_OSIntNesting
;
CMP.B #1,R6L ; if (OSIntNesting == 1) {
BNE _OSTickISR_1
MOV.W @_OSTCBCur, R6 ; Save current task's SP into its TCB
MOV.W SP, @R6 ;
; ; }
JSR @_INT_SCI
JSR @_OSIntExit
; POPALL
POP R6
POP R5
POP R4
POP R3
POP R2
POP R1
POP R0
RTE
.END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -