source: rtems/doc/user/clock.t @ 5e60f15

Last change on this file since 5e60f15 was 5e60f15, checked in by Joel Sherrill <joel.sherrill@…>, on 07/15/08 at 21:50:40

2008-07-15 Joel Sherrill <joel.sherrill@…>

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