source: rtems/doc/user/clock.t @ 0660b4f8

4.104.114.84.95
Last change on this file since 0660b4f8 was 0660b4f8, checked in by Joel Sherrill <joel.sherrill@…>, on 11/16/99 at 19:50:56

Changed copyright date to 1999.

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