source: rtems/doc/user/clock.t @ a94c5a5d

4.104.114.84.95
Last change on this file since a94c5a5d was a94c5a5d, checked in by Joel Sherrill <joel.sherrill@…>, on 05/31/97 at 15:55:10

Changed bitwise OR's used to build up option and attribute sets
to be correct in either C or Ada.

Added the interrupt disable, enable, flash, and is in progress directives.

changed "97" to "1997"

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