1 | @c |
---|
2 | @c COPYRIGHT (c) 1988-1998. |
---|
3 | @c On-Line Applications Research Corporation (OAR). |
---|
4 | @c All rights reserved. |
---|
5 | @c |
---|
6 | @c $Id$ |
---|
7 | @c |
---|
8 | |
---|
9 | @chapter Clock Manager |
---|
10 | |
---|
11 | @section Introduction |
---|
12 | |
---|
13 | The clock manager provides support for time of day |
---|
14 | and other time related capabilities. The directives provided by |
---|
15 | the clock manager are: |
---|
16 | |
---|
17 | @itemize @bullet |
---|
18 | @item @code{@value{DIRPREFIX}clock_set} - Set system date and time |
---|
19 | @item @code{@value{DIRPREFIX}clock_get} - Get system date and time information |
---|
20 | @item @code{@value{DIRPREFIX}clock_tick} - Announce a clock tick |
---|
21 | @end itemize |
---|
22 | |
---|
23 | @section Background |
---|
24 | |
---|
25 | @subsection Required Support |
---|
26 | |
---|
27 | For the features provided by the clock manager to be |
---|
28 | utilized, periodic timer interrupts are required. Therefore, a |
---|
29 | real-time clock or hardware timer is necessary to create the |
---|
30 | timer interrupts. The @code{@value{DIRPREFIX}clock_tick} |
---|
31 | directive is normally called |
---|
32 | by the timer ISR to announce to RTEMS that a system clock tick |
---|
33 | has occurred. Elapsed time is measured in ticks. A tick is |
---|
34 | defined to be an integral number of microseconds which is |
---|
35 | specified by the user in the Configuration Table. |
---|
36 | |
---|
37 | @subsection Time and Date Data Structures |
---|
38 | |
---|
39 | The clock facilities of the clock manager operate |
---|
40 | upon calendar time. These directives utilize the following date |
---|
41 | and time @value{STRUCTURE} for the native time and date format: |
---|
42 | |
---|
43 | @ifset is-C |
---|
44 | @example |
---|
45 | struct rtems_tod_control @{ |
---|
46 | rtems_unsigned32 year; /* greater than 1987 */ |
---|
47 | rtems_unsigned32 month; /* 1 - 12 */ |
---|
48 | rtems_unsigned32 day; /* 1 - 31 */ |
---|
49 | rtems_unsigned32 hour; /* 0 - 23 */ |
---|
50 | rtems_unsigned32 minute; /* 0 - 59 */ |
---|
51 | rtems_unsigned32 second; /* 0 - 59 */ |
---|
52 | rtems_unsigned32 ticks; /* elapsed between seconds */ |
---|
53 | @}; |
---|
54 | |
---|
55 | typedef struct rtems_tod_control rtems_time_of_day; |
---|
56 | @end example |
---|
57 | @end ifset |
---|
58 | |
---|
59 | @ifset is-Ada |
---|
60 | @example |
---|
61 | type Time_Of_Day is |
---|
62 | record |
---|
63 | Year : RTEMS.Unsigned32; -- year, A.D. |
---|
64 | Month : RTEMS.Unsigned32; -- month, 1 .. 12 |
---|
65 | Day : RTEMS.Unsigned32; -- day, 1 .. 31 |
---|
66 | Hour : RTEMS.Unsigned32; -- hour, 0 .. 23 |
---|
67 | Minute : RTEMS.Unsigned32; -- minute, 0 .. 59 |
---|
68 | Second : RTEMS.Unsigned32; -- second, 0 .. 59 |
---|
69 | Ticks : RTEMS.Unsigned32; -- elapsed ticks between seconds |
---|
70 | end record; |
---|
71 | @end example |
---|
72 | @end ifset |
---|
73 | |
---|
74 | |
---|
75 | The native date and time format is the only format |
---|
76 | supported when setting the system date and time using the |
---|
77 | @code{@value{DIRPREFIX}clock_get} directive. Some applications |
---|
78 | expect to operate on a "UNIX-style" date and time data structure. The |
---|
79 | @code{@value{DIRPREFIX}clock_get} directive can optionally return |
---|
80 | the current date and time in the |
---|
81 | following @value{STRUCTURE}: |
---|
82 | |
---|
83 | @ifset is-C |
---|
84 | @example |
---|
85 | @group |
---|
86 | typedef struct @{ |
---|
87 | rtems_unsigned32 seconds; /* seconds since RTEMS epoch*/ |
---|
88 | rtems_unsigned32 microseconds; /* since last second */ |
---|
89 | @} rtems_clock_time_value; |
---|
90 | @end group |
---|
91 | @end example |
---|
92 | @end ifset |
---|
93 | |
---|
94 | @ifset is-Ada |
---|
95 | @example |
---|
96 | type Clock_Time_Value is |
---|
97 | record |
---|
98 | Seconds : Unsigned32; |
---|
99 | Microseconds : Unsigned32; |
---|
100 | end record; |
---|
101 | @end example |
---|
102 | @end ifset |
---|
103 | |
---|
104 | The seconds field in this @value{STRUCTURE} is the number of |
---|
105 | seconds since the RTEMS epoch of January 1, 1988. |
---|
106 | |
---|
107 | @subsection Clock Tick and Timeslicing |
---|
108 | |
---|
109 | Timeslicing is a task scheduling discipline in which |
---|
110 | tasks of equal priority are executed for a specific period of |
---|
111 | time before control of the CPU is passed to another task. It is |
---|
112 | also sometimes referred to as the automatic round-robin |
---|
113 | scheduling algorithm. The length of time allocated to each task |
---|
114 | is known as the quantum or timeslice. |
---|
115 | |
---|
116 | The system's timeslice is defined as an integral |
---|
117 | number of ticks, and is specified in the Configuration Table. |
---|
118 | The timeslice is defined for the entire system of tasks, but |
---|
119 | timeslicing is enabled and disabled on a per task basis. |
---|
120 | |
---|
121 | The @code{@value{DIRPREFIX}clock_tick} |
---|
122 | directive implements timeslicing by |
---|
123 | decrementing the running task's time-remaining counter when both |
---|
124 | timeslicing and preemption are enabled. If the task's timeslice |
---|
125 | has expired, then that task will be preempted if there exists a |
---|
126 | ready task of equal priority. |
---|
127 | |
---|
128 | @subsection Delays |
---|
129 | |
---|
130 | A sleep timer allows a task to delay for a given |
---|
131 | interval or up until a given time, and then wake and continue |
---|
132 | execution. This type of timer is created automatically by the |
---|
133 | @code{@value{DIRPREFIX}task_wake_after} |
---|
134 | and @code{@value{DIRPREFIX}task_wake_when} directives and, as a result, |
---|
135 | does not have an RTEMS ID. Once activated, a sleep timer cannot |
---|
136 | be explicitly deleted. Each task may activate one and only one |
---|
137 | sleep timer at a time. |
---|
138 | |
---|
139 | @subsection Timeouts |
---|
140 | |
---|
141 | Timeouts are a special type of timer automatically |
---|
142 | created when the timeout option is used on the |
---|
143 | @code{@value{DIRPREFIX}message_queue_receive}, |
---|
144 | @code{@value{DIRPREFIX}event_receive}, |
---|
145 | @code{@value{DIRPREFIX}semaphore_obtain} and |
---|
146 | @code{@value{DIRPREFIX}region_get_segment} directives. |
---|
147 | Each task may have one and only one timeout active at a time. |
---|
148 | When a timeout expires, it unblocks the task with a timeout status code. |
---|
149 | |
---|
150 | @section Operations |
---|
151 | |
---|
152 | @subsection Announcing a Tick |
---|
153 | |
---|
154 | RTEMS provides the @code{@value{DIRPREFIX}clock_tick} directive which is |
---|
155 | called from the user's real-time clock ISR to inform RTEMS that |
---|
156 | a tick has elapsed. The tick frequency value, defined in |
---|
157 | microseconds, is a configuration parameter found in the |
---|
158 | Configuration Table. RTEMS divides one million microseconds |
---|
159 | (one second) by the number of microseconds per tick to determine |
---|
160 | the number of calls to the |
---|
161 | @code{@value{DIRPREFIX}clock_tick} directive per second. The |
---|
162 | frequency of @code{@value{DIRPREFIX}clock_tick} |
---|
163 | calls determines the resolution |
---|
164 | (granularity) for all time dependent RTEMS actions. For |
---|
165 | example, calling @code{@value{DIRPREFIX}clock_tick} |
---|
166 | ten times per second yields a higher |
---|
167 | resolution than calling @code{@value{DIRPREFIX}clock_tick} |
---|
168 | two times per second. The @code{@value{DIRPREFIX}clock_tick} |
---|
169 | directive is responsible for maintaining both |
---|
170 | calendar time and the dynamic set of timers. |
---|
171 | |
---|
172 | @subsection Setting the Time |
---|
173 | |
---|
174 | The @code{@value{DIRPREFIX}clock_set} directive allows a task or an ISR to |
---|
175 | set the date and time maintained by RTEMS. If setting the date |
---|
176 | and time causes any outstanding timers to pass their deadline, |
---|
177 | then the expired timers will be fired during the invocation of |
---|
178 | the @code{@value{DIRPREFIX}clock_set} directive. |
---|
179 | |
---|
180 | @subsection Obtaining the Time |
---|
181 | |
---|
182 | The @code{@value{DIRPREFIX}clock_get} directive allows a task or an ISR to |
---|
183 | obtain the current date and time or date and time related |
---|
184 | information. The current date and time can be returned in |
---|
185 | either native or UNIX-style format. Additionally, the |
---|
186 | application can obtain date and time related information such as |
---|
187 | the number of seconds since the RTEMS epoch, the number of ticks |
---|
188 | since the executive was initialized, and the number of ticks per |
---|
189 | second. The information returned by the |
---|
190 | @code{@value{DIRPREFIX}clock_get} directive is |
---|
191 | dependent on the option selected by the caller. The following |
---|
192 | options are available: |
---|
193 | |
---|
194 | @itemize @bullet |
---|
195 | @item @code{@value{RPREFIX}CLOCK_GET_TOD} - obtain native style date and time |
---|
196 | |
---|
197 | @item @code{@value{RPREFIX}CLOCK_GET_TIME_VALUE} - obtain UNIX-style |
---|
198 | date and time |
---|
199 | |
---|
200 | @item @code{@value{RPREFIX}CLOCK_GET_TICKS_SINCE_BOOT} - obtain number of ticks |
---|
201 | since RTEMS was initialized |
---|
202 | |
---|
203 | @item @code{@value{RPREFIX}CLOCK_GET_SECONDS_SINCE_EPOCH} - obtain number |
---|
204 | of seconds since RTEMS epoch |
---|
205 | |
---|
206 | @item @code{@value{RPREFIX}CLOCK_GET_TICKS_PER_SECOND} - obtain number of clock |
---|
207 | ticks per second |
---|
208 | |
---|
209 | @end itemize |
---|
210 | |
---|
211 | Calendar time operations will return an error code if |
---|
212 | invoked before the date and time have been set. |
---|
213 | |
---|
214 | @section Directives |
---|
215 | |
---|
216 | This section details the clock manager's directives. |
---|
217 | A subsection is dedicated to each of this manager's directives |
---|
218 | and describes the calling sequence, related constants, usage, |
---|
219 | and status codes. |
---|
220 | |
---|
221 | @page |
---|
222 | @subsection CLOCK_SET - Set system date and time |
---|
223 | |
---|
224 | @subheading CALLING SEQUENCE: |
---|
225 | |
---|
226 | @ifset is-C |
---|
227 | @c @findex rtems_clock_set |
---|
228 | @example |
---|
229 | rtems_status_code rtems_clock_set( |
---|
230 | rtems_time_of_day *time_buffer |
---|
231 | ); |
---|
232 | @end example |
---|
233 | @end ifset |
---|
234 | |
---|
235 | @ifset is-Ada |
---|
236 | @example |
---|
237 | procedure Clock_Set ( |
---|
238 | Time_Buffer : in RTEMS.Time_Of_Day; |
---|
239 | Result : out RTEMS.Status_Codes |
---|
240 | ); |
---|
241 | @end example |
---|
242 | @end ifset |
---|
243 | |
---|
244 | @subheading DIRECTIVE STATUS CODES: |
---|
245 | @code{@value{RPREFIX}SUCCESSFUL} - date and time set successfully@* |
---|
246 | @code{INVALID_TIME_OF_DAY} - invalid time of day |
---|
247 | |
---|
248 | @subheading DESCRIPTION: |
---|
249 | |
---|
250 | This directive sets the system date and time. The |
---|
251 | date, time, and ticks in the time_buffer @value{STRUCTURE} are all |
---|
252 | range-checked, and an error is returned if any one is out of its |
---|
253 | valid range. |
---|
254 | |
---|
255 | @subheading NOTES: |
---|
256 | |
---|
257 | Years before 1988 are invalid. |
---|
258 | |
---|
259 | The system date and time are based on the configured |
---|
260 | tick rate (number of microseconds in a tick). |
---|
261 | |
---|
262 | Setting the time forward may cause a higher priority |
---|
263 | task, blocked waiting on a specific time, to be made ready. In |
---|
264 | this case, the calling task will be preempted after the next |
---|
265 | clock tick. |
---|
266 | |
---|
267 | Re-initializing RTEMS causes the system date and time |
---|
268 | to be reset to an uninitialized state. Another call to |
---|
269 | @code{@value{DIRPREFIX}clock_set} is required to re-initialize |
---|
270 | the system date and time to application specific specifications. |
---|
271 | |
---|
272 | @page |
---|
273 | @subsection CLOCK_GET - Get system date and time information |
---|
274 | |
---|
275 | @subheading CALLING SEQUENCE: |
---|
276 | |
---|
277 | @ifset is-C |
---|
278 | @c @findex rtems_clock_get |
---|
279 | @example |
---|
280 | rtems_status_code rtems_clock_get( |
---|
281 | rtems_clock_get_options option, |
---|
282 | void *time_buffer |
---|
283 | ); |
---|
284 | @end example |
---|
285 | @end ifset |
---|
286 | |
---|
287 | @ifset is-Ada |
---|
288 | @example |
---|
289 | procedure Clock_Get ( |
---|
290 | Option : in RTEMS.Clock_Get_Options; |
---|
291 | Time_Buffer : in RTEMS.Address; |
---|
292 | Result : out RTEMS.Status_Codes |
---|
293 | ); |
---|
294 | @end example |
---|
295 | @end ifset |
---|
296 | |
---|
297 | @subheading DIRECTIVE STATUS CODES: |
---|
298 | @code{@value{RPREFIX}SUCCESSFUL} - current time obtained successfully@* |
---|
299 | @code{@value{RPREFIX}NOT_DEFINED} - system date and time is not set |
---|
300 | |
---|
301 | @subheading DESCRIPTION: |
---|
302 | |
---|
303 | This directive obtains the system date and time. If |
---|
304 | the caller is attempting to obtain the date and time (i.e. |
---|
305 | option is set to either @code{@value{RPREFIX}CLOCK_GET_SECONDS_SINCE_EPOCH}, |
---|
306 | @code{@value{RPREFIX}CLOCK_GET_TOD}, or |
---|
307 | @code{@value{RPREFIX}CLOCK_GET_TIME_VALUE}) and the date and time |
---|
308 | has not been set with a previous call to |
---|
309 | @code{@value{DIRPREFIX}clock_set}, then the |
---|
310 | @code{@value{RPREFIX}NOT_DEFINED} status code is returned. |
---|
311 | The caller can always obtain the number of ticks per second (option is |
---|
312 | @code{@value{RPREFIX}CLOCK_GET_TICKS_PER_SECOND}) and the number of |
---|
313 | ticks since the executive was initialized option is |
---|
314 | @code{@value{RPREFIX}CLOCK_GET_TICKS_SINCE_BOOT}). |
---|
315 | |
---|
316 | The data type expected for time_buffer is indicated below: |
---|
317 | |
---|
318 | @ifset is-C |
---|
319 | @itemize @bullet |
---|
320 | @item @code{@value{RPREFIX}CLOCK_GET_TOD} - (rtems_time_of_day *) |
---|
321 | |
---|
322 | @item @code{@value{RPREFIX}CLOCK_GET_TIME_VALUE} - (rtems_clock_time_value *) |
---|
323 | |
---|
324 | @item @code{@value{RPREFIX}CLOCK_GET_TICKS_SINCE_BOOT} - (rtems_interval *) |
---|
325 | |
---|
326 | @item @code{@value{RPREFIX}CLOCK_GET_SECONDS_SINCE_EPOCH} - (rtems_interval *) |
---|
327 | |
---|
328 | @item @code{@value{RPREFIX}CLOCK_GET_TICKS_PER_SECOND} - (rtems_interval *) |
---|
329 | |
---|
330 | @end itemize |
---|
331 | @end ifset |
---|
332 | |
---|
333 | @ifset is-Ada |
---|
334 | @itemize @bullet |
---|
335 | @item @code{@value{RPREFIX}CLOCK_GET_TOD} - Address of an variable of |
---|
336 | type RTEMS.Time_Of_Day |
---|
337 | |
---|
338 | @item @code{@value{RPREFIX}CLOCK_GET_TIME_VALUE} - Address of an variable of |
---|
339 | type RTEMS.Clock_Time_Value |
---|
340 | |
---|
341 | @item @code{@value{RPREFIX}CLOCK_GET_TICKS_SINCE_BOOT} - Address of an |
---|
342 | variable of type RTEMS.Interval |
---|
343 | |
---|
344 | @item @code{@value{RPREFIX}CLOCK_GET_SECONDS_SINCE_EPOCH} - Address of an |
---|
345 | variable of type RTEMS.Interval |
---|
346 | |
---|
347 | @item @code{@value{RPREFIX}CLOCK_GET_TICKS_PER_SECOND} - Address of an |
---|
348 | variable of type RTEMS.Interval |
---|
349 | |
---|
350 | @end itemize |
---|
351 | @end ifset |
---|
352 | |
---|
353 | @subheading NOTES: |
---|
354 | |
---|
355 | This directive is callable from an ISR. |
---|
356 | |
---|
357 | This directive will not cause the running task to be |
---|
358 | preempted. Re-initializing RTEMS causes the system date and |
---|
359 | time to be reset to an uninitialized state. Another call to |
---|
360 | @code{@value{DIRPREFIX}clock_set} is required to re-initialize the |
---|
361 | system date and time to application specific specifications. |
---|
362 | |
---|
363 | @page |
---|
364 | @subsection CLOCK_TICK - Announce a clock tick |
---|
365 | |
---|
366 | @subheading CALLING SEQUENCE: |
---|
367 | |
---|
368 | @ifset is-C |
---|
369 | @c @findex rtems_clock_tick |
---|
370 | @example |
---|
371 | rtems_status_code rtems_clock_tick( void ); |
---|
372 | @end example |
---|
373 | @end ifset |
---|
374 | |
---|
375 | @ifset is-Ada |
---|
376 | @example |
---|
377 | procedure Clock_Tick ( |
---|
378 | Result : out RTEMS.Status_Codes |
---|
379 | ); |
---|
380 | @end example |
---|
381 | @end ifset |
---|
382 | |
---|
383 | @subheading DIRECTIVE STATUS CODES: |
---|
384 | @code{@value{RPREFIX}SUCCESSFUL} - current time obtained successfully |
---|
385 | |
---|
386 | @subheading DESCRIPTION: |
---|
387 | |
---|
388 | This directive announces to RTEMS that a system clock |
---|
389 | tick has occurred. The directive is usually called from the |
---|
390 | timer interrupt ISR of the local processor. This directive |
---|
391 | maintains the system date and time, decrements timers for |
---|
392 | delayed tasks, timeouts, rate monotonic periods, and implements |
---|
393 | timeslicing. |
---|
394 | |
---|
395 | @subheading NOTES: |
---|
396 | |
---|
397 | This directive is typically called from an ISR. |
---|
398 | |
---|
399 | The microseconds_per_tick and ticks_per_timeslice |
---|
400 | parameters in the Configuration Table contain the number of |
---|
401 | microseconds per tick and number of ticks per timeslice, |
---|
402 | respectively. |
---|
403 | |
---|