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 Timer Manager |
---|
10 | |
---|
11 | @cindex timers |
---|
12 | |
---|
13 | @section Introduction |
---|
14 | |
---|
15 | The timer manager provides support for timer |
---|
16 | facilities. The directives provided by the timer manager are: |
---|
17 | |
---|
18 | @itemize @bullet |
---|
19 | @item @code{@value{DIRPREFIX}timer_create} - Create a timer |
---|
20 | @item @code{@value{DIRPREFIX}timer_ident} - Get ID of a timer |
---|
21 | @item @code{@value{DIRPREFIX}timer_cancel} - Cancel a timer |
---|
22 | @item @code{@value{DIRPREFIX}timer_delete} - Delete a timer |
---|
23 | @item @code{@value{DIRPREFIX}timer_fire_after} - Fire timer after interval |
---|
24 | @item @code{@value{DIRPREFIX}timer_fire_when} - Fire timer when specified |
---|
25 | @item @code{@value{DIRPREFIX}timer_reset} - Reset an interval timer |
---|
26 | @end itemize |
---|
27 | |
---|
28 | |
---|
29 | @section Background |
---|
30 | |
---|
31 | @subsection Required Support |
---|
32 | |
---|
33 | A clock tick is required to support the functionality provided by this manager. |
---|
34 | |
---|
35 | @subsection Timers |
---|
36 | |
---|
37 | A timer is an RTEMS object which allows the |
---|
38 | application to schedule operations to occur at specific times in |
---|
39 | the future. User supplied timer service routines are invoked by |
---|
40 | the @code{@value{DIRPREFIX}clock_tick} directive |
---|
41 | when the timer fires. Timer service routines may perform |
---|
42 | any operations or directives which normally |
---|
43 | would be performed by the application code which invoked the |
---|
44 | @code{@value{DIRPREFIX}clock_tick} directive. |
---|
45 | |
---|
46 | The timer can be used to implement watchdog routines |
---|
47 | which only fire to denote that an application error has |
---|
48 | occurred. The timer is reset at specific points in the |
---|
49 | application to insure that the watchdog does not fire. Thus, if |
---|
50 | the application does not reset the watchdog timer, then the |
---|
51 | timer service routine will fire to indicate that the application |
---|
52 | has failed to reach a reset point. This use of a timer is |
---|
53 | sometimes referred to as a "keep alive" or a "deadman" timer. |
---|
54 | |
---|
55 | @subsection Timer Service Routines |
---|
56 | |
---|
57 | The timer service routine should adhere to @value{LANGUAGE} calling |
---|
58 | conventions and have a prototype similar to the following: |
---|
59 | |
---|
60 | @ifset is-C |
---|
61 | @example |
---|
62 | rtems_timer_service_routine user_routine( |
---|
63 | rtems_id timer_id, |
---|
64 | void *user_data |
---|
65 | ); |
---|
66 | @end example |
---|
67 | @end ifset |
---|
68 | |
---|
69 | @ifset is-Ada |
---|
70 | @example |
---|
71 | procedure User_Routine( |
---|
72 | Timer_ID : in RTEMS.ID; |
---|
73 | User_Data : in System.Address |
---|
74 | ); |
---|
75 | @end example |
---|
76 | @end ifset |
---|
77 | |
---|
78 | Where the timer_id parameter is the RTEMS object ID |
---|
79 | of the timer which is being fired and user_data is a pointer to |
---|
80 | user-defined information which may be utilized by the timer |
---|
81 | service routine. The argument user_data may be NULL. |
---|
82 | |
---|
83 | @section Operations |
---|
84 | |
---|
85 | @subsection Creating a Timer |
---|
86 | |
---|
87 | The @code{@value{DIRPREFIX}timer_create} directive creates a timer by |
---|
88 | allocating a Timer Control Block (TMCB), assigning the timer a |
---|
89 | user-specified name, and assigning it a timer ID. Newly created |
---|
90 | timers do not have a timer service routine associated with them |
---|
91 | and are not active. |
---|
92 | |
---|
93 | @subsection Obtaining Timer IDs |
---|
94 | |
---|
95 | When a timer is created, RTEMS generates a unique |
---|
96 | timer ID and assigns it to the created timer until it is |
---|
97 | deleted. The timer ID may be obtained by either of two methods. |
---|
98 | First, as the result of an invocation of the |
---|
99 | @code{@value{DIRPREFIX}timer_create} |
---|
100 | directive, the timer ID is stored in a user provided location. |
---|
101 | Second, the timer ID may be obtained later using the |
---|
102 | @code{@value{DIRPREFIX}timer_ident} directive. The timer ID |
---|
103 | is used by other directives to manipulate this timer. |
---|
104 | |
---|
105 | @subsection Initiating an Interval Timer |
---|
106 | |
---|
107 | The @code{@value{DIRPREFIX}timer_fire_after} directive initiates a timer to |
---|
108 | fire a user provided timer service routine after the specified |
---|
109 | number of clock ticks have elapsed. When the interval has |
---|
110 | elapsed, the timer service routine will be invoked from the |
---|
111 | @code{@value{DIRPREFIX}clock_tick} directive. |
---|
112 | |
---|
113 | @subsection Initiating a Time of Day Timer |
---|
114 | |
---|
115 | The @code{@value{DIRPREFIX}timer_fire_when} directive initiates a timer to |
---|
116 | fire a user provided timer service routine when the specified |
---|
117 | time of day has been reached. When the interval has elapsed, |
---|
118 | the timer service routine will be invoked from the |
---|
119 | @code{@value{DIRPREFIX}clock_tick} directive. |
---|
120 | |
---|
121 | @subsection Canceling a Timer |
---|
122 | |
---|
123 | The @code{@value{DIRPREFIX}timer_cancel} directive is used to halt the |
---|
124 | specified timer. Once canceled, the timer service routine will |
---|
125 | not fire unless the timer is reinitiated. The timer can be |
---|
126 | reinitiated using the @code{@value{DIRPREFIX}timer_reset}, |
---|
127 | @code{@value{DIRPREFIX}timer_fire_after}, and |
---|
128 | @code{@value{DIRPREFIX}timer_fire_when} directives. |
---|
129 | |
---|
130 | @subsection Resetting a Timer |
---|
131 | |
---|
132 | The @code{@value{DIRPREFIX}timer_reset} directive is used to restore an |
---|
133 | interval timer initiated by a previous invocation of |
---|
134 | @code{@value{DIRPREFIX}timer_fire_after} to |
---|
135 | its original interval length. If the |
---|
136 | timer has not been used or the last usage of this timer |
---|
137 | was by a @code{@value{DIRPREFIX}timer_fire_when} directive, then an error is |
---|
138 | returned. The timer service routine is not changed or |
---|
139 | fired by this directive. |
---|
140 | |
---|
141 | @subsection Deleting a Timer |
---|
142 | |
---|
143 | The @code{@value{DIRPREFIX}timer_delete} directive is used to delete a timer. |
---|
144 | If the timer is running and has not expired, the timer is |
---|
145 | automatically canceled. The timer's control block is returned |
---|
146 | to the TMCB free list when it is deleted. A timer can be |
---|
147 | deleted by a task other than the task which created the timer. |
---|
148 | Any subsequent references to the timer's name and ID are invalid. |
---|
149 | |
---|
150 | @section Directives |
---|
151 | |
---|
152 | This section details the timer manager's directives. |
---|
153 | A subsection is dedicated to each of this manager's directives |
---|
154 | and describes the calling sequence, related constants, usage, |
---|
155 | and status codes. |
---|
156 | |
---|
157 | @c |
---|
158 | @c |
---|
159 | @c |
---|
160 | @page |
---|
161 | @subsection TIMER_CREATE - Create a timer |
---|
162 | |
---|
163 | @cindex create a timer |
---|
164 | |
---|
165 | @subheading CALLING SEQUENCE: |
---|
166 | |
---|
167 | @ifset is-C |
---|
168 | @findex rtems_timer_create |
---|
169 | @example |
---|
170 | rtems_status_code rtems_timer_create( |
---|
171 | rtems_name name, |
---|
172 | rtems_id *id |
---|
173 | ); |
---|
174 | @end example |
---|
175 | @end ifset |
---|
176 | |
---|
177 | @ifset is-Ada |
---|
178 | @example |
---|
179 | procedure Timer_Create ( |
---|
180 | Name : in RTEMS.Name; |
---|
181 | ID : out RTEMS.ID; |
---|
182 | Result : out RTEMS.Status_Codes |
---|
183 | ); |
---|
184 | @end example |
---|
185 | @end ifset |
---|
186 | |
---|
187 | @subheading DIRECTIVE STATUS CODES: |
---|
188 | @code{@value{RPREFIX}SUCCESSFUL} - timer created successfully@* |
---|
189 | @code{@value{RPREFIX}INVALID_NAME} - invalid timer name@* |
---|
190 | @code{@value{RPREFIX}TOO_MANY} - too many timers created |
---|
191 | |
---|
192 | @subheading DESCRIPTION: |
---|
193 | |
---|
194 | This directive creates a timer. The assigned timer |
---|
195 | id is returned in id. This id is used to access the timer with |
---|
196 | other timer manager directives. For control and maintenance of |
---|
197 | the timer, RTEMS allocates a TMCB from the local TMCB free pool |
---|
198 | and initializes it. |
---|
199 | |
---|
200 | @subheading NOTES: |
---|
201 | |
---|
202 | This directive will not cause the calling task to be |
---|
203 | preempted. |
---|
204 | |
---|
205 | @c |
---|
206 | @c |
---|
207 | @c |
---|
208 | @page |
---|
209 | @subsection TIMER_IDENT - Get ID of a timer |
---|
210 | |
---|
211 | @cindex obtain the ID of a timer |
---|
212 | |
---|
213 | @subheading CALLING SEQUENCE: |
---|
214 | |
---|
215 | @ifset is-C |
---|
216 | @findex rtems_timer_ident |
---|
217 | @example |
---|
218 | rtems_status_code rtems_timer_ident( |
---|
219 | rtems_name name, |
---|
220 | rtems_id *id |
---|
221 | ); |
---|
222 | @end example |
---|
223 | @end ifset |
---|
224 | |
---|
225 | @ifset is-Ada |
---|
226 | @example |
---|
227 | procedure Timer_Ident ( |
---|
228 | Name : in RTEMS.Name; |
---|
229 | ID : out RTEMS.ID; |
---|
230 | Result : out RTEMS.Status_Codes |
---|
231 | ); |
---|
232 | @end example |
---|
233 | @end ifset |
---|
234 | |
---|
235 | @subheading DIRECTIVE STATUS CODES: |
---|
236 | @code{@value{RPREFIX}SUCCESSFUL} - timer identified successfully@* |
---|
237 | @code{@value{RPREFIX}INVALID_NAME} - timer name not found |
---|
238 | |
---|
239 | @subheading DESCRIPTION: |
---|
240 | |
---|
241 | This directive obtains the timer id associated with |
---|
242 | the timer name to be acquired. If the timer name is not unique, |
---|
243 | then the timer id will match one of the timers with that name. |
---|
244 | However, this timer id is not guaranteed to correspond to the |
---|
245 | desired timer. The timer id is used to access this timer in |
---|
246 | other timer related directives. |
---|
247 | |
---|
248 | @subheading NOTES: |
---|
249 | |
---|
250 | This directive will not cause the running task to be |
---|
251 | preempted. |
---|
252 | |
---|
253 | @c |
---|
254 | @c |
---|
255 | @c |
---|
256 | @page |
---|
257 | @subsection TIMER_CANCEL - Cancel a timer |
---|
258 | |
---|
259 | @cindex cancel a timer |
---|
260 | |
---|
261 | @subheading CALLING SEQUENCE: |
---|
262 | |
---|
263 | @ifset is-C |
---|
264 | @findex rtems_timer_cancel |
---|
265 | @example |
---|
266 | rtems_status_code rtems_timer_cancel( |
---|
267 | rtems_id id |
---|
268 | ); |
---|
269 | @end example |
---|
270 | @end ifset |
---|
271 | |
---|
272 | @ifset is-Ada |
---|
273 | @example |
---|
274 | procedure Timer_Cancel ( |
---|
275 | ID : in RTEMS.ID; |
---|
276 | Result : out RTEMS.Status_Codes |
---|
277 | ); |
---|
278 | @end example |
---|
279 | @end ifset |
---|
280 | |
---|
281 | @subheading DIRECTIVE STATUS CODES: |
---|
282 | @code{@value{RPREFIX}SUCCESSFUL} - timer canceled successfully@* |
---|
283 | @code{@value{RPREFIX}INVALID_ID} - invalid timer id |
---|
284 | |
---|
285 | @subheading DESCRIPTION: |
---|
286 | |
---|
287 | This directive cancels the timer id. This timer will |
---|
288 | be reinitiated by the next invocation of @code{@value{DIRPREFIX}timer_reset}, |
---|
289 | @code{@value{DIRPREFIX}timer_fire_after}, or |
---|
290 | @code{@value{DIRPREFIX}timer_fire_when} with id. |
---|
291 | |
---|
292 | @subheading NOTES: |
---|
293 | |
---|
294 | This directive will not cause the running task to be preempted. |
---|
295 | |
---|
296 | @c |
---|
297 | @c |
---|
298 | @c |
---|
299 | @page |
---|
300 | @subsection TIMER_DELETE - Delete a timer |
---|
301 | |
---|
302 | @cindex delete a timer |
---|
303 | |
---|
304 | @subheading CALLING SEQUENCE: |
---|
305 | |
---|
306 | @ifset is-C |
---|
307 | @findex rtems_timer_delete |
---|
308 | @example |
---|
309 | rtems_status_code rtems_timer_delete( |
---|
310 | rtems_id id |
---|
311 | ); |
---|
312 | @end example |
---|
313 | @end ifset |
---|
314 | |
---|
315 | @ifset is-Ada |
---|
316 | @example |
---|
317 | procedure Timer_Delete ( |
---|
318 | ID : in RTEMS.ID; |
---|
319 | Result : out RTEMS.Status_Codes |
---|
320 | ); |
---|
321 | @end example |
---|
322 | @end ifset |
---|
323 | |
---|
324 | @subheading DIRECTIVE STATUS CODES: |
---|
325 | @code{@value{RPREFIX}SUCCESSFUL} - timer deleted successfully@* |
---|
326 | @code{@value{RPREFIX}INVALID_ID} - invalid timer id |
---|
327 | |
---|
328 | @subheading DESCRIPTION: |
---|
329 | |
---|
330 | This directive deletes the timer specified by id. If |
---|
331 | the timer is running, it is automatically canceled. The TMCB |
---|
332 | for the deleted timer is reclaimed by RTEMS. |
---|
333 | |
---|
334 | @subheading NOTES: |
---|
335 | |
---|
336 | This directive will not cause the running task to be |
---|
337 | preempted. |
---|
338 | |
---|
339 | A timer can be deleted by a task other than the task |
---|
340 | which created the timer. |
---|
341 | |
---|
342 | @c |
---|
343 | @c |
---|
344 | @c |
---|
345 | @page |
---|
346 | @subsection TIMER_FIRE_AFTER - Fire timer after interval |
---|
347 | |
---|
348 | @cindex fire a timer after an interval |
---|
349 | |
---|
350 | @subheading CALLING SEQUENCE: |
---|
351 | |
---|
352 | @ifset is-C |
---|
353 | @findex rtems_timer_fire_after |
---|
354 | @example |
---|
355 | rtems_status_code rtems_timer_fire_after( |
---|
356 | rtems_id id, |
---|
357 | rtems_interval ticks, |
---|
358 | rtems_timer_service_routine_entry routine, |
---|
359 | void *user_data |
---|
360 | ); |
---|
361 | @end example |
---|
362 | @end ifset |
---|
363 | |
---|
364 | @ifset is-Ada |
---|
365 | @example |
---|
366 | procedure Timer_Fire_After ( |
---|
367 | ID : in RTEMS.ID; |
---|
368 | Ticks : in RTEMS.Interval; |
---|
369 | Routine : in RTEMS.Timer_Service_Routine; |
---|
370 | User_Data : in RTEMS.Address; |
---|
371 | Result : out RTEMS.Status_Codes |
---|
372 | ); |
---|
373 | @end example |
---|
374 | @end ifset |
---|
375 | |
---|
376 | @subheading DIRECTIVE STATUS CODES: |
---|
377 | @code{@value{RPREFIX}SUCCESSFUL} - timer initiated successfully@* |
---|
378 | @code{@value{RPREFIX}INVALID_ID} - invalid timer id@* |
---|
379 | @code{@value{RPREFIX}INVALID_NUMBER} - invalid interval |
---|
380 | |
---|
381 | @subheading DESCRIPTION: |
---|
382 | |
---|
383 | This directive initiates the timer specified by id. |
---|
384 | If the timer is running, it is automatically canceled before |
---|
385 | being initiated. The timer is scheduled to fire after an |
---|
386 | interval ticks clock ticks has passed. When the timer fires, |
---|
387 | the timer service routine routine will be invoked with the |
---|
388 | argument user_data. |
---|
389 | |
---|
390 | @subheading NOTES: |
---|
391 | |
---|
392 | This directive will not cause the running task to be |
---|
393 | preempted. |
---|
394 | |
---|
395 | @c |
---|
396 | @c |
---|
397 | @c |
---|
398 | @page |
---|
399 | @subsection TIMER_FIRE_WHEN - Fire timer when specified |
---|
400 | |
---|
401 | @cindex fire a timer at wall time |
---|
402 | |
---|
403 | @subheading CALLING SEQUENCE: |
---|
404 | |
---|
405 | @ifset is-C |
---|
406 | @findex rtems_timer_fire_when |
---|
407 | @example |
---|
408 | rtems_status_code rtems_timer_fire_when( |
---|
409 | rtems_id id, |
---|
410 | rtems_time_of_day *wall_time, |
---|
411 | rtems_timer_service_routine_entry routine, |
---|
412 | void *user_data |
---|
413 | ); |
---|
414 | @end example |
---|
415 | @end ifset |
---|
416 | |
---|
417 | @ifset is-Ada |
---|
418 | @example |
---|
419 | procedure Timer_Fire_When ( |
---|
420 | ID : in RTEMS.ID; |
---|
421 | Wall_Time : in RTEMS.Time_Of_Day; |
---|
422 | Routine : in RTEMS.Timer_Service_Routine; |
---|
423 | User_Data : in RTEMS.Address; |
---|
424 | Result : out RTEMS.Status_Codes |
---|
425 | ); |
---|
426 | @end example |
---|
427 | @end ifset |
---|
428 | |
---|
429 | @subheading DIRECTIVE STATUS CODES: |
---|
430 | @code{@value{RPREFIX}SUCCESSFUL} - timer initiated successfully@* |
---|
431 | @code{@value{RPREFIX}INVALID_ID} - invalid timer id@* |
---|
432 | @code{@value{RPREFIX}NOT_DEFINED} - system date and time is not set@* |
---|
433 | @code{@value{RPREFIX}INVALID_CLOCK} - invalid time of day |
---|
434 | |
---|
435 | @subheading DESCRIPTION: |
---|
436 | |
---|
437 | This directive initiates the timer specified by id. |
---|
438 | If the timer is running, it is automatically canceled before |
---|
439 | being initiated. The timer is scheduled to fire at the time of |
---|
440 | day specified by wall_time. When the timer fires, the timer |
---|
441 | service routine routine will be invoked with the argument |
---|
442 | user_data. |
---|
443 | |
---|
444 | @subheading NOTES: |
---|
445 | |
---|
446 | This directive will not cause the running task to be |
---|
447 | preempted. |
---|
448 | |
---|
449 | @c |
---|
450 | @c |
---|
451 | @c |
---|
452 | @page |
---|
453 | @subsection TIMER_RESET - Reset an interval timer |
---|
454 | |
---|
455 | @cindex reset a timer |
---|
456 | |
---|
457 | @subheading CALLING SEQUENCE: |
---|
458 | |
---|
459 | @ifset is-C |
---|
460 | @findex rtems_timer_reset |
---|
461 | @example |
---|
462 | rtems_status_code rtems_timer_reset( |
---|
463 | rtems_id id |
---|
464 | ); |
---|
465 | @end example |
---|
466 | @end ifset |
---|
467 | |
---|
468 | @ifset is-Ada |
---|
469 | @example |
---|
470 | procedure Timer_Reset ( |
---|
471 | ID : in RTEMS.ID; |
---|
472 | Result : out RTEMS.Status_Codes |
---|
473 | ); |
---|
474 | @end example |
---|
475 | @end ifset |
---|
476 | |
---|
477 | @subheading DIRECTIVE STATUS CODES: |
---|
478 | @code{@value{RPREFIX}SUCCESSFUL} - timer reset successfully@* |
---|
479 | @code{@value{RPREFIX}INVALID_ID} - invalid timer id@* |
---|
480 | @code{@value{RPREFIX}NOT_DEFINED} - attempted to reset a when or newly created timer |
---|
481 | |
---|
482 | @subheading DESCRIPTION: |
---|
483 | |
---|
484 | This directive resets the timer associated with id. |
---|
485 | This timer must have been previously initiated with a |
---|
486 | @code{@value{DIRPREFIX}timer_fire_after} |
---|
487 | directive. If active the timer is canceled, |
---|
488 | after which the timer is reinitiated using the same interval and |
---|
489 | timer service routine which the original |
---|
490 | @code{@value{DIRPREFIX}timer_fire_after} |
---|
491 | directive used. |
---|
492 | |
---|
493 | @subheading NOTES: |
---|
494 | |
---|
495 | If the timer has not been used or the last usage of this timer |
---|
496 | was by a @code{@value{DIRPREFIX}timer_fire_when} |
---|
497 | directive, then the @code{@value{RPREFIX}NOT_DEFINED} error is |
---|
498 | returned. |
---|
499 | |
---|
500 | Restarting a cancelled after timer results in the timer being |
---|
501 | reinitiated with its previous timer service routine and interval. |
---|
502 | |
---|
503 | This directive will not cause the running task to be preempted. |
---|
504 | |
---|