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 | |
---|
25 | The clock manager provides support for time of day |
---|
26 | and other time related capabilities. The directives provided by |
---|
27 | the 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 | |
---|
54 | For the features provided by the clock manager to be |
---|
55 | utilized, periodic timer interrupts are required. Therefore, a |
---|
56 | real-time clock or hardware timer is necessary to create the |
---|
57 | timer interrupts. The clock_tick directive is normally called |
---|
58 | by the timer ISR to announce to RTEMS that a system clock tick |
---|
59 | has occurred. Elapsed time is measured in ticks. A tick is |
---|
60 | defined to be an integral number of microseconds which is |
---|
61 | specified 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 | |
---|
68 | The clock facilities of the clock manager operate |
---|
69 | upon calendar time. These directives utilize the following date |
---|
70 | and time structure for the native time and date format: |
---|
71 | |
---|
72 | @ifset is-C |
---|
73 | @example |
---|
74 | struct 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 | |
---|
84 | typedef struct rtems_tod_control rtems_time_of_day; |
---|
85 | @end example |
---|
86 | @end ifset |
---|
87 | |
---|
88 | @ifset is-Ada |
---|
89 | @example |
---|
90 | type 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 | |
---|
104 | The native date and time format is the only format |
---|
105 | supported when setting the system date and time using the |
---|
106 | clock_get directive. Some applications expect to operate on a |
---|
107 | "UNIX-style" date and time data structure. The clock_get |
---|
108 | directive can optionally return the current date and time in the |
---|
109 | following structure: |
---|
110 | |
---|
111 | @ifset is-C |
---|
112 | @example |
---|
113 | @group |
---|
114 | typedef 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 |
---|
124 | type Clock_Time_Value is |
---|
125 | record |
---|
126 | Seconds : Unsigned32; |
---|
127 | Microseconds : Unsigned32; |
---|
128 | end record; |
---|
129 | @end example |
---|
130 | @end ifset |
---|
131 | |
---|
132 | The seconds field in this structure is the number of |
---|
133 | seconds 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 | |
---|
140 | Timeslicing is a task scheduling discipline in which |
---|
141 | tasks of equal priority are executed for a specific period of |
---|
142 | time before control of the CPU is passed to another task. It is |
---|
143 | also sometimes referred to as the automatic round-robin |
---|
144 | scheduling algorithm. The length of time allocated to each task |
---|
145 | is known as the quantum or timeslice. |
---|
146 | |
---|
147 | The system's timeslice is defined as an integral |
---|
148 | number of ticks, and is specified in the Configuration Table. |
---|
149 | The timeslice is defined for the entire system of tasks, but |
---|
150 | timeslicing is enabled and disabled on a per task basis. |
---|
151 | |
---|
152 | The clock_tick directive implements timeslicing by |
---|
153 | decrementing the running task's time-remaining counter when both |
---|
154 | timeslicing and preemption are enabled. If the task's timeslice |
---|
155 | has expired, then that task will be preempted if there exists a |
---|
156 | ready 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 | |
---|
163 | A sleep timer allows a task to delay for a given |
---|
164 | interval or up until a given time, and then wake and continue |
---|
165 | execution. This type of timer is created automatically by the |
---|
166 | task_wake_after and task_wake_when directives and, as a result, |
---|
167 | does not have an RTEMS ID. Once activated, a sleep timer cannot |
---|
168 | be explicitly deleted. Each task may activate one and only one |
---|
169 | sleep timer at a time. |
---|
170 | |
---|
171 | @ifinfo |
---|
172 | @node Timeouts, Clock Manager Operations, Delays, Clock Manager Background |
---|
173 | @end ifinfo |
---|
174 | @subsection Timeouts |
---|
175 | |
---|
176 | Timeouts are a special type of timer automatically |
---|
177 | created when the timeout option is used on the |
---|
178 | message_queue_receive, event_receive, semaphore_obtain and |
---|
179 | region_get_segment directives. Each task may have one and only |
---|
180 | one timeout active at a time. When a timeout expires, it |
---|
181 | unblocks 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 | |
---|
200 | RTEMS provides the clock_tick directive which is |
---|
201 | called from the user's real-time clock ISR to inform RTEMS that |
---|
202 | a tick has elapsed. The tick frequency value, defined in |
---|
203 | microseconds, is a configuration parameter found in the |
---|
204 | Configuration Table. RTEMS divides one million microseconds |
---|
205 | (one second) by the number of microseconds per tick to determine |
---|
206 | the number of calls to the clock_tick directive per second. The |
---|
207 | frequency of clock_tick calls determines the resolution |
---|
208 | (granularity) for all time dependent RTEMS actions. For |
---|
209 | example, calling clock_tick ten times per second yields a higher |
---|
210 | resolution than calling clock_tick two times per second. The |
---|
211 | clock_tick directive is responsible for maintaining both |
---|
212 | calendar 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 | |
---|
219 | The clock_set directive allows a task or an ISR to |
---|
220 | set the date and time maintained by RTEMS. If setting the date |
---|
221 | and time causes any outstanding timers to pass their deadline, |
---|
222 | then the expired timers will be fired during the invocation of |
---|
223 | the 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 | |
---|
230 | The clock_get directive allows a task or an ISR to |
---|
231 | obtain the current date and time or date and time related |
---|
232 | information. The current date and time can be returned in |
---|
233 | either native or UNIX-style format. Additionally, the |
---|
234 | application can obtain date and time related information such as |
---|
235 | the number of seconds since the RTEMS epoch, the number of ticks |
---|
236 | since the executive was initialized, and the number of ticks per |
---|
237 | second. The information returned by the clock_get directive is |
---|
238 | dependent on the option selected by the caller. The following |
---|
239 | options 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 |
---|
247 | since RTEMS was initialized |
---|
248 | |
---|
249 | @item @code{CLOCK_GET_SECONDS_SINCE_EPOCH} - obtain number of seconds |
---|
250 | since RTEMS epoch |
---|
251 | |
---|
252 | @item @code{CLOCK_GET_TICKS_PER_SECOND} - obtain number of clock ticks |
---|
253 | per second |
---|
254 | |
---|
255 | @end itemize |
---|
256 | |
---|
257 | Calendar time operations will return an error code if |
---|
258 | invoked 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 | |
---|
272 | This section details the clock manager's directives. |
---|
273 | A subsection is dedicated to each of this manager's directives |
---|
274 | and describes the calling sequence, related constants, usage, |
---|
275 | and 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 |
---|
287 | rtems_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 |
---|
295 | procedure 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 | |
---|
308 | This directive sets the system date and time. The |
---|
309 | date, time, and ticks in the time_buffer structure are all |
---|
310 | range-checked, and an error is returned if any one is out of its |
---|
311 | valid range. |
---|
312 | |
---|
313 | @subheading NOTES: |
---|
314 | |
---|
315 | Years before 1988 are invalid. |
---|
316 | |
---|
317 | The system date and time are based on the configured |
---|
318 | tick rate (number of microseconds in a tick). |
---|
319 | |
---|
320 | Setting the time forward may cause a higher priority |
---|
321 | task, blocked waiting on a specific time, to be made ready. In |
---|
322 | this case, the calling task will be preempted after the next |
---|
323 | clock tick. |
---|
324 | |
---|
325 | Re-initializing RTEMS causes the system date and time |
---|
326 | to be reset to an uninitialized state. Another call to |
---|
327 | clock_set is required to re-initialize the system date and time |
---|
328 | to 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 |
---|
340 | rtems_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 |
---|
349 | procedure 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 | |
---|
363 | This directive obtains the system date and time. If |
---|
364 | the caller is attempting to obtain the date and time (i.e. |
---|
365 | option 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 |
---|
367 | has not been set with a previous call to clock_set, then the |
---|
368 | @code{NOT_DEFINED} status code is returned. The caller can always |
---|
369 | obtain the number of ticks per second (option is |
---|
370 | @code{CLOCK_GET_TICKS_PER_SECOND}) and the number of ticks since the |
---|
371 | executive was initialized option is @code{CLOCK_GET_TICKS_SINCE_BOOT}). |
---|
372 | |
---|
373 | @subheading NOTES: |
---|
374 | |
---|
375 | This directive is callable from an ISR. |
---|
376 | |
---|
377 | This directive will not cause the running task to be |
---|
378 | preempted. Re-initializing RTEMS causes the system date and |
---|
379 | time to be reset to an uninitialized state. Another call to |
---|
380 | clock_set is required to re-initialize the system date and time |
---|
381 | to 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 |
---|
393 | rtems_status_code rtems_clock_tick( void ); |
---|
394 | @end example |
---|
395 | @end ifset |
---|
396 | |
---|
397 | @ifset is-Ada |
---|
398 | @example |
---|
399 | procedure 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 | |
---|
410 | This directive announces to RTEMS that a system clock |
---|
411 | tick has occurred. The directive is usually called from the |
---|
412 | timer interrupt ISR of the local processor. This directive |
---|
413 | maintains the system date and time, decrements timers for |
---|
414 | delayed tasks, timeouts, rate monotonic periods, and implements |
---|
415 | timeslicing. |
---|
416 | |
---|
417 | @subheading NOTES: |
---|
418 | |
---|
419 | This directive is typically called from an ISR. |
---|
420 | |
---|
421 | The microseconds_per_tick and ticks_per_timeslice |
---|
422 | parameters in the Configuration Table contain the number of |
---|
423 | microseconds per tick and number of ticks per timeslice, |
---|
424 | respectively. |
---|
425 | |
---|