source: rtems/doc/user/timer.t @ adee5979

4.104.114.84.95
Last change on this file since adee5979 was adee5979, checked in by Joel Sherrill <joel.sherrill@…>, on 05/04/00 at 19:45:17

Numerous changes based on comments from Stephan Wilms <Stephan.Wilms@…>
including a new section in the Getting Started called "Where to
Go From Here", lots of index entries added, and more configuration
table information.

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