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

4.104.114.84.95
Last change on this file since ae68ff0 was ae68ff0, checked in by Joel Sherrill <joel.sherrill@…>, on 05/27/97 at 12:40:11

Initial revision

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