source: rtems/doc/user/clock.t @ 87ed029

4.104.114.84.95
Last change on this file since 87ed029 was 87ed029, checked in by Joel Sherrill <joel.sherrill@…>, on 04/02/98 at 16:18:26

Added "findex" for all directive pages but it turns out that this
blows up both makeinfo and texi2dvi. So I have commented them out.

  • Property mode set to 100644
File size: 12.6 KB
Line 
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
13The clock manager provides support for time of day
14and other time related capabilities.  The directives provided by
15the 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
27For the features provided by the clock manager to be
28utilized, periodic timer interrupts are required.  Therefore, a
29real-time clock or hardware timer is necessary to create the
30timer interrupts.  The @code{@value{DIRPREFIX}clock_tick}
31directive is normally called
32by the timer ISR to announce to RTEMS that a system clock tick
33has occurred.  Elapsed time is measured in ticks.  A tick is
34defined to be an integral number of microseconds which is
35specified by the user in the Configuration Table.
36
37@subsection Time and Date Data Structures
38
39The clock facilities of the clock manager operate
40upon calendar time.  These directives utilize the following date
41and time @value{STRUCTURE} for the native time and date format:
42
43@ifset is-C
44@example
45struct 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
55typedef struct rtems_tod_control rtems_time_of_day;
56@end example
57@end ifset
58
59@ifset is-Ada
60@example
61type 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
75The native date and time format is the only format
76supported when setting the system date and time using the
77@code{@value{DIRPREFIX}clock_get} directive.  Some applications
78expect to operate on a "UNIX-style" date and time data structure.  The
79@code{@value{DIRPREFIX}clock_get} directive can optionally return
80the current date and time in the
81following @value{STRUCTURE}:
82
83@ifset is-C
84@example
85@group
86typedef 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
96type Clock_Time_Value is
97   record
98      Seconds      : Unsigned32;
99      Microseconds : Unsigned32;
100   end record;
101@end example
102@end ifset
103
104The seconds field in this @value{STRUCTURE} is the number of
105seconds since the RTEMS epoch of January 1, 1988.
106
107@subsection Clock Tick and Timeslicing
108
109Timeslicing is a task scheduling discipline in which
110tasks of equal priority are executed for a specific period of
111time before control of the CPU is passed to another task.  It is
112also sometimes referred to as the automatic round-robin
113scheduling algorithm.  The length of time allocated to each task
114is known as the quantum or timeslice.
115
116The system's timeslice is defined as an integral
117number of ticks, and is specified in the Configuration Table.
118The timeslice is defined for the entire system of tasks, but
119timeslicing is enabled and disabled on a per task basis.
120
121The @code{@value{DIRPREFIX}clock_tick}
122directive implements timeslicing by
123decrementing the running task's time-remaining counter when both
124timeslicing and preemption are enabled.  If the task's timeslice
125has expired, then that task will be preempted if there exists a
126ready task of equal priority.
127
128@subsection Delays
129
130A sleep timer allows a task to delay for a given
131interval or up until a given time, and then wake and continue
132execution.  This type of timer is created automatically by the
133@code{@value{DIRPREFIX}task_wake_after}
134and @code{@value{DIRPREFIX}task_wake_when} directives and, as a result,
135does not have an RTEMS ID.  Once activated, a sleep timer cannot
136be explicitly deleted.  Each task may activate one and only one
137sleep timer at a time.
138
139@subsection Timeouts
140
141Timeouts are a special type of timer automatically
142created 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. 
147Each task may have one and only one timeout active at a time. 
148When a timeout expires, it unblocks the task with a timeout status code.
149
150@section Operations
151
152@subsection Announcing a Tick
153
154RTEMS provides the @code{@value{DIRPREFIX}clock_tick} directive which is
155called from the user's real-time clock ISR to inform RTEMS that
156a tick has elapsed.  The tick frequency value, defined in
157microseconds, is a configuration parameter found in the
158Configuration Table.  RTEMS divides one million microseconds
159(one second) by the number of microseconds per tick to determine
160the number of calls to the
161@code{@value{DIRPREFIX}clock_tick} directive per second.  The
162frequency of @code{@value{DIRPREFIX}clock_tick}
163calls determines the resolution
164(granularity) for all time dependent RTEMS actions.  For
165example, calling @code{@value{DIRPREFIX}clock_tick}
166ten times per second yields a higher
167resolution than calling @code{@value{DIRPREFIX}clock_tick}
168two times per second.  The @code{@value{DIRPREFIX}clock_tick}
169directive is responsible for maintaining both
170calendar time and the dynamic set of timers.
171
172@subsection Setting the Time
173
174The @code{@value{DIRPREFIX}clock_set} directive allows a task or an ISR to
175set the date and time maintained by RTEMS.  If setting the date
176and time causes any outstanding timers to pass their deadline,
177then the expired timers will be fired during the invocation of
178the @code{@value{DIRPREFIX}clock_set} directive.
179
180@subsection Obtaining the Time
181
182The @code{@value{DIRPREFIX}clock_get} directive allows a task or an ISR to
183obtain the current date and time or date and time related
184information.  The current date and time can be returned in
185either native or UNIX-style format.  Additionally, the
186application can obtain date and time related information such as
187the number of seconds since the RTEMS epoch, the number of ticks
188since the executive was initialized, and the number of ticks per
189second.  The information returned by the
190@code{@value{DIRPREFIX}clock_get} directive is
191dependent on the option selected by the caller.  The following
192options 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
198date and time
199
200@item @code{@value{RPREFIX}CLOCK_GET_TICKS_SINCE_BOOT} - obtain number of ticks
201since RTEMS was initialized
202
203@item @code{@value{RPREFIX}CLOCK_GET_SECONDS_SINCE_EPOCH} - obtain number
204of seconds since RTEMS epoch
205
206@item @code{@value{RPREFIX}CLOCK_GET_TICKS_PER_SECOND} - obtain number of clock
207ticks per second
208
209@end itemize
210
211Calendar time operations will return an error code if
212invoked before the date and time have been set.
213
214@section Directives
215
216This section details the clock manager's directives.
217A subsection is dedicated to each of this manager's directives
218and describes the calling sequence, related constants, usage,
219and 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
229rtems_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
237procedure 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
250This directive sets the system date and time.  The
251date, time, and ticks in the time_buffer @value{STRUCTURE} are all
252range-checked, and an error is returned if any one is out of its
253valid range.
254
255@subheading NOTES:
256
257Years before 1988 are invalid.
258
259The system date and time are based on the configured
260tick rate (number of microseconds in a tick).
261
262Setting the time forward may cause a higher priority
263task, blocked waiting on a specific time, to be made ready.  In
264this case, the calling task will be preempted after the next
265clock tick.
266
267Re-initializing RTEMS causes the system date and time
268to be reset to an uninitialized state.  Another call to
269@code{@value{DIRPREFIX}clock_set} is required to re-initialize
270the 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
280rtems_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
289procedure 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
303This directive obtains the system date and time.  If
304the caller is attempting to obtain the date and time (i.e.
305option 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
308has 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.
311The 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
313ticks since the executive was initialized option is
314@code{@value{RPREFIX}CLOCK_GET_TICKS_SINCE_BOOT}).
315
316The 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
336type RTEMS.Time_Of_Day
337
338@item @code{@value{RPREFIX}CLOCK_GET_TIME_VALUE} - Address of an variable of
339type RTEMS.Clock_Time_Value
340
341@item @code{@value{RPREFIX}CLOCK_GET_TICKS_SINCE_BOOT} - Address of an
342variable of type RTEMS.Interval
343
344@item @code{@value{RPREFIX}CLOCK_GET_SECONDS_SINCE_EPOCH} - Address of an
345variable of type RTEMS.Interval
346
347@item @code{@value{RPREFIX}CLOCK_GET_TICKS_PER_SECOND} - Address of an
348variable of type RTEMS.Interval
349
350@end itemize
351@end ifset
352
353@subheading NOTES:
354
355This directive is callable from an ISR.
356
357This directive will not cause the running task to be
358preempted.  Re-initializing RTEMS causes the system date and
359time to be reset to an uninitialized state.  Another call to
360@code{@value{DIRPREFIX}clock_set} is required to re-initialize the
361system 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
371rtems_status_code rtems_clock_tick( void );
372@end example
373@end ifset
374
375@ifset is-Ada
376@example
377procedure 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
388This directive announces to RTEMS that a system clock
389tick has occurred.  The directive is usually called from the
390timer interrupt ISR of the local processor.  This directive
391maintains the system date and time, decrements timers for
392delayed tasks, timeouts, rate monotonic periods, and implements
393timeslicing.
394
395@subheading NOTES:
396
397This directive is typically called from an ISR.
398
399The microseconds_per_tick and ticks_per_timeslice
400parameters in the Configuration Table contain the number of
401microseconds per tick and number of ticks per timeslice,
402respectively.
403
Note: See TracBrowser for help on using the repository browser.