📄 os_time.lst
字号:
97 }
98 }
99 }
100 if (minutes > 59) {
101 return (OS_TIME_INVALID_MINUTES); /* Validate arguments to be within range */
102 }
103 if (seconds > 59) {
104 return (OS_TIME_INVALID_SECONDS);
105 }
106 if (milli > 999) {
107 return (OS_TIME_INVALID_MILLI);
108 }
109 #endif
110 /* Compute the total number of clock ticks required.. */
111 /* .. (rounded to the nearest tick) */
112 ticks = ((INT32U)hours * 3600L + (INT32U)minutes * 60L + (INT32U)seconds) * OS_TICKS_PER_SEC
113 + OS_TICKS_PER_SEC * ((INT32U)milli + 500L / OS_TICKS_PER_SEC) / 1000L;
114 loops = (INT16U)(ticks / 65536L); /* Compute the integral number of 65536 tick delays */
115 ticks = ticks % 65536L; /* Obtain the fractional number of ticks */
116 OSTimeDly((INT16U)ticks);
117 while (loops > 0) {
118 OSTimeDly((INT16U)32768u);
119 OSTimeDly((INT16U)32768u);
120 loops--;
121 }
C51 COMPILER V8.08 OS_TIME 08/04/2008 21:49:52 PAGE 4
122 return (OS_NO_ERR);
123 }
124 #endif
125 /*$PAGE*/
126 /*
127 *********************************************************************************************************
128 * RESUME A DELAYED TASK
129 *
130 * Description: This function is used resume a task that has been delayed through a call to either
131 * OSTimeDly() or OSTimeDlyHMSM(). Note that you can call this function to resume a
132 * task that is waiting for an event with timeout. This would make the task look
133 * like a timeout occurred.
134 *
135 * Also, you cannot resume a task that has called OSTimeDlyHMSM() with a combined time that
136 * exceeds 65535 clock ticks. In other words, if the clock tick runs at 100 Hz then, you will
137 * not be able to resume a delayed task that called OSTimeDlyHMSM(0, 10, 55, 350) or higher:
138 *
139 * (10 Minutes * 60 + 55 Seconds + 0.35) * 100 ticks/second.
140 *
141 * Arguments : prio specifies the priority of the task to resume
142 *
143 * Returns : OS_NO_ERR Task has been resumed
144 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
145 * (i.e. >= OS_LOWEST_PRIO)
146 * OS_TIME_NOT_DLY Task is not waiting for time to expire
147 * OS_TASK_NOT_EXIST The desired task has not been created or has been assigned to a M
-utex.
148 *********************************************************************************************************
149 */
150
151 #if OS_TIME_DLY_RESUME_EN > 0
152 INT8U OSTimeDlyResume (INT8U prio)
153 {
154 OS_TCB *ptcb;
155 #if OS_CRITICAL_METHOD == 3 /* Storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
158
159
160
161 if (prio >= OS_LOWEST_PRIO) {
162 return (OS_PRIO_INVALID);
163 }
164 OS_ENTER_CRITICAL();
165 ptcb = OSTCBPrioTbl[prio]; /* Make sure that task exist */
166 if (ptcb == (OS_TCB *)0) {
167 OS_EXIT_CRITICAL();
168 return (OS_TASK_NOT_EXIST); /* The task does not exist */
169 }
170 if (ptcb == (OS_TCB *)1) {
171 OS_EXIT_CRITICAL();
172 return (OS_TASK_NOT_EXIST); /* The task does not exist */
173 }
174 if (ptcb->OSTCBDly == 0) { /* See if task is delayed */
175 OS_EXIT_CRITICAL();
176 return (OS_TIME_NOT_DLY); /* Indicate that task was not delayed */
177 }
178
179 ptcb->OSTCBDly = 0; /* Clear the time delay */
180 if ((ptcb->OSTCBStat & OS_STAT_PEND_ANY) != OS_STAT_RDY) {
181 ptcb->OSTCBStat &= ~OS_STAT_PEND_ANY; /* Yes, Clear status flag */
182 ptcb->OSTCBPendTO = TRUE; /* Indicate PEND timeout */
C51 COMPILER V8.08 OS_TIME 08/04/2008 21:49:52 PAGE 5
183 } else {
184 ptcb->OSTCBPendTO = FALSE;
185 }
186 if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) == OS_STAT_RDY) { /* Is task suspended? */
187 OSRdyGrp |= ptcb->OSTCBBitY; /* No, Make ready */
188 OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
189 OS_EXIT_CRITICAL();
190 OS_Sched(); /* See if this is new highest priority */
191 } else {
192 OS_EXIT_CRITICAL(); /* Task may be suspended */
193 }
194 return (OS_NO_ERR);
195 }
196 #endif
197 /*$PAGE*/
198 /*
199 *********************************************************************************************************
200 * GET CURRENT SYSTEM TIME
201 *
202 * Description: This function is used by your application to obtain the current value of the 32-bit
203 * counter which keeps track of the number of clock ticks.
204 *
205 * Arguments : none
206 *
207 * Returns : The current value of OSTime
208 *********************************************************************************************************
209 */
210
211 #if OS_TIME_GET_SET_EN > 0
212 INT32U OSTimeGet (void)
213 {
214 INT32U ticks;
215 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
218
219
220
221 OS_ENTER_CRITICAL();
222 ticks = OSTime;
223 OS_EXIT_CRITICAL();
224 return (ticks);
225 }
226 #endif
227
228 /*
229 *********************************************************************************************************
230 * SET SYSTEM CLOCK
231 *
232 * Description: This function sets the 32-bit counter which keeps track of the number of clock ticks.
233 *
234 * Arguments : ticks specifies the new value that OSTime needs to take.
235 *
236 * Returns : none
237 *********************************************************************************************************
238 */
239
240 #if OS_TIME_GET_SET_EN > 0
241 void OSTimeSet (INT32U ticks)
242 {
243 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
C51 COMPILER V8.08 OS_TIME 08/04/2008 21:49:52 PAGE 6
#endif
246
247
248
249 OS_ENTER_CRITICAL();
250 OSTime = ticks;
251 OS_EXIT_CRITICAL();
252 }
253 #endif
C51 COMPILATION COMPLETE. 0 WARNING(S), 57 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -