📄 os_time.s
字号:
.module OS_TIME.c
.area text(rom, con, rel)
.dbfile F:\AVRPRA~1\ucosii-port2-mega8\OS_TIME.c
.dbfunc e OSTimeDly _OSTimeDly fV
; cpu_sr -> R20
; ticks -> R22,R23
.even
_OSTimeDly::
rcall push_gset2
movw R22,R16
.dbline -1
.dbline 36
; /*
; *********************************************************************************************************
; * uC/OS-II
; * The Real-Time Kernel
; * TIME MANAGEMENT
; *
; * (c) Copyright 1992-2001, Jean J. Labrosse, Weston, FL
; * All Rights Reserved
; *
; * File : OS_TIME.C
; * By : Jean J. Labrosse
; *********************************************************************************************************
; */
;
; #ifndef OS_MASTER_FILE
; #include "includes.h"
; #endif
;
; /*
; *********************************************************************************************************
; * DELAY TASK 'n' TICKS (n from 0 to 65535)
; *
; * Description: This function is called to delay execution of the currently running task until the
; * specified number of system ticks expires. This, of course, directly equates to delaying
; * the current task for some time to expire. No delay will result If the specified delay is
; * 0. If the specified delay is greater than 0 then, a context switch will result.
; *
; * Arguments : ticks is the time delay that the task will be suspended in number of clock 'ticks'.
; * Note that by specifying 0, the task will not be delayed.
; *
; * Returns : none
; *********************************************************************************************************
; */
;
; void OSTimeDly (INT16U ticks)
; {
.dbline 42
; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
; OS_CPU_SR cpu_sr;
; #endif
;
;
; if (ticks > 0) { /* 0 means no delay! */
cpi R22,0
cpc R22,R23
brne X1
rjmp L4
X1:
X0:
.dbline 42
.dbline 43
; OS_ENTER_CRITICAL();
rcall _OS_CPU_SR_Save
mov R20,R16
.dbline 44
; if ((OSRdyTbl[OSTCBCur->OSTCBY] &= ~OSTCBCur->OSTCBBitX) == 0) { /* Delay current task */
ldi R24,<_OSRdyTbl
ldi R25,>_OSRdyTbl
lds R30,_OSTCBCur
lds R31,_OSTCBCur+1
ldd R2,z+13
clr R3
add R2,R24
adc R3,R25
lds R30,_OSTCBCur
lds R31,_OSTCBCur+1
ldd R4,z+14
com R4
movw R30,R2
ldd R5,z+0
and R5,R4
mov R4,R5
std z+0,R4
tst R5
brne L6
.dbline 44
.dbline 45
; OSRdyGrp &= ~OSTCBCur->OSTCBBitY;
lds R30,_OSTCBCur
lds R31,_OSTCBCur+1
ldd R2,z+15
com R2
lds R3,_OSRdyGrp
and R3,R2
sts _OSRdyGrp,R3
.dbline 46
; }
L6:
.dbline 47
lds R30,_OSTCBCur
lds R31,_OSTCBCur+1
std z+9,R23
std z+8,R22
.dbline 48
mov R16,R20
rcall _OS_CPU_SR_Restore
.dbline 49
rcall _OS_Sched
.dbline 50
L4:
.dbline -2
L3:
rcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r cpu_sr 20 c
.dbsym r ticks 22 i
.dbend
.dbfunc e OSTimeDlyHMSM _OSTimeDlyHMSM fc
; ticks -> y+0
; loops -> R10,R11
; milli -> y+14
; seconds -> y+12
; minutes -> R12
; hours -> R10
.even
_OSTimeDlyHMSM::
rcall push_gset4
mov R12,R18
mov R10,R16
sbiw R28,4
.dbline -1
.dbline 80
; OSTCBCur->OSTCBDly = ticks; /* Load ticks in TCB */
; OS_EXIT_CRITICAL();
; OS_Sched(); /* Find next task to run! */
; }
; }
; /*$PAGE*/
; /*
; *********************************************************************************************************
; * DELAY TASK FOR SPECIFIED TIME
; *
; * Description: This function is called to delay execution of the currently running task until some time
; * expires. This call allows you to specify the delay time in HOURS, MINUTES, SECONDS and
; * MILLISECONDS instead of ticks.
; *
; * Arguments : hours specifies the number of hours that the task will be delayed (max. is 255)
; * minutes specifies the number of minutes (max. 59)
; * seconds specifies the number of seconds (max. 59)
; * milli specifies the number of milliseconds (max. 999)
; *
; * Returns : OS_NO_ERR
; * OS_TIME_INVALID_MINUTES
; * OS_TIME_INVALID_SECONDS
; * OS_TIME_INVALID_MS
; * OS_TIME_ZERO_DLY
; *
; * Note(s) : The resolution on the milliseconds depends on the tick rate. For example, you can't do
; * a 10 mS delay if the ticker interrupts every 100 mS. In this case, the delay would be
; * set to 0. The actual delay is rounded to the nearest tick.
; *********************************************************************************************************
; */
;
; #if OS_TIME_DLY_HMSM_EN > 0
; INT8U OSTimeDlyHMSM (INT8U hours, INT8U minutes, INT8U seconds, INT16U milli)
; {
.dbline 85
clr R2
cp R2,R10
brlo L13
cp R2,R12
brlo L13
ldd R0,y+12
cp R2,R0
brlo L13
ldd R0,y+14
ldd R1,y+15
tst R0
brne X2
tst R1
brne X4
rjmp L9
X4:
X2:
L13:
.dbline 85
; INT32U ticks;
; INT16U loops;
;
;
; if (hours > 0 || minutes > 0 || seconds > 0 || milli > 0) {
.dbline 86
; if (minutes > 59) {
ldi R24,59
cp R24,R12
brsh L14
.dbline 86
.dbline 87
; return (OS_TIME_INVALID_MINUTES); /* Validate arguments to be within range */
ldi R16,81
rjmp L8
L14:
.dbline 89
; }
; if (seconds > 59) {
ldi R24,59
ldd R0,y+12
cp R24,R0
brsh L16
.dbline 89
.dbline 90
; return (OS_TIME_INVALID_SECONDS);
ldi R16,82
rjmp L8
L16:
.dbline 92
; }
; if (milli > 999) {
ldi R24,999
ldi R25,3
ldd R0,y+14
ldd R1,y+15
cp R24,R0
cpc R25,R1
brsh L18
.dbline 92
.dbline 93
; return (OS_TIME_INVALID_MILLI);
ldi R16,83
rjmp L8
L18:
.dbline 97
; }
; /* Compute the total number of clock ticks required.. */
; /* .. (rounded to the nearest tick) */
; ticks = ((INT32U)hours * 3600L + (INT32U)minutes * 60L + (INT32U)seconds) * OS_TICKS_PER_SEC
mov R2,R12
clr R3
clr R4
clr R5
ldi R20,60
ldi R21,0
ldi R22,0
ldi R23,0
st -y,R5
st -y,R4
st -y,R3
st -y,R2
movw R16,R20
movw R18,R22
rcall empy32u
movw R2,R16
movw R4,R18
mov R6,R10
clr R7
clr R8
clr R9
ldi R20,16
ldi R21,14
ldi R22,0
ldi R23,0
st -y,R9
st -y,R8
st -y,R7
st -y,R6
movw R16,R20
movw R18,R22
rcall empy32u
movw R6,R16
movw R8,R18
add R6,R2
adc R7,R3
adc R8,R4
adc R9,R5
ldd R2,y+12
clr R3
clr R4
clr R5
add R6,R2
adc R7,R3
adc R8,R4
adc R9,R5
ldi R20,50
ldi R21,0
ldi R22,0
ldi R23,0
st -y,R9
st -y,R8
st -y,R7
st -y,R6
movw R16,R20
movw R18,R22
rcall empy32u
movw R2,R16
movw R4,R18
ldi R20,10
ldi R21,0
ldi R22,0
ldi R23,0
ldd R6,y+14
ldd R7,y+15
clr R8
clr R9
add R6,R20
adc R7,R21
adc R8,R22
adc R9,R23
ldi R20,50
ldi R21,0
ldi R22,0
ldi R23,0
st -y,R9
st -y,R8
st -y,R7
st -y,R6
movw R16,R20
movw R18,R22
rcall empy32u
ldi R20,232
ldi R21,3
ldi R22,0
ldi R23,0
st -y,R23
st -y,R22
st -y,R21
st -y,R20
rcall div32u
add R2,R16
adc R3,R17
adc R4,R18
adc R5,R19
movw R30,R28
std z+0,R2
std z+1,R3
std z+2,R4
std z+3,R5
.dbline 99
; + OS_TICKS_PER_SEC * ((INT32U)milli + 500L / OS_TICKS_PER_SEC) / 1000L;
; loops = (INT16U)(ticks / 65536L); /* Compute the integral number of 65536 tick delays */
movw R30,R28
ldd R2,z+0
ldd R3,z+1
ldd R4,z+2
ldd R5,z+3
movw R10,R4
.dbline 100
; ticks = ticks % 65536L; /* Obtain the fractional number of ticks */
ldi R20,255
ldi R21,255
ldi R22,0
ldi R23,0
movw R30,R28
ldd R2,z+0
ldd R3,z+1
ldd R4,z+2
ldd R5,z+3
and R2,R20
and R3,R21
and R4,R22
and R5,R23
movw R30,R28
std z+0,R2
std z+1,R3
std z+2,R4
std z+3,R5
.dbline 101
; OSTimeDly((INT16U)ticks);
movw R30,R28
ldd R16,z+0
ldd R17,z+1
rcall _OSTimeDly
rjmp L21
L20:
.dbline 102
.dbline 103
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -