📄 os_cpu_a.s
字号:
INC R16 ;
STS _OSRunning,R16 ;
LDS R30,_OSTCBHighRdy ; Let Z point to TCB of highest priority task
LDS R31,_OSTCBHighRdy+1 ; ready to run
LD R28,Z+ ; Load Y (R29:R28) pointer
LD R29,Z+ ;
POP_SP ; Restore stack pointer
POP_SREG ; Restore status register
POP_ALL ; Restore all registers
RET ; Start task
;/*$PAGE*/.
;********************************************************************************************************
; TASK LEVEL CONTEXT SWITCH
;
; Description : This function is called when a task makes a higher priority task ready-to-run.
;
; 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 --> LSB of task code address
; +1 MSB of task code address (High memory)
;
; 3) The saved context of the task to resume looks as follows:
;
; OSTCBHighRdy->OSTCBStkPtr --> SPL of (return) stack pointer (Low memory)
; SPH of (return) stack pointer
; Flags to load in status register
; R31
; R30
; R27
; .
; .
; R0
; PCH
; PCL (High memory)
;********************************************************************************************************
_OSCtxSw::
PUSH_ALL ; Save current task's context
PUSH_SREG
PUSH_SP
LDS R30,_OSTCBCur ; Z = OSTCBCur->OSTCBStkPtr
LDS R31,_OSTCBCur+1 ;
ST Z+,R28 ; Save Y (R29:R28) pointer
ST Z+,R29 ;
CALL _OSTaskSwHook ; Call user defined task switch hook
LDS R16,_OSPrioHighRdy ; OSPrioCur = OSPrioHighRdy
STS _OSPrioCur,R16
LDS R30,_OSTCBHighRdy ; Let Z point to TCB of highest priority task
LDS R31,_OSTCBHighRdy+1 ; ready to run
STS _OSTCBCur,R30 ; OSTCBCur = OSTCBHighRdy
STS _OSTCBCur+1,R31 ;
LD R28,Z+ ; Restore Y pointer
LD R29,Z+ ;
POP_SP ; Restore stack pointer
POP_SREG ; Restore status register
POP_ALL ; Restore all registers
RET
;/*$PAGE*/.
;*********************************************************************************************************
; 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.
;
; 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:
;
; OSTCBCur->OSTCBStkPtr ------> SPL of (return) stack pointer (Low memory)
; SPH of (return) stack pointer
; Flags to load in status register
; R31
; R30
; R27
; .
; .
; R0
; PCH
; PCL (High memory)
;
; 3) The saved context of the task to resume looks as follows:
;
; OSTCBHighRdy->OSTCBStkPtr --> SPL of (return) stack pointer (Low memory)
; SPH of (return) stack pointer
; Flags to load in status register
; R31
; R30
; R27
; .
; .
; R0
; PCH
; PCL (High memory)
;*********************************************************************************************************
_OSIntCtxSw::
CALL _OSTaskSwHook ; Call user defined task switch hook
LDS R16,_OSPrioHighRdy ; OSPrioCur = OSPrioHighRdy
STS _OSPrioCur,R16 ;
LDS R30,_OSTCBHighRdy ; Z = OSTCBHighRdy->OSTCBStkPtr
LDS R31,_OSTCBHighRdy+1 ;
STS _OSTCBCur,R30 ; OSTCBCur = OSTCBHighRdy
STS _OSTCBCur+1,R31 ;
LD R28,Z+ ; Restore Y pointer
LD R29,Z+ ;
POP_SP ; Restore stack pointer
POP_SREG ; Restore status register
POP_ALL ; Restore all registers
RET
;/*$PAGE*/.
;********************************************************************************************************
; SYSTEM TICK ISR
;
; Description : This function is the ISR used to notify uC/OS-II that a system tick has occurred.
;
; The following C-like pseudo-code describe the operation being performed in the code below.
;
; Save all registers on the current task's stack:
; Use the PUSH_ALL macro
; Get the SREG, set Bit #7 and save onto the task's stack using -Y addressing
; Use the PUSH_SP macro to save the task's hardware stack pointer onto 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:
; Use the POP_SP macro to restore the task's hardware stack pointer
; Use the POP_SREG macro to restore the SREG register
; Use the POP_ALL macro to restore the remaining registers
; Return (DO NOT use a RETI instruction);
;********************************************************************************************************
_OSTickISR::
PUSH_ALL ; Save all registers and status register
IN R16,SREG ; Save the SREG but with interrupts enabled
SBR R16,BIT07
ST -Y,R16
PUSH_SP ; Save the task's hardware stack pointer onto task's stack
LDS R16,_OSIntNesting ; Notify uC/OS-II of ISR
INC R16 ;
STS _OSIntNesting,R16 ;
CPI R16,1 ; if (OSIntNesting == 1) {
BRNE OSTickISR_1
LDS R30,_OSTCBCur ; OSTCBCur->OSTCBStkPtr = Y
LDS R31,_OSTCBCur+1
ST Z+,R28
ST Z+,R29 ; }
OSTickISR_1:
CALL _OSTickISR_Handler ; Handle the tick ISR
CALL _OSIntExit ; Notify uC/OS-II about end of ISR
POP_SP ; Restore the hardware stack pointer from task's stack
POP_SREG ; Restore the SREG register
POP_ALL ; Restore all registers
RET ; Note: RET instead of RETI
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -