📄 os_time.lst
字号:
C51 COMPILER V7.50 OS_TIME 12/14/2007 08:25:39 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE OS_TIME
OBJECT MODULE PLACED IN OS_TIME.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE OS_TIME.C LARGE BROWSE DEBUG OBJECTEXTEND
line level source
1 /*
2 *********************************************************************************************************
3 * uC/OS-II
4 * The Real-Time Kernel
5 * TIME MANAGEMENT
6 *
7 * (c) Copyright 1992-2007, Jean J. Labrosse, Weston, FL
8 * All Rights Reserved
9 *
10 * File : OS_TIME.C
11 * By : Jean J. Labrosse
12 * Version : V2.85
13 *
14 * LICENSING TERMS:
15 * ---------------
16 * uC/OS-II is provided in source form for FREE evaluation, for educational use or for peaceful research.
-
17 * If you plan on using uC/OS-II in a commercial product you need to contact Micri祄 to properly license
18 * its use in your product. We provide ALL the source code for your convenience and to help you experience
19 * uC/OS-II. The fact that the source is provided does NOT mean that you can use it without paying a
20 * licensing fee.
21 *********************************************************************************************************
22 */
23
24 #ifndef OS_MASTER_FILE
25 #include <ucos_ii.h>
26 #endif
27
28 /*
29 *********************************************************************************************************
30 * DELAY TASK 'n' TICKS (n from 0 to 65535)
31 *
32 * Description: This function is called to delay execution of the currently running task until the
33 * specified number of system ticks expires. This, of course, directly equates to delaying
34 * the current task for some time to expire. No delay will result If the specified delay is
35 * 0. If the specified delay is greater than 0 then, a context switch will result.
36 *
37 * Arguments : ticks is the time delay that the task will be suspended in number of clock 'ticks'.
38 * Note that by specifying 0, the task will not be delayed.
39 *
40 * Returns : none
41 *********************************************************************************************************
42 */
43
44 void OSTimeDly (INT16U ticks) reentrant
45 {
46 1 INT8U y;
47 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
50 1
51 1
52 1
53 1 if (OSIntNesting > 0) { /* See if trying to call from an ISR */
54 2 return;
C51 COMPILER V7.50 OS_TIME 12/14/2007 08:25:39 PAGE 2
55 2 }
56 1 if (ticks > 0) { /* 0 means no delay! */
57 2 OS_ENTER_CRITICAL();
58 2 y = OSTCBCur->OSTCBY; /* Delay current task */
59 2 OSRdyTbl[y] &= ~OSTCBCur->OSTCBBitX;
60 2 if (OSRdyTbl[y] == 0) {
61 3 OSRdyGrp &= ~OSTCBCur->OSTCBBitY;
62 3 }
63 2 OSTCBCur->OSTCBDly = ticks; /* Load ticks in TCB */
64 2 OS_EXIT_CRITICAL();
65 2 OS_Sched(); /* Find next task to run! */
66 2 }
67 1 }
68 /*$PAGE*/
69 /*
70 *********************************************************************************************************
71 * DELAY TASK FOR SPECIFIED TIME
72 *
73 * Description: This function is called to delay execution of the currently running task until some time
74 * expires. This call allows you to specify the delay time in HOURS, MINUTES, SECONDS and
75 * MILLISECONDS instead of ticks.
76 *
77 * Arguments : hours specifies the number of hours that the task will be delayed (max. is 255)
78 * minutes specifies the number of minutes (max. 59)
79 * seconds specifies the number of seconds (max. 59)
80 * milli specifies the number of milliseconds (max. 999)
81 *
82 * Returns : OS_ERR_NONE
83 * OS_ERR_TIME_INVALID_MINUTES
84 * OS_ERR_TIME_INVALID_SECONDS
85 * OS_ERR_TIME_INVALID_MS
86 * OS_ERR_TIME_ZERO_DLY
87 * OS_ERR_TIME_DLY_ISR
88 *
89 * Note(s) : The resolution on the milliseconds depends on the tick rate. For example, you can't do
90 * a 10 mS delay if the ticker interrupts every 100 mS. In this case, the delay would be
91 * set to 0. The actual delay is rounded to the nearest tick.
92 *********************************************************************************************************
93 */
94
95 #if OS_TIME_DLY_HMSM_EN > 0
96 INT8U OSTimeDlyHMSM (INT8U hours, INT8U minutes, INT8U seconds, INT16U ms) reentrant
97 {
98 1 INT32U ticks;
99 1 INT16U loops;
100 1
101 1
102 1 if (OSIntNesting > 0) { /* See if trying to call from an ISR */
103 2 return (OS_ERR_TIME_DLY_ISR);
104 2 }
105 1 #if OS_ARG_CHK_EN > 0
if (hours == 0) {
if (minutes == 0) {
if (seconds == 0) {
if (ms == 0) {
return (OS_ERR_TIME_ZERO_DLY);
}
}
}
}
if (minutes > 59) {
return (OS_ERR_TIME_INVALID_MINUTES); /* Validate arguments to be within range */
C51 COMPILER V7.50 OS_TIME 12/14/2007 08:25:39 PAGE 3
}
if (seconds > 59) {
return (OS_ERR_TIME_INVALID_SECONDS);
}
if (ms > 999) {
return (OS_ERR_TIME_INVALID_MS);
}
#endif
125 1 /* Compute the total number of clock ticks required.. */
126 1 /* .. (rounded to the nearest tick) */
127 1 ticks = ((INT32U)hours * 3600L + (INT32U)minutes * 60L + (INT32U)seconds) * OS_TICKS_PER_SEC
128 1 + OS_TICKS_PER_SEC * ((INT32U)ms + 500L / OS_TICKS_PER_SEC) / 1000L;
129 1 loops = (INT16U)(ticks >> 16); /* Compute the integral number of 65536 tick delays */
130 1 ticks = ticks & 0xFFFFL; /* Obtain the fractional number of ticks */
131 1 OSTimeDly((INT16U)ticks);
132 1 while (loops > 0) {
133 2 OSTimeDly((INT16U)32768u);
134 2 OSTimeDly((INT16U)32768u);
135 2 loops--;
136 2 }
137 1 return (OS_ERR_NONE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -