📄 ucos_ii.s
字号:
.module Ucos_ii.c
.area lit(rom, con, rel)
_OSMapTbl::
.byte 1,2
.byte 4,8
.byte 16,32
.byte 64,128
_OSUnMapTbl::
.byte 0,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 3,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 4,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 3,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 5,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 3,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 4,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 3,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 6,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 3,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 4,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 3,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 5,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 3,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 4,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 3,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 7,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 3,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 4,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 3,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 5,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 3,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 4,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 3,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 6,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 3,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 4,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 3,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 5,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 3,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 4,0
.byte 1,0
.byte 2,0
.byte 1,0
.byte 3,0
.byte 1,0
.byte 2,0
.byte 1,0
.area text(rom, con, rel)
; i -> R10,R11
.even
_OSInit::
xcall push_gset3x
sbiw R28,3
; /*
; *********************************************************************************************************
; * uC/OS-II
; * The Real-Time Kernel
; *
; * (c) Copyright 1992-1998, Jean J. Labrosse, Plantation, FL
; * All Rights Reserved
; *
; * V2.00
; *
; * File : uCOS_II.C
; * By : Jean J. Labrosse
; *********************************************************************************************************
; */
;
; #define OS_GLOBALS /* Declare GLOBAL variables */
; #include "includes.h"
;
;
; #define OS_MASTER_FILE /* Prevent the following files from including includes.h */
; #include "os_core.c"
; #include "os_task.c"
; #include "os_time.c"
; //#include "uart.c"
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
ldi R24,0
ldi R25,0
ldi R26,0
ldi R27,0
sts _OSTime+1,R25
sts _OSTime,R24
sts _OSTime+2+1,R27
sts _OSTime+2,R26
;
clr R2
sts _OSIntNesting,R2
;
sts _OSLockNesting,R2
;
;
sts _OSTaskCtr,R2
;
;
sts _OSRunning,R2
;
ldi R24,0
ldi R25,0
ldi R26,0
ldi R27,0
sts _OSIdleCtr+1,R25
sts _OSIdleCtr,R24
sts _OSIdleCtr+2+1,R27
sts _OSIdleCtr+2,R26
;
;
ldi R24,0
ldi R25,0
ldi R26,0
ldi R27,0
sts _OSCtxSwCtr+1,R25
sts _OSCtxSwCtr,R24
sts _OSCtxSwCtr+2+1,R27
sts _OSCtxSwCtr+2,R26
;
sts _OSRdyGrp,R2
clr R10
clr R11
xjmp L6
L3:
ldi R24,<_OSRdyTbl
ldi R25,>_OSRdyTbl
movw R30,R10
add R30,R24
adc R31,R25
clr R2
std z+0,R2
L4:
movw R24,R10
adiw R24,1
movw R10,R24
L6:
;
movw R24,R10
cpi R24,2
ldi R30,0
cpc R25,R30
brlo L3
;
;
;
;
clr R2
sts _OSPrioCur,R2
;
sts _OSPrioHighRdy,R2
;
clr R3
sts _OSTCBHighRdy+1,R3
sts _OSTCBHighRdy,R2
;
sts _OSTCBCur+1,R3
sts _OSTCBCur,R2
;
sts _OSTCBList+1,R3
sts _OSTCBList,R2
clr R10
clr R11
xjmp L10
L7:
ldi R16,2
ldi R17,0
movw R18,R10
xcall empy16s
movw R30,R16
ldi R24,<_OSTCBPrioTbl
ldi R25,>_OSTCBPrioTbl
add R30,R24
adc R31,R25
clr R2
clr R3
std z+1,R3
std z+0,R2
L8:
movw R24,R10
adiw R24,1
movw R10,R24
L10:
;
movw R24,R10
cpi R24,16
ldi R30,0
cpc R25,R30
brlo L7
clr R10
clr R11
xjmp L14
L11:
movw R18,R10
subi R18,255 ; offset = 1
sbci R19,255
ldi R16,14
ldi R17,0
xcall empy16s
movw R2,R16
ldi R24,<_OSTCBTbl
ldi R25,>_OSTCBTbl
add R2,R24
adc R3,R25
ldi R16,14
ldi R17,0
movw R18,R10
xcall empy16s
movw R30,R16
ldi R24,<_OSTCBTbl+2
ldi R25,>_OSTCBTbl+2
add R30,R24
adc R31,R25
std z+1,R3
std z+0,R2
L12:
movw R24,R10
adiw R24,1
movw R10,R24
L14:
;
;
;
movw R24,R10
cpi R24,5
ldi R30,0
cpc R25,R30
brlo L11
;
;
;
clr R2
clr R3
sts _OSTCBTbl+70+2+1,R3
sts _OSTCBTbl+70+2,R2
;
ldi R24,<_OSTCBTbl
ldi R25,>_OSTCBTbl
sts _OSTCBFreeList+1,R25
sts _OSTCBFreeList,R24
clr R10
clr R11
xjmp L21
L18:
movw R18,R10
subi R18,255 ; offset = 1
sbci R19,255
ldi R16,8
ldi R17,0
xcall empy16s
movw R2,R16
ldi R24,<_OSEventTbl
ldi R25,>_OSEventTbl
add R2,R24
adc R3,R25
ldi R16,8
ldi R17,0
movw R18,R10
xcall empy16s
movw R30,R16
ldi R24,<_OSEventTbl
ldi R25,>_OSEventTbl
add R30,R24
adc R31,R25
std z+1,R3
std z+0,R2
L19:
movw R24,R10
adiw R24,1
movw R10,R24
L21:
;
;
;
movw R24,R10
cpi R24,1
ldi R30,0
cpc R25,R30
brlo L18
;
;
;
clr R2
clr R3
sts _OSEventTbl+8+1,R3
sts _OSEventTbl+8,R2
;
ldi R24,<_OSEventTbl
ldi R25,>_OSEventTbl
sts _OSEventFreeList+1,R25
sts _OSEventFreeList,R24
;
;
;
;
ldi R24,15
std y+2,R24
ldi R24,<_OSTaskIdleStk+99
ldi R25,>_OSTaskIdleStk+99
std y+1,R25
std y+0,R24
clr R18
clr R19
ldi R16,<PL_OSTaskIdle
ldi R17,>PL_OSTaskIdle
xcall _OSTaskCreate
L2:
adiw R28,3
xcall pop_gset3x
.dbline 0 ; func end
ret
.even
_OSIntExit::
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
st -y,r16
in r16,0x3F
cli
push r16
ld r16,y+
;
lds R24,_OSIntNesting
subi R24,1
mov R2,R24
sts _OSIntNesting,R2
lds R4,_OSLockNesting
or R2,R4
breq X0
xjmp L25
X0:
;
ldi R24,<_OSUnMapTbl
ldi R25,>_OSUnMapTbl
lds R30,_OSRdyGrp
clr R31
add R30,R24
adc R31,R25
lpm R30,Z
sts _OSIntExitY,R30
;
ldi R24,<_OSRdyTbl
ldi R25,>_OSRdyTbl
clr R31
add R30,R24
adc R31,R25
ldd R30,z+0
clr R31
ldi R24,<_OSUnMapTbl
ldi R25,>_OSUnMapTbl
add R30,R24
adc R31,R25
lpm R2,Z
clr R3
lds R4,_OSIntExitY
clr R5
lsl R4
rol R5
lsl R4
rol R5
lsl R4
rol R5
add R4,R2
adc R5,R3
sts _OSPrioHighRdy,R4
;
lds R2,_OSPrioCur
cp R4,R2
breq L27
;
mov R2,R4
ldi R24,2
mul R24,R2
movw R30,R0
ldi R24,<_OSTCBPrioTbl
ldi R25,>_OSTCBPrioTbl
add R30,R24
adc R31,R25
ldd R2,z+0
ldd R3,z+1
sts _OSTCBHighRdy+1,R3
sts _OSTCBHighRdy,R2
;
ldi R24,1
ldi R25,0
ldi R26,0
ldi R27,0
lds R4,_OSCtxSwCtr+2
lds R5,_OSCtxSwCtr+2+1
lds R2,_OSCtxSwCtr
lds R3,_OSCtxSwCtr+1
add R2,R24
adc R3,R25
adc R4,R26
adc R5,R27
sts _OSCtxSwCtr+1,R3
sts _OSCtxSwCtr,R2
sts _OSCtxSwCtr+2+1,R5
sts _OSCtxSwCtr+2,R4
;
xcall _OSIntCtxSw
;
L27:
;
L25:
;
st -y,r16
pop r16
out 0x3F,r16
ld r16,y+
L24:
.dbline 0 ; func end
ret
; y -> R10
.even
_OSSched::
xcall push_gset3x
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
st -y,r16
in r16,0x3F
cli
push r16
ld r16,y+
;
lds R2,_OSIntNesting
lds R3,_OSLockNesting
or R3,R2
breq X1
xjmp L30
X1:
;
ldi R24,<_OSUnMapTbl
ldi R25,>_OSUnMapTbl
lds R30,_OSRdyGrp
clr R31
add R30,R24
adc R31,R25
lpm R10,Z
;
ldi R24,<_OSRdyTbl
ldi R25,>_OSRdyTbl
mov R30,R10
clr R31
add R30,R24
adc R31,R25
ldd R30,z+0
clr R31
ldi R24,<_OSUnMapTbl
ldi R25,>_OSUnMapTbl
add R30,R24
adc R31,R25
lpm R2,Z
clr R3
mov R4,R10
clr R5
lsl R4
rol R5
lsl R4
rol R5
lsl R4
rol R5
add R4,R2
adc R5,R3
sts _OSPrioHighRdy,R4
;
lds R2,_OSPrioCur
cp R4,R2
breq L32
;
mov R2,R4
ldi R24,2
mul R24,R2
movw R30,R0
ldi R24,<_OSTCBPrioTbl
ldi R25,>_OSTCBPrioTbl
add R30,R24
adc R31,R25
ldd R2,z+0
ldd R3,z+1
sts _OSTCBHighRdy+1,R3
sts _OSTCBHighRdy,R2
;
ldi R24,1
ldi R25,0
ldi R26,0
ldi R27,0
lds R4,_OSCtxSwCtr+2
lds R5,_OSCtxSwCtr+2+1
lds R2,_OSCtxSwCtr
lds R3,_OSCtxSwCtr+1
add R2,R24
adc R3,R25
adc R4,R26
adc R5,R27
sts _OSCtxSwCtr+1,R3
sts _OSCtxSwCtr,R2
sts _OSCtxSwCtr+2+1,R5
sts _OSCtxSwCtr+2,R4
;
xcall _OSCtxSw
;
L32:
;
L30:
;
st -y,r16
pop r16
out 0x3F,r16
ld r16,y+
L29:
xcall pop_gset3x
.dbline 0 ; func end
ret
; x -> R12
; y -> R10
.even
_OSStart::
xcall push_gset4x
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
lds R2,_OSRunning
tst R2
breq X2
xjmp L35
X2:
;
ldi R24,<_OSUnMapTbl
ldi R25,>_OSUnMapTbl
lds R30,_OSRdyGrp
clr R31
add R30,R24
adc R31,R25
lpm R10,Z
;
ldi R24,<_OSRdyTbl
ldi R25,>_OSRdyTbl
mov R30,R10
clr R31
add R30,R24
adc R31,R25
ldd R30,z+0
clr R31
ldi R24,<_OSUnMapTbl
ldi R25,>_OSUnMapTbl
add R30,R24
adc R31,R25
lpm R12,Z
;
mov R2,R12
clr R3
mov R4,R10
clr R5
lsl R4
rol R5
lsl R4
rol R5
lsl R4
rol R5
add R4,R2
adc R5,R3
sts _OSPrioHighRdy,R4
;
mov R2,R4
sts _OSPrioCur,R2
;
ldi R24,2
mul R24,R2
movw R30,R0
ldi R24,<_OSTCBPrioTbl
ldi R25,>_OSTCBPrioTbl
add R30,R24
adc R31,R25
ldd R2,z+0
ldd R3,z+1
sts _OSTCBHighRdy+1,R3
sts _OSTCBHighRdy,R2
;
sts _OSTCBCur+1,R3
sts _OSTCBCur,R2
;
xcall _OSStartHighRdy
;
L35:
L34:
xcall pop_gset4x
.dbline 0 ; func end
ret
; pdata -> R16,R17
.even
_OSTaskIdle::
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
L38:
;
;
st -y,r16
in r16,0x3F
cli
push r16
ld r16,y+
;
ldi R24,1
ldi R25,0
ldi R26,0
ldi R27,0
lds R4,_OSIdleCtr+2
lds R5,_OSIdleCtr+2+1
lds R2,_OSIdleCtr
lds R3,_OSIdleCtr+1
add R2,R24
adc R3,R25
adc R4,R26
adc R5,R27
sts _OSIdleCtr+1,R3
sts _OSIdleCtr,R2
sts _OSIdleCtr+2+1,R5
sts _OSIdleCtr+2,R4
;
st -y,r16
pop r16
out 0x3F,r16
ld r16,y+
;
xjmp L38
X3:
L37:
.dbline 0 ; func end
ret
; ptcb -> R10,R11
; opt -> y+10
; pext -> y+8
; stk_size -> y+6
; id -> y+4
; pbos -> y+2
; ptos -> R18,R19
; prio -> R16
.even
_OSTCBInit::
xcall push_gset3x
;
;
;
;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -