📄 os_cpu_a.s90
字号:
;
; 2) OSStartHighRdy() MUST:
; a) Call OSTaskSwHook() then,
; b) Set OSRunning to TRUE,
; c) Switch to the highest priority task.
;********************************************************************************************************
OSStartHighRdy: CALL OSTaskSwHook ; Invoke user defined context switch hook
LDS R16,OSRunning ; Indicate that we are multitasking
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+ ;
POPSP ; Restore stack pointer
POPSREG ; Restore status register
POPRS ; Restore all registers
RET ; Start task
;********************************************************************************************************
; 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 --> LSB of (return) stack pointer (Low memory)
; SPH of (return) stack pointer
; Flags to load in status register
; R31
; R30
; R7
; .
; .
; .
; R0 (High memory)
;********************************************************************************************************
OSCtxSw: PUSHRS ; Save current task's context
PUSHSREG
PUSHSP
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+ ;
POPSP ; Restore stack pointer
POPSREG ; Restore status register
POPRS ; Restore all registers
RET
;*********************************************************************************************************
; 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:
;
; SP+0 --> LSB of return address of OSIntCtxSw() (Low memory)
; +1 MSB of return address of OSIntCtxSw()
; +2 LSB of return address of OSIntExit()
; +3 MSB of return address of OSIntExit()
; +4 LSB of task code address
; +5 MSB of task code address (High memory)
;
; 3) The saved context of the task to resume looks as follows:
;
; OSTCBHighRdy->OSTCBStkPtr --> LSB of (return) stack pointer (Low memory)
; SPH of (return) stack pointer
; Flags to load in status register
; R31
; R30
; R7
; .
; .
; .
; R0 (High memory)
;*********************************************************************************************************
OSIntCtxSw: IN R30,SPL ; Z = SP
IN R31,SPH
; ADIW R30,4 ; (Uncomment if OS_CRITICAL_METHOD is 1, see OS_CPU.H)
ADIW R30,5 ; Adjust Z to point to task return address
ST -Y,R31 ; Save SP
ST -Y,R30 ;
LDS R30,OSTCBCur ; Z = OSTCBCur->OSTCBStkPtr
LDS R31,OSTCBCur+1 ;
ST Z+,R28 ; Save Y pointer
ST Z+,R29 ;
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+ ;
POPSP ; Restore stack pointer
POPSREG ; Restore status register
POPRS ; Restore all registers
RET
;********************************************************************************************************
; SYSTEM TICK ISR
;
; Description : This function is the ISR used to notify uC/OS-II that a system tick has occurred.
;
;
;********************************************************************************************************
OSTickISR: PUSHRS ; Save all registers and status register
IN R16,SREG
SBR R16,0x80 ; Set interrupt bit in status reg and save
ST -Y,R16
LDI R16,256-(4000000/50/1024) ; Reload timer to overflow at a rate of 50Hz
OUT TCNT0,R16 ; at a prescaler of 1024 and 4.0 MHz AVR clock
LDS R16,OSIntNesting ; Notify uC/OS-II of ISR
INC R16 ;
STS OSIntNesting,R16 ;
SEI
CALL OSTimeTick ; Call uC/OS-II's tick updating function
CALL OSIntExit ; Notify uC/OS-II about end of ISR
POPSREG ; Restore status register
POPRS ; Restore all registers
RET ; Note: RET instead of RETI
;********************************************************************************************************
; INTVEC
;
; Description : Set up the AVR interrupt vector table so that the TIMER0 overflow interrupt
; vectors to the function above.
;
;********************************************************************************************************
COMMON INTVEC
DS 16*4
JMP OSTickISR
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -