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