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 | |
---|
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 | @example |
---|
73 | struct 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 | |
---|
83 | typedef struct rtems_tod_control rtems_time_of_day; |
---|
84 | @end example |
---|
85 | |
---|
86 | |
---|
87 | The native date and time format is the only format |
---|
88 | supported when setting the system date and time using the |
---|
89 | clock_get directive. Some applications expect to operate on a |
---|
90 | "UNIX-style" date and time data structure. The clock_get |
---|
91 | directive can optionally return the current date and time in the |
---|
92 | following structure: |
---|
93 | |
---|
94 | @example |
---|
95 | @group |
---|
96 | typedef 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 | |
---|
104 | The seconds field in this structure is the number of |
---|
105 | seconds 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 | |
---|
112 | Timeslicing is a task scheduling discipline in which |
---|
113 | tasks of equal priority are executed for a specific period of |
---|
114 | time before control of the CPU is passed to another task. It is |
---|
115 | also sometimes referred to as the automatic round-robin |
---|
116 | scheduling algorithm. The length of time allocated to each task |
---|
117 | is known as the quantum or timeslice. |
---|
118 | |
---|
119 | The system's timeslice is defined as an integral |
---|
120 | number of ticks, and is specified in the Configuration Table. |
---|
121 | The timeslice is defined for the entire system of tasks, but |
---|
122 | timeslicing is enabled and disabled on a per task basis. |
---|
123 | |
---|
124 | The clock_tick directive implements timeslicing by |
---|
125 | decrementing the running task's time-remaining counter when both |
---|
126 | timeslicing and preemption are enabled. If the task's timeslice |
---|
127 | has expired, then that task will be preempted if there exists a |
---|
128 | ready 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 | |
---|
135 | A sleep timer allows a task to delay for a given |
---|
136 | interval or up until a given time, and then wake and continue |
---|
137 | execution. This type of timer is created automatically by the |
---|
138 | task_wake_after and task_wake_when directives and, as a result, |
---|
139 | does not have an RTEMS ID. Once activated, a sleep timer cannot |
---|
140 | be explicitly deleted. Each task may activate one and only one |
---|
141 | sleep timer at a time. |
---|
142 | |
---|
143 | @ifinfo |
---|
144 | @node Timeouts, Clock Manager Operations, Delays, Clock Manager Background |
---|
145 | @end ifinfo |
---|
146 | @subsection Timeouts |
---|
147 | |
---|
148 | Timeouts are a special type of timer automatically |
---|
149 | created when the timeout option is used on the |
---|
150 | message_queue_receive, event_receive, semaphore_obtain and |
---|
151 | region_get_segment directives. Each task may have one and only |
---|
152 | one timeout active at a time. When a timeout expires, it |
---|
153 | unblocks 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 | |
---|
172 | RTEMS provides the clock_tick directive which is |
---|
173 | called from the user's real-time clock ISR to inform RTEMS that |
---|
174 | a tick has elapsed. The tick frequency value, defined in |
---|
175 | microseconds, is a configuration parameter found in the |
---|
176 | Configuration Table. RTEMS divides one million microseconds |
---|
177 | (one second) by the number of microseconds per tick to determine |
---|
178 | the number of calls to the clock_tick directive per second. The |
---|
179 | frequency of clock_tick calls determines the resolution |
---|
180 | (granularity) for all time dependent RTEMS actions. For |
---|
181 | example, calling clock_tick ten times per second yields a higher |
---|
182 | resolution than calling clock_tick two times per second. The |
---|
183 | clock_tick directive is responsible for maintaining both |
---|
184 | calendar 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 | |
---|
191 | The clock_set directive allows a task or an ISR to |
---|
192 | set the date and time maintained by RTEMS. If setting the date |
---|
193 | and time causes any outstanding timers to pass their deadline, |
---|
194 | then the expired timers will be fired during the invocation of |
---|
195 | the 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 | |
---|
202 | The clock_get directive allows a task or an ISR to |
---|
203 | obtain the current date and time or date and time related |
---|
204 | information. The current date and time can be returned in |
---|
205 | either native or UNIX-style format. Additionally, the |
---|
206 | application can obtain date and time related information such as |
---|
207 | the number of seconds since the RTEMS epoch, the number of ticks |
---|
208 | since the executive was initialized, and the number of ticks per |
---|
209 | second. The information returned by the clock_get directive is |
---|
210 | dependent on the option selected by the caller. The following |
---|
211 | options 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 | |
---|
221 | Calendar time operations will return an error code if |
---|
222 | invoked 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 | |
---|
236 | This section details the clock manager's directives. |
---|
237 | A subsection is dedicated to each of this manager's directives |
---|
238 | and describes the calling sequence, related constants, usage, |
---|
239 | and 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 |
---|
250 | rtems_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 | |
---|
261 | This directive sets the system date and time. The |
---|
262 | date, time, and ticks in the time_buffer structure are all |
---|
263 | range-checked, and an error is returned if any one is out of its |
---|
264 | valid range. |
---|
265 | |
---|
266 | @subheading NOTES: |
---|
267 | |
---|
268 | Years before 1988 are invalid. |
---|
269 | |
---|
270 | The system date and time are based on the configured |
---|
271 | tick rate (number of microseconds in a tick). |
---|
272 | |
---|
273 | Setting the time forward may cause a higher priority |
---|
274 | task, blocked waiting on a specific time, to be made ready. In |
---|
275 | this case, the calling task will be preempted after the next |
---|
276 | clock tick. |
---|
277 | |
---|
278 | Re-initializing RTEMS causes the system date and time |
---|
279 | to be reset to an uninitialized state. Another call to |
---|
280 | clock_set is required to re-initialize the system date and time |
---|
281 | to 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 |
---|
292 | rtems_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 | |
---|
304 | This directive obtains the system date and time. If |
---|
305 | the caller is attempting to obtain the date and time (i.e. |
---|
306 | option is set to either CLOCK_GET_SECONDS_SINCE_EPOCH, |
---|
307 | CLOCK_GET_TOD, or CLOCK_GET_TIME_VALUE) and the date and time |
---|
308 | has not been set with a previous call to clock_set, then the |
---|
309 | NOT_DEFINED status code is returned. The caller can always |
---|
310 | obtain the number of ticks per second (option is |
---|
311 | CLOCK_GET_TICKS_PER_SECOND) and the number of ticks since the |
---|
312 | executive was initialized option is CLOCK_GET_TICKS_SINCE_BOOT). |
---|
313 | |
---|
314 | @subheading NOTES: |
---|
315 | |
---|
316 | This directive is callable from an ISR. |
---|
317 | |
---|
318 | This directive will not cause the running task to be |
---|
319 | preempted. Re-initializing RTEMS causes the system date and |
---|
320 | time to be reset to an uninitialized state. Another call to |
---|
321 | clock_set is required to re-initialize the system date and time |
---|
322 | to 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 |
---|
333 | rtems_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 | |
---|
341 | This directive announces to RTEMS that a system clock |
---|
342 | tick has occurred. The directive is usually called from the |
---|
343 | timer interrupt ISR of the local processor. This directive |
---|
344 | maintains the system date and time, decrements timers for |
---|
345 | delayed tasks, timeouts, rate monotonic periods, and implements |
---|
346 | timeslicing. |
---|
347 | |
---|
348 | @subheading NOTES: |
---|
349 | |
---|
350 | This directive is typically called from an ISR. |
---|
351 | |
---|
352 | The microseconds_per_tick and ticks_per_timeslice |
---|
353 | parameters in the Configuration Table contain the number of |
---|
354 | microseconds per tick and number of ticks per timeslice, |
---|
355 | respectively. |
---|
356 | |
---|