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