source: rtems/doc/user/timer.t @ 169502e

4.104.114.84.95
Last change on this file since 169502e was 169502e, checked in by Joel Sherrill <joel.sherrill@…>, on 10/11/99 at 19:03:05

Turned on concept and function name indexing.

  • Property mode set to 100644
File size: 13.3 KB
Line 
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
15The timer manager provides support for timer
16facilities.  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
33A clock tick is required to support the functionality provided by this manager.
34
35@subsection Timers
36
37A timer is an RTEMS object which allows the
38application to schedule operations to occur at specific times in
39the future.  User supplied timer service routines are invoked by
40the @code{@value{DIRPREFIX}clock_tick} directive
41when the timer fires.  Timer service routines may perform
42any operations or directives which normally
43would be performed by the application code which invoked the
44@code{@value{DIRPREFIX}clock_tick} directive.
45
46The timer can be used to implement watchdog routines
47which only fire to denote that an application error has
48occurred.  The timer is reset at specific points in the
49application to insure that the watchdog does not fire.  Thus, if
50the application does not reset the watchdog timer, then the
51timer service routine will fire to indicate that the application
52has failed to reach a reset point.  This use of a timer is
53sometimes referred to as a "keep alive" or a "deadman" timer.
54
55@subsection Timer Service Routines
56
57The timer service routine should adhere to @value{LANGUAGE} calling
58conventions and have a prototype similar to the following:
59
60@ifset is-C
61@example
62rtems_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
71procedure User_Routine(
72  Timer_ID  : in     RTEMS.ID;
73  User_Data : in     System.Address
74);
75@end example
76@end ifset
77
78Where the timer_id parameter is the RTEMS object ID
79of the timer which is being fired and user_data is a pointer to
80user-defined information which may be utilized by the timer
81service routine.  The argument user_data may be NULL.
82
83@section Operations
84
85@subsection Creating a Timer
86
87The @code{@value{DIRPREFIX}timer_create} directive creates a timer by
88allocating a Timer Control Block (TMCB), assigning the timer a
89user-specified name, and assigning it a timer ID.  Newly created
90timers do not have a timer service routine associated with them
91and are not active.
92
93@subsection Obtaining Timer IDs
94
95When a timer is created, RTEMS generates a unique
96timer ID and assigns it to the created timer until it is
97deleted.  The timer ID may be obtained by either of two methods.
98First, as the result of an invocation of the
99@code{@value{DIRPREFIX}timer_create}
100directive, the timer ID is stored in a user provided location.
101Second, the timer ID may be obtained later using the
102@code{@value{DIRPREFIX}timer_ident} directive.  The timer ID
103is used by other directives to manipulate this timer.
104
105@subsection Initiating an Interval Timer
106
107The @code{@value{DIRPREFIX}timer_fire_after} directive initiates a timer to
108fire a user provided timer service routine after the specified
109number of clock ticks have elapsed.  When the interval has
110elapsed, 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
115The @code{@value{DIRPREFIX}timer_fire_when} directive initiates a timer to
116fire a user provided timer service routine when the specified
117time of day has been reached.  When the interval has elapsed,
118the timer service routine will be invoked from the
119@code{@value{DIRPREFIX}clock_tick} directive.
120
121@subsection Canceling a Timer
122
123The @code{@value{DIRPREFIX}timer_cancel} directive is used to halt the
124specified timer.  Once canceled, the timer service routine will
125not fire unless the timer is reinitiated.  The timer can be
126reinitiated 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
132The @code{@value{DIRPREFIX}timer_reset} directive is used to restore an
133interval timer initiated by a previous invocation of
134@code{@value{DIRPREFIX}timer_fire_after} to
135its original interval length.  If the
136timer has not been used or the last usage of this timer
137was by a @code{@value{DIRPREFIX}timer_fire_when} directive, then an error is
138returned.  The timer service routine is not changed or
139fired by this directive.
140
141@subsection Deleting a Timer
142
143The @code{@value{DIRPREFIX}timer_delete} directive is used to delete a timer.
144If the timer is running and has not expired, the timer is
145automatically canceled.  The timer's control block is returned
146to the TMCB free list when it is deleted.  A timer can be
147deleted by a task other than the task which created the timer.
148Any subsequent references to the timer's name and ID are invalid.
149
150@section Directives
151
152This section details the timer manager's directives.
153A subsection is dedicated to each of this manager's directives
154and describes the calling sequence, related constants, usage,
155and 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
170rtems_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
179procedure 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
194This directive creates a timer.  The assigned timer
195id is returned in id.  This id is used to access the timer with
196other timer manager directives.  For control and maintenance of
197the timer, RTEMS allocates a TMCB from the local TMCB free pool
198and initializes it.
199
200@subheading NOTES:
201
202This directive will not cause the calling task to be
203preempted.
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
218rtems_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
227procedure 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
241This directive obtains the timer id associated with
242the timer name to be acquired.  If the timer name is not unique,
243then the timer id will match one of the timers with that name.
244However, this timer id is not guaranteed to correspond to the
245desired timer.  The timer id is used to access this timer in
246other timer related directives.
247
248@subheading NOTES:
249
250This directive will not cause the running task to be
251preempted.
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
266rtems_status_code rtems_timer_cancel(
267  rtems_id id
268);
269@end example
270@end ifset
271
272@ifset is-Ada
273@example
274procedure 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
287This directive cancels the timer id.  This timer will
288be 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
294This 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
309rtems_status_code rtems_timer_delete(
310  rtems_id id
311);
312@end example
313@end ifset
314
315@ifset is-Ada
316@example
317procedure 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
330This directive deletes the timer specified by id.  If
331the timer is running, it is automatically canceled.  The TMCB
332for the deleted timer is reclaimed by RTEMS.
333
334@subheading NOTES:
335
336This directive will not cause the running task to be
337preempted.
338
339A timer can be deleted by a task other than the task
340which 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
355rtems_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
366procedure 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
383This directive initiates the timer specified by id.
384If the timer is running, it is automatically canceled before
385being initiated.  The timer is scheduled to fire after an
386interval ticks clock ticks has passed.  When the timer fires,
387the timer service routine routine will be invoked with the
388argument user_data.
389
390@subheading NOTES:
391
392This directive will not cause the running task to be
393preempted.
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
408rtems_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
419procedure 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
437This directive initiates the timer specified by id.
438If the timer is running, it is automatically canceled before
439being initiated.  The timer is scheduled to fire at the time of
440day specified by wall_time.  When the timer fires, the timer
441service routine routine will be invoked with the argument
442user_data.
443
444@subheading NOTES:
445
446This directive will not cause the running task to be
447preempted.
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
462rtems_status_code rtems_timer_reset(
463  rtems_id   id
464);
465@end example
466@end ifset
467
468@ifset is-Ada
469@example
470procedure 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
484This directive resets the timer associated with id.
485This timer must have been previously initiated with a
486@code{@value{DIRPREFIX}timer_fire_after}
487directive.  If active the timer is canceled,
488after which the timer is reinitiated using the same interval and
489timer service routine which the original
490@code{@value{DIRPREFIX}timer_fire_after}
491directive used.
492
493@subheading NOTES:
494
495If the timer has not been used or the last usage of this timer
496was by a @code{@value{DIRPREFIX}timer_fire_when}
497directive, then the @code{@value{RPREFIX}NOT_DEFINED} error is
498returned.
499
500Restarting a cancelled after timer results in the timer being
501reinitiated with its previous timer service routine and interval.
502
503This directive will not cause the running task to be preempted.
504
Note: See TracBrowser for help on using the repository browser.