os-task-switch.lst
来自「ucos-ii-at90S-icc-avr」· LST 代码 · 共 1,781 行 · 第 1/5 页
LST
1,781 行
__start:
__text_start:
0010 E5CF LDI R28,0x5F
0011 E0D2 LDI R29,2
0012 BFCD OUT P3D,R28
0013 BFDE OUT P3E,R29
0014 51C0 SUBI R28,0x10
0015 40D0 SBCI R29,0
0016 EA0A LDI R16,0xAA
0017 8308 STD R16,0+Y
0018 2400 CLR R0
0019 E6E0 LDI R30,0x60
001A E0F0 LDI R31,0
001B E012 LDI R17,2
001C 30E1 CPI R30,1
001D 07F1 CPC R31,R17
001E F011 BEQ 0x0021
001F 9201 ST R0,Z+
0020 CFFB RJMP 0x001C
0021 8300 STD R16,0+Z
0022 E2E0 LDI R30,0x20
0023 E0F0 LDI R31,0
0024 E6A0 LDI R26,0x60
0025 E0B0 LDI R27,0
0026 E010 LDI R17,0
0027 32E0 CPI R30,0x20
0028 07F1 CPC R31,R17
0029 F021 BEQ 0x002E
002A 95C8 LPM
002B 9631 ADIW R30,1
002C 920D ST R0,X+
002D CFF9 RJMP 0x0027
002E D04F RCALL _main
_exit:
002F CFFF RJMP _exit
FILE: H:\编程2002-10-15-HOME\做过的项目\2002-10-22\home-c\software\UCOS-II\ucos2_iccavr\iccavr\os-task-switch\os_cpu_a.s
(0001) ;*******************************************************************************
(0002) ; uC/OS-II
(0003) ; The Real-Time Kernel
(0004) ;
(0005) ; AT90 Specific code
(0006) ; (ICC V6.21)
(0007) ;
(0008) ;
(0009) ; File: OS_CPU_A.S
(0010) ; By:
(0011) ; Modified by:
(0012) ; Port Version: V1.00
(0013) ;
(0014) ;
(0015) ;*******************************************************************************
(0016)
(0017) ;include
(0018)
(0019) ;*******************************************************************************
(0020) ; I/O PORT ADDRESSES
(0021) ;*******************************************************************************
(0022)
(0023) SREG =0x3F
(0024) SPH =0x3E
(0025) SPL =0x3D
(0026) TCNT0 =0x32
(0027)
(0028) PIND = 0x10
(0029) PORTD = 0x12
(0030)
(0031) ;*******************************************************************************
(0032) ; MACROS
(0033) ;*******************************************************************************
(0034)
(0035) ; Push registers
(0036) .macro PUSHRS
(0037) ST -Y,R0
(0038) ST -Y,R1
(0039) ST -Y,R2
(0040) ST -Y,R3
(0041) ST -Y,R4
(0042) ST -Y,R5
(0043) ST -Y,R6
(0044) ST -Y,R7
(0045) ST -Y,R8
(0046) ST -Y,R9
(0047) ST -Y,R10
(0048) ST -Y,R11
(0049) ST -Y,R12
(0050) ST -Y,R13
(0051) ST -Y,R14
(0052) ST -Y,R15
(0053) ST -Y,R16
(0054) ST -Y,R17
(0055) ST -Y,R18
(0056) ST -Y,R19
(0057) ST -Y,R20
(0058) ST -Y,R21
(0059) ST -Y,R22
(0060) ST -Y,R23
(0061) ST -Y,R24
(0062) ST -Y,R25
(0063) ST -Y,R26
(0064) ST -Y,R27
(0065) ST -Y,R30
(0066) ST -Y,R31
(0067) .endmacro
(0068)
(0069) ; Pop registers
(0070) .macro POPRS
(0071) LD R31,Y+
(0072) LD R30,Y+
(0073) LD R27,Y+
(0074) LD R26,Y+
(0075) LD R25,Y+
(0076) LD R24,Y+
(0077) LD R23,Y+
(0078) LD R22,Y+
(0079) LD R21,Y+
(0080) LD R20,Y+
(0081) LD R19,Y+
(0082) LD R18,Y+
(0083) LD R17,Y+
(0084) LD R16,Y+
(0085) LD R15,Y+
(0086) LD R14,Y+
(0087) LD R13,Y+
(0088) LD R12,Y+
(0089) LD R11,Y+
(0090) LD R10,Y+
(0091) LD R9,Y+
(0092) LD R8,Y+
(0093) LD R7,Y+
(0094) LD R6,Y+
(0095) LD R5,Y+
(0096) LD R4,Y+
(0097) LD R3,Y+
(0098) LD R2,Y+
(0099) LD R1,Y+
(0100) LD R0,Y+
(0101) .endmacro
(0102)
(0103) ; Push stack pointer
(0104) .macro PUSHSP
(0105) IN R16,SPH
(0106) ST -Y,R16
(0107) IN R16,SPL
(0108) ST -Y,R16
(0109) .endmacro
(0110)
(0111) ; Pop stack pointer
(0112) .macro POPSP
(0113) LD R16,Y+
(0114) OUT SPL,R16
(0115) LD R16,Y+
(0116) OUT SPH,R16
(0117) .endmacro
(0118)
(0119) ;Push SREG
(0120) .macro PUSHSREG
(0121) IN R16,SREG
(0122) ST -Y,R16
(0123) .endmacro
(0124)
(0125) ; Pop SREG
(0126) .macro POPSREG
(0127) LD R16,Y+
(0128) OUT SREG,R16
(0129) .endmacro
(0130)
(0131) .area text(rel)
(0132)
(0133)
(0134) ;*******************************************************************************
(0135) ; START HIGHEST PRIORITY TASK READY-TO-RUN
(0136) ;
(0137) ; Description : This function is called by OSStart() to start the highest
(0138) ; priority task that was created by your application before calling OSStart().
(0139) ;
(0140) ; Note(s):
(0141) ; 1) The (data)stack frame is assumed to look as follows:
(0142) ;
(0143) ; OSTCBHighRdy->OSTCBStkPtr --> LSB of (return) stack pointer (Low memory)
(0144) ; MSB of (return) stack pointer
(0145) ; Flags to load in status register
(0146) ; R31
(0147) ; R30
(0148) ; R7
(0149) ; .
(0150) ; .
(0151) ; .
(0152) ; R0 (High memory)
(0153) ;
(0154) ; where the stack pointer points to the task start address.
(0155) ;
(0156) ;
(0157) ; 2) OSStartHighRdy() MUST:
(0158) ; a) RCALL OSTaskSwHook() then,
(0159) ; b) Set OSRunning to TRUE,
(0160) ; c) Switch to the highest priority task.
(0161) ;*******************************************************************************
(0162)
(0163) _OSStartHighRdy::
(0164) LDS R16,_OSRunning ; Indicate that we are multitasking
_OSStartHighRdy:
0030 91000200 LDS R16,_OSRunning
(0165) INC R16
0032 9503 INC R16
(0166) STS _OSRunning,R16 ;
0033 93000200 STS R16,_OSRunning
0035 D3AE RCALL 0x03E4
(0167)
(0168) LDS R30,_OSTCBHighRdy ; Let Z point to TCB of highest priority task
(0169) LDS R31,_OSTCBHighRdy+1 ; ready to run
(0170) LD R28,Z+ ; Load Y (R29:R28) pointer
0036 91C1 LD R28,Z+
(0171) LD R29,Z+ ;
0037 91D1 LD R29,Z+
0038 9109 LD R16,Y+
0039 BF0D OUT P3D,R16
003A 9109 LD R16,Y+
003B BF0E OUT P3E,R16
003C D34B RCALL 0x0388
(0172)
(0173) POPSP ; Restore stack pointer
(0174) POPSREG ; Restore status register
(0175) POPRS ; Restore all registers
(0176) RET ; start task
003D 9508 RET
_OSCtxSw:
003E D36A RCALL 0x03A9
003F B70E IN R16,P3E
0040 930A ST R16,-Y
0041 B70D IN R16,P3D
0042 930A ST R16,-Y
0043 D39B RCALL 0x03DF
(0177)
(0178) ;*******************************************************************************
(0179) ; TASK LEVEL CONTEXT SWITCH
(0180) ;
(0181) ; Description : This function is called when a task makes a higher priority task
(0182) ; ready-to-run.
(0183) ;
(0184) ; Note(s):
(0185) ; 1) Upon entry,
(0186) ; OSTCBCur points to the OS_TCB of the task to suspend
(0187) ; OSTCBHighRdy points to the OS_TCB of the task to resume
(0188) ;
(0189) ; 2) The stack frame of the task to suspend looks as follows:
(0190) ;
(0191) ; SP +0 --> LSB of task code address
(0192) ; +1 MSB of task code address (High memory)
(0193) ;
(0194) ; 3) The saved context of the task to resume looks as follows:
(0195) ;
(0196) ; OSTCBHighRdy->OSTCBStkPtr --> LSB of (return) stack pointer (Low memory)
(0197) ; MSB of (return) stack pointer
(0198) ; Flags to load in status register
(0199) ; R31
(0200) ; R30
(0201) ; R7
(0202) ; .
(0203) ; .
(0204) ; .
(0205) ; R0 (High memory)
(0206) ;*******************************************************************************
(0207)
(0208) _OSCtxSw:: PUSHRS ; Save current task's context
(0209) PUSHSREG
(0210) PUSHSP
(0211)
(0212) LDS R30,_OSTCBCur ; Z = OSTCBCur->OSTCBStkPtr
(0213) LDS R31,_OSTCBCur+1 ;
(0214) ST Z+,R28 ; Save Y (R29:R28) pointer
0044 93C1 ST R28,Z+
(0215) ST Z+,R29 ;
0045 93D1 ST R29,Z+
(0216)
(0217) LDS R16,_OSPrioHighRdy ; OSPrioCur = OSPrioHighRdy
0046 910001F6 LDS R16,_OSPrioHighRdy
(0218) STS _OSPrioCur,R16
0048 930001F7 STS R16,_OSPrioCur
004A D399 RCALL 0x03E4
(0219)
(0220) LDS R30,_OSTCBHighRdy ; Let Z point to TCB of highest priority task
(0221) LDS R31,_OSTCBHighRdy+1 ; ready to run
(0222) STS _OSTCBCur,R30 ; OSTCBCur = OSTCBHighRdy
004B 93E001F4 STS R30,_OSTCBCur
(0223) STS _OSTCBCur+1,R31 ;
004D 93F001F5 STS R31,_OSTCBCur+1
(0224)
(0225) LD R28,Z+ ; Restore Y pointer
004F 91C1 LD R28,Z+
(0226) LD R29,Z+ ;
0050 91D1 LD R29,Z+
0051 9109 LD R16,Y+
0052 BF0D OUT P3D,R16
0053 9109 LD R16,Y+
0054 BF0E OUT P3E,R16
0055 D332 RCALL 0x0388
(0227)
(0228) POPSP ; Restore stack pointer
(0229) POPSREG ; Restore status register
(0230) POPRS ; Restore all registers
(0231) RET
0056 9508 RET
_OSTickISR:
0057 D351 RCALL 0x03A9
(0232)
(0233) _OSTickISR::
(0234) PUSHRS ; Save interrupted task's context
(0235)
(0236) IN R16,SREG
(0237) ;move to end
(0238) ; SBR R16,0x80 ; Set interrupt bit in status reg and save
(0239) ST -Y,R16
(0240) ; PUSHSP
(0241)
(0242) ;avr-gcc ->11059200
(0243) LDI R16,256-(8000000/50/1024) ; Reload timer to overflow at a rate of 50Hz
0058 E604 LDI R16,0x64
(0244) OUT TCNT0,R16 ; at a prescaler of 1024 and 7.3728 MHz AVR clock
0059 BF02 OUT P32,R16
(0245)
(0246) LDS R16,_OSIntNesting ; Notify uC/OS-II of ISR
005A 910001F9 LDS R16,_OSIntNesting
(0247) INC R16 ;
005C 9503 INC R16
(0248) STS _OSIntNesting,R16 ;
005D 930001F9 STS R16,_OSIntNesting
(0249)
(0250) ;why?
(0251) ; SEI ; Enable interrupts
(0252) RCALL _OSTimeTick ; RCALL uC/OS-II's tick updating function
005F D18C RCALL _OSTimeTick
(0253) RCALL _OSIntExit ; Notify uC/OS-II about end of ISR
0060 D1B9 RCALL _OSIntExit
0061 D326 RCALL 0x0388
(0254)
(0255) ; POPSP
(0256) POPSREG ; Restore status register
(0257) POPRS ; Restore all registers
(0258) SEI
0062 9478 BSET 7
(0259) RET ; Note: RET instead of RETI
0063 9508 RET
(0260)
(0261) ;*******************************************************************************
(0262) ; INTERRUPT LEVEL CONTEXT SWITCH
(0263) ;
(0264) ; Description : This function is called by OSIntExit() to perform a context
(0265) ; switch to a task that has been made ready-to-run by an ISR.
(0266) ;
(0267) ; Note(s):
(0268) ; 1) Upon entry,
(0269) ; OSTCBCur points to the OS_TCB of the task to suspend
(0270) ; OSTCBHighRdy points to the OS_TCB of the task to resume
(0271) ;
(0272) ; 2) The stack frame of the task to suspend looks as follows:
(0273) ;
(0274) ; SP +0 --> LSB of return address of OSIntCtxSw() (Low memory)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?