source: rtems/doc/user/clock.t @ 78287f41

4.104.114.84.95
Last change on this file since 78287f41 was 6449498, checked in by Joel Sherrill <joel.sherrill@…>, on 01/17/02 at 21:47:47

2001-01-17 Joel Sherrill <joel@…>

  • SUPPORT, LICENSE: New files.
  • Numerous files touched as part of merging the 4.5 branch onto the mainline development trunk and ensuring that the script that cuts snapshots and releases works on the documentation.
  • 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  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
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  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
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_TIME_OF_DAY} - invalid time of day
266
267@subheading DESCRIPTION:
268
269This directive sets the system date and time.  The
270date, time, and ticks in the time_buffer @value{STRUCTURE} are all
271range-checked, and an error is returned if any one is out of its
272valid range.
273
274@subheading NOTES:
275
276Years before 1988 are invalid.
277
278The system date and time are based on the configured
279tick rate (number of microseconds in a tick).
280
281Setting the time forward may cause a higher priority
282task, blocked waiting on a specific time, to be made ready.  In
283this case, the calling task will be preempted after the next
284clock tick.
285
286Re-initializing RTEMS causes the system date and time
287to be reset to an uninitialized state.  Another call to
288@code{@value{DIRPREFIX}clock_set} is required to re-initialize
289the 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
304rtems_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
313procedure 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
327This directive obtains the system date and time.  If
328the caller is attempting to obtain the date and time (i.e.
329option 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
332has 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.
335The 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
337ticks since the executive was initialized option is
338@code{@value{RPREFIX}CLOCK_GET_TICKS_SINCE_BOOT}).
339
340The @code{option} argument may taken on any value of the enumerated
341type @code{rtems_clock_get_options}.  The data type expected for
342@code{time_buffer} is based on the value of @code{option} as
343indicated 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
364type RTEMS.Time_Of_Day
365
366@item @code{@value{RPREFIX}CLOCK_GET_TIME_VALUE} - Address of an variable of
367type RTEMS.Clock_Time_Value
368
369@item @code{@value{RPREFIX}CLOCK_GET_TICKS_SINCE_BOOT} - Address of an
370variable of type RTEMS.Interval
371
372@item @code{@value{RPREFIX}CLOCK_GET_SECONDS_SINCE_EPOCH} - Address of an
373variable of type RTEMS.Interval
374
375@item @code{@value{RPREFIX}CLOCK_GET_TICKS_PER_SECOND} - Address of an
376variable of type RTEMS.Interval
377
378@end itemize
379@end ifset
380
381@subheading NOTES:
382
383This directive is callable from an ISR.
384
385This directive will not cause the running task to be
386preempted.  Re-initializing RTEMS causes the system date and
387time to be reset to an uninitialized state.  Another call to
388@code{@value{DIRPREFIX}clock_set} is required to re-initialize the
389system 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
404rtems_status_code rtems_clock_tick( void );
405@end example
406@end ifset
407
408@ifset is-Ada
409@example
410procedure 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
421This directive announces to RTEMS that a system clock
422tick has occurred.  The directive is usually called from the
423timer interrupt ISR of the local processor.  This directive
424maintains the system date and time, decrements timers for
425delayed tasks, timeouts, rate monotonic periods, and implements
426timeslicing.
427
428@subheading NOTES:
429
430This directive is typically called from an ISR.
431
432The microseconds_per_tick and ticks_per_timeslice
433parameters in the Configuration Table contain the number of
434microseconds per tick and number of ticks per timeslice,
435respectively.
436
Note: See TracBrowser for help on using the repository browser.