📄 os_time.lst
字号:
C51 COMPILER V7.50 OS_TIME 08/08/2005 11:36:57 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 ORDER NOAREGS DEBUG OBJECTEXTEND SRC(.\OS_TIME.SRC)
line level source
1 /*
2 *********************************************************************************************************
3 * uC/OS-II
4 * The Real-Time Kernel
5 * TIME MANAGEMENT
6 *
7 * (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
8 * All Rights Reserved
9 *
10 * File : OS_TIME.C
11 * By : Jean J. Labrosse
12 *********************************************************************************************************
13 */
14
15 #ifndef OS_MASTER_FILE
16 #include "includes.h"
17 #endif
18
19 /*
20 *********************************************************************************************************
21 * DELAY TASK 'n' TICKS (n from 0 to 65535)
22 *
23 * Description: This function is called to delay execution of the currently running task until the
24 * specified number of system ticks expires. This, of course, directly equates to delaying
25 * the current task for some time to expire. No delay will result If the specified delay is
26 * 0. If the specified delay is greater than 0 then, a context switch will result.
27 *
28 * Arguments : ticks is the time delay that the task will be suspended in number of clock 'ticks'.
29 * Note that by specifying 0, the task will not be delayed.
30 *
31 * Returns : none
32 *********************************************************************************************************
33 */
34
35 void OSTimeDly (INT16U ticks)
36 {
37 1
38 1
39 1
40 1 if (ticks > 0) { /* 0 means no delay! */
41 2 OS_ENTER_CRITICAL();
42 2 if ((OSRdyTbl[OSTCBCur->OSTCBY] &= ~OSTCBCur->OSTCBBitX) == 0) { /* Delay current task */
43 3 OSRdyGrp &= ~OSTCBCur->OSTCBBitY;
44 3 }
45 2 OSTCBCur->OSTCBDly = ticks; /* Load ticks in TCB */
46 2 OS_EXIT_CRITICAL();
47 2 OS_Sched(); /* Find next task to run! */
48 2 }
49 1 }
50 /*$PAGE*/
51 /*
52 *********************************************************************************************************
53 * DELAY TASK FOR SPECIFIED TIME
54 *
55 * Description: This function is called to delay execution of the currently running task until some time
C51 COMPILER V7.50 OS_TIME 08/08/2005 11:36:57 PAGE 2
56 * expires. This call allows you to specify the delay time in HOURS, MINUTES, SECONDS and
57 * MILLISECONDS instead of ticks.
58 *
59 * Arguments : hours specifies the number of hours that the task will be delayed (max. is 255)
60 * minutes specifies the number of minutes (max. 59)
61 * seconds specifies the number of seconds (max. 59)
62 * milli specifies the number of milliseconds (max. 999)
63 *
64 * Returns : OS_NO_ERR
65 * OS_TIME_INVALID_MINUTES
66 * OS_TIME_INVALID_SECONDS
67 * OS_TIME_INVALID_MS
68 * OS_TIME_ZERO_DLY
69 *
70 * Note(s) : The resolution on the milliseconds depends on the tick rate. For example, you can't do
71 * a 10 mS delay if the ticker interrupts every 100 mS. In this case, the delay would be
72 * set to 0. The actual delay is rounded to the nearest tick.
73 *********************************************************************************************************
74 */
75
76 #if OS_TIME_DLY_HMSM_EN > 0
77 INT8U OSTimeDlyHMSM (INT8U hours, INT8U minutes, INT8U seconds, INT16U milli)
78 {
79 1 INT32U ticks;
80 1 INT16U loops;
81 1
82 1
83 1 if (hours > 0 || minutes > 0 || seconds > 0 || milli > 0) {
84 2 if (minutes > 59) {
85 3 return (OS_TIME_INVALID_MINUTES); /* Validate arguments to be within range */
86 3 }
87 2 if (seconds > 59) {
88 3 return (OS_TIME_INVALID_SECONDS);
89 3 }
90 2 if (milli > 999) {
91 3 return (OS_TIME_INVALID_MILLI);
92 3 }
93 2 /* Compute the total number of clock ticks required.. */
94 2 /* .. (rounded to the nearest tick) */
95 2 ticks = ((INT32U)hours * 3600L + (INT32U)minutes * 60L + (INT32U)seconds) * OS_TICKS_PER_SEC
96 2 + OS_TICKS_PER_SEC * ((INT32U)milli + 500L / OS_TICKS_PER_SEC) / 1000L;
97 2 loops = (INT16U)(ticks / 65536L); /* Compute the integral number of 65536 tick delays */
98 2 ticks = ticks % 65536L; /* Obtain the fractional number of ticks */
99 2 OSTimeDly((INT16U)ticks);
100 2 while (loops > 0) {
101 3 OSTimeDly(32768);
102 3 OSTimeDly(32768);
103 3 loops--;
104 3 }
105 2 return (OS_NO_ERR);
106 2 }
107 1 return (OS_TIME_ZERO_DLY);
108 1 }
109 #endif
110 /*$PAGE*/
111 /*
112 *********************************************************************************************************
113 * RESUME A DELAYED TASK
114 *
115 * Description: This function is used resume a task that has been delayed through a call to either
116 * OSTimeDly() or OSTimeDlyHMSM(). Note that you MUST NOT call this function to resume a
117 * task that is waiting for an event with timeout. This situation would make the task look
C51 COMPILER V7.50 OS_TIME 08/08/2005 11:36:57 PAGE 3
118 * like a timeout occurred (unless you desire this effect). Also, you cannot resume a task
119 * that has called OSTimeDlyHMSM() with a combined time that exceeds 65535 clock ticks. In
120 * other words, if the clock tick runs at 100 Hz then, you will not be able to resume a
121 * delayed task that called OSTimeDlyHMSM(0, 10, 55, 350) or higher.
122 *
123 * (10 Minutes * 60 + 55 Seconds + 0.35) * 100 ticks/second.
124 *
125 * Arguments : prio specifies the priority of the task to resume
126 *
127 * Returns : OS_NO_ERR Task has been resumed
128 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
129 * (i.e. >= OS_LOWEST_PRIO)
130 * OS_TIME_NOT_DLY Task is not waiting for time to expire
131 * OS_TASK_NOT_EXIST The desired task has not been created
132 *********************************************************************************************************
133 */
134
135 #if OS_TIME_DLY_RESUME_EN > 0
136 INT8U OSTimeDlyResume (INT8U prio)
137 {
138 1
139 1 OS_TCB *ptcb;
140 1
141 1
142 1 if (prio >= OS_LOWEST_PRIO) {
143 2 return (OS_PRIO_INVALID);
144 2 }
145 1 OS_ENTER_CRITICAL();
146 1 ptcb = (OS_TCB *)OSTCBPrioTbl[prio]; /* Make sure that task exist */
147 1 if (ptcb != (OS_TCB *)0) {
148 2 if (ptcb->OSTCBDly != 0) { /* See if task is delayed */
149 3 ptcb->OSTCBDly = 0; /* Clear the time delay */
150 3 if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) == OS_STAT_RDY) { /* See if task is ready to run */
151 4 OSRdyGrp |= ptcb->OSTCBBitY; /* Make task ready to run */
152 4 OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
153 4 OS_EXIT_CRITICAL();
154 4 OS_Sched(); /* See if this is new highest priority */
155 4 } else {
156 4 OS_EXIT_CRITICAL(); /* Task may be suspended */
157 4 }
158 3 return (OS_NO_ERR);
159 3 } else {
160 3 OS_EXIT_CRITICAL();
161 3 return (OS_TIME_NOT_DLY); /* Indicate that task was not delayed */
162 3 }
163 2 }
164 1 OS_EXIT_CRITICAL();
165 1 return (OS_TASK_NOT_EXIST); /* The task does not exist */
166 1 }
167 #endif
168 /*$PAGE*/
169 /*
170 *********************************************************************************************************
171 * GET CURRENT SYSTEM TIME
172 *
173 * Description: This function is used by your application to obtain the current value of the 32-bit
174 * counter which keeps track of the number of clock ticks.
175 *
176 * Arguments : none
177 *
178 * Returns : The current value of OSTime
179 *********************************************************************************************************
C51 COMPILER V7.50 OS_TIME 08/08/2005 11:36:57 PAGE 4
180 */
181
182 #if OS_TIME_GET_SET_EN > 0
183 INT32U OSTimeGet (void)
184 {
185 1
186 1 INT32U ticks;
187 1
188 1
189 1 OS_ENTER_CRITICAL();
190 1 ticks = OSTime;
191 1 OS_EXIT_CRITICAL();
192 1 return (ticks);
193 1 }
194 #endif
195
196 /*
197 *********************************************************************************************************
198 * SET SYSTEM CLOCK
199 *
200 * Description: This function sets the 32-bit counter which keeps track of the number of clock ticks.
201 *
202 * Arguments : ticks specifies the new value that OSTime needs to take.
203 *
204 * Returns : none
205 *********************************************************************************************************
206 */
207
208 #if OS_TIME_GET_SET_EN > 0
209 void OSTimeSet (INT32U ticks)
210 {
211 1
212 1
213 1
214 1 OS_ENTER_CRITICAL();
215 1 OSTime = ticks;
216 1 OS_EXIT_CRITICAL();
217 1 }
218 #endif
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 712 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- 14
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -