source: rtems/doc/user/timer.t @ 5cd3258

4.104.114.84.95
Last change on this file since 5cd3258 was 5cd3258, checked in by Joel Sherrill <joel.sherrill@…>, on 01/17/02 at 23:14:16

2001-01-17 Joel Sherrill <joel@…>

  • timer.t: Added task-based timer information including the new directives rtems_timer_initiate(), rtems_timer_server_fire_after(), and rtems_timer_server_fire_when().
  • Property mode set to 100644
File size: 20.1 KB
Line 
1@c
2@c  COPYRIGHT (c) 1988-2002.
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_initiate_server} - Initiate server for task-based timers
26@item @code{@value{DIRPREFIX}timer_server_fire_after} - Fire task-based timer after interval
27@item @code{@value{DIRPREFIX}timer_server_fire_when} - Fire task-based timer when specified
28@item @code{@value{DIRPREFIX}timer_reset} - Reset an interval timer
29@end itemize
30
31
32@section Background
33
34@subsection Required Support
35
36A clock tick is required to support the functionality provided by this manager.
37
38@subsection Timers
39
40A timer is an RTEMS object which allows the
41application to schedule operations to occur at specific times in
42the future.  User supplied timer service routines are invoked by
43either the @code{@value{DIRPREFIX}clock_tick} directive or
44a special Timer Server task when the timer fires.  Timer service
45routines may perform any operations or directives which normally
46would be performed by the application code which invoked the
47@code{@value{DIRPREFIX}clock_tick} directive.
48
49The timer can be used to implement watchdog routines
50which only fire to denote that an application error has
51occurred.  The timer is reset at specific points in the
52application to insure that the watchdog does not fire.  Thus, if
53the application does not reset the watchdog timer, then the
54timer service routine will fire to indicate that the application
55has failed to reach a reset point.  This use of a timer is
56sometimes referred to as a "keep alive" or a "deadman" timer.
57
58@subsection Timer Server
59
60The Timer Server task is responsible for executing the timer
61service routines associated with all task-based timers.
62This task executes at a priority higher than any RTEMS application
63task and thus can be viewed logically as the lowest priority interrupt.
64
65By providing a mechanism where timer service routines execute
66in task rather than interrupt space, the application is
67allowed a bit more flexibility in what operations a timer
68service routine can perform.  For example, the Timer Server
69can be configured to have a floating point context in which case
70it would be save to perform floating point operations
71from a task-based timer.  Most of the time, executing floating
72point instructions from an interrupt service routine
73is not considered safe.
74
75The Timer Server is designed to remain blocked until a
76task-based timer fires.  This reduces the execution overhead
77of the Timer Server.
78
79@subsection Timer Service Routines
80
81The timer service routine should adhere to @value{LANGUAGE} calling
82conventions and have a prototype similar to the following:
83
84@ifset is-C
85@findex rtems_timer_service_routine
86@example
87rtems_timer_service_routine user_routine(
88  rtems_id   timer_id,
89  void      *user_data
90);
91@end example
92@end ifset
93
94@ifset is-Ada
95@example
96procedure User_Routine(
97  Timer_ID  : in     RTEMS.ID;
98  User_Data : in     System.Address
99);
100@end example
101@end ifset
102
103Where the timer_id parameter is the RTEMS object ID
104of the timer which is being fired and user_data is a pointer to
105user-defined information which may be utilized by the timer
106service routine.  The argument user_data may be NULL.
107
108@section Operations
109
110@subsection Creating a Timer
111
112The @code{@value{DIRPREFIX}timer_create} directive creates a timer by
113allocating a Timer Control Block (TMCB), assigning the timer a
114user-specified name, and assigning it a timer ID.  Newly created
115timers do not have a timer service routine associated with them
116and are not active.
117
118@subsection Obtaining Timer IDs
119
120When a timer is created, RTEMS generates a unique
121timer ID and assigns it to the created timer until it is
122deleted.  The timer ID may be obtained by either of two methods.
123First, as the result of an invocation of the
124@code{@value{DIRPREFIX}timer_create}
125directive, the timer ID is stored in a user provided location.
126Second, the timer ID may be obtained later using the
127@code{@value{DIRPREFIX}timer_ident} directive.  The timer ID
128is used by other directives to manipulate this timer.
129
130@subsection Initiating an Interval Timer
131
132The @code{@value{DIRPREFIX}timer_fire_after}
133and @code{@value{DIRPREFIX}timer_server_fire_after}
134directives initiate a timer to fire a user provided
135timer service routine after the specified
136number of clock ticks have elapsed.  When the interval has
137elapsed, the timer service routine will be invoked from the
138@code{@value{DIRPREFIX}clock_tick} directive if it was initiated
139by the @code{@value{DIRPREFIX}timer_fire_after} directive
140and from the Timer Server task if initiated by the
141@code{@value{DIRPREFIX}timer_server_fire_after} directive.
142
143@subsection Initiating a Time of Day Timer
144
145The @code{@value{DIRPREFIX}timer_fire_when}
146and @code{@value{DIRPREFIX}timer_server_fire_when}
147directive initiate a timer to
148fire a user provided timer service routine when the specified
149time of day has been reached.  When the interval has elapsed,
150the timer service routine will be invoked from the
151@code{@value{DIRPREFIX}clock_tick} directive
152by the @code{@value{DIRPREFIX}timer_fire_when} directive
153and from the Timer Server task if initiated by the
154@code{@value{DIRPREFIX}timer_server_fire_when} directive.
155
156@subsection Canceling a Timer
157
158The @code{@value{DIRPREFIX}timer_cancel} directive is used to halt the
159specified timer.  Once canceled, the timer service routine will
160not fire unless the timer is reinitiated.  The timer can be
161reinitiated using the @code{@value{DIRPREFIX}timer_reset},
162@code{@value{DIRPREFIX}timer_fire_after}, and
163@code{@value{DIRPREFIX}timer_fire_when} directives.
164
165@subsection Resetting a Timer
166
167The @code{@value{DIRPREFIX}timer_reset} directive is used to restore an
168interval timer initiated by a previous invocation of
169@code{@value{DIRPREFIX}timer_fire_after} or
170@code{@value{DIRPREFIX}timer_server_fire_after} to
171its original interval length.  If the
172timer has not been used or the last usage of this timer
173was by the @code{@value{DIRPREFIX}timer_fire_when}
174or @code{@value{DIRPREFIX}timer_server_fire_when}
175directive, then an error is returned.  The timer service routine
176is not changed or fired by this directive.
177
178@subsection Initiating the Timer Server
179
180The @code{@value{DIRPREFIX}timer_initiate_server} directive is used to
181allocate and start the execution of the Timer Server task.  The
182application can specify both the stack size and attributes of the
183Timer Server.  The Timer Server executes at a priority higher than
184any application task and thus the user can expect to be preempted
185as the result of executing the @code{@value{DIRPREFIX}timer_initiate_server}
186directive.
187
188@subsection Deleting a Timer
189
190The @code{@value{DIRPREFIX}timer_delete} directive is used to delete a timer.
191If the timer is running and has not expired, the timer is
192automatically canceled.  The timer's control block is returned
193to the TMCB free list when it is deleted.  A timer can be
194deleted by a task other than the task which created the timer.
195Any subsequent references to the timer's name and ID are invalid.
196
197@section Directives
198
199This section details the timer manager's directives.
200A subsection is dedicated to each of this manager's directives
201and describes the calling sequence, related constants, usage,
202and status codes.
203
204@c
205@c
206@c
207@page
208@subsection TIMER_CREATE - Create a timer
209
210@cindex create a timer
211
212@subheading CALLING SEQUENCE:
213
214@ifset is-C
215@findex rtems_timer_create
216@example
217rtems_status_code rtems_timer_create(
218  rtems_name  name,
219  rtems_id   *id
220);
221@end example
222@end ifset
223
224@ifset is-Ada
225@example
226procedure Timer_Create (
227   Name   : in     RTEMS.Name;
228   ID     :    out RTEMS.ID;
229   Result :    out RTEMS.Status_Codes
230);
231@end example
232@end ifset
233
234@subheading DIRECTIVE STATUS CODES:
235@code{@value{RPREFIX}SUCCESSFUL} - timer created successfully@*
236@code{@value{RPREFIX}INVALID_NAME} - invalid timer name@*
237@code{@value{RPREFIX}TOO_MANY} - too many timers created
238
239@subheading DESCRIPTION:
240
241This directive creates a timer.  The assigned timer
242id is returned in id.  This id is used to access the timer with
243other timer manager directives.  For control and maintenance of
244the timer, RTEMS allocates a TMCB from the local TMCB free pool
245and initializes it.
246
247@subheading NOTES:
248
249This directive will not cause the calling task to be
250preempted.
251
252@c
253@c
254@c
255@page
256@subsection TIMER_IDENT - Get ID of a timer
257
258@cindex obtain the ID of a timer
259
260@subheading CALLING SEQUENCE:
261
262@ifset is-C
263@findex rtems_timer_ident
264@example
265rtems_status_code rtems_timer_ident(
266  rtems_name  name,
267  rtems_id   *id
268);
269@end example
270@end ifset
271
272@ifset is-Ada
273@example
274procedure Timer_Ident (
275   Name   : in     RTEMS.Name;
276   ID     :    out 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 identified successfully@*
284@code{@value{RPREFIX}INVALID_NAME} - timer name not found
285
286@subheading DESCRIPTION:
287
288This directive obtains the timer id associated with
289the timer name to be acquired.  If the timer name is not unique,
290then the timer id will match one of the timers with that name.
291However, this timer id is not guaranteed to correspond to the
292desired timer.  The timer id is used to access this timer in
293other timer related directives.
294
295@subheading NOTES:
296
297This directive will not cause the running task to be
298preempted.
299
300@c
301@c
302@c
303@page
304@subsection TIMER_CANCEL - Cancel a timer
305
306@cindex cancel a timer
307
308@subheading CALLING SEQUENCE:
309
310@ifset is-C
311@findex rtems_timer_cancel
312@example
313rtems_status_code rtems_timer_cancel(
314  rtems_id id
315);
316@end example
317@end ifset
318
319@ifset is-Ada
320@example
321procedure Timer_Cancel (
322   ID     : in     RTEMS.ID;
323   Result :    out RTEMS.Status_Codes
324);
325@end example
326@end ifset
327
328@subheading DIRECTIVE STATUS CODES:
329@code{@value{RPREFIX}SUCCESSFUL} - timer canceled successfully@*
330@code{@value{RPREFIX}INVALID_ID} - invalid timer id
331
332@subheading DESCRIPTION:
333
334This directive cancels the timer id.  This timer will
335be reinitiated by the next invocation of @code{@value{DIRPREFIX}timer_reset},
336@code{@value{DIRPREFIX}timer_fire_after}, or
337@code{@value{DIRPREFIX}timer_fire_when} with this id.
338
339@subheading NOTES:
340
341This directive will not cause the running task to be preempted.
342
343@c
344@c
345@c
346@page
347@subsection TIMER_DELETE - Delete a timer
348
349@cindex delete a timer
350
351@subheading CALLING SEQUENCE:
352
353@ifset is-C
354@findex rtems_timer_delete
355@example
356rtems_status_code rtems_timer_delete(
357  rtems_id id
358);
359@end example
360@end ifset
361
362@ifset is-Ada
363@example
364procedure Timer_Delete (
365   ID     : in     RTEMS.ID;
366   Result :    out RTEMS.Status_Codes
367);
368@end example
369@end ifset
370
371@subheading DIRECTIVE STATUS CODES:
372@code{@value{RPREFIX}SUCCESSFUL} - timer deleted successfully@*
373@code{@value{RPREFIX}INVALID_ID} - invalid timer id
374
375@subheading DESCRIPTION:
376
377This directive deletes the timer specified by id.  If
378the timer is running, it is automatically canceled.  The TMCB
379for the deleted timer is reclaimed by RTEMS.
380
381@subheading NOTES:
382
383This directive will not cause the running task to be
384preempted.
385
386A timer can be deleted by a task other than the task
387which created the timer.
388
389@c
390@c
391@c
392@page
393@subsection TIMER_FIRE_AFTER - Fire timer after interval
394
395@cindex fire a timer after an interval
396
397@subheading CALLING SEQUENCE:
398
399@ifset is-C
400@findex rtems_timer_fire_after
401@example
402rtems_status_code rtems_timer_fire_after(
403  rtems_id                           id,
404  rtems_interval                     ticks,
405  rtems_timer_service_routine_entry  routine,
406  void                              *user_data
407);
408@end example
409@end ifset
410
411@ifset is-Ada
412@example
413procedure Timer_Fire_After (
414   ID        : in     RTEMS.ID;
415   Ticks     : in     RTEMS.Interval;
416   Routine   : in     RTEMS.Timer_Service_Routine;
417   User_Data : in     RTEMS.Address;
418   Result    :    out RTEMS.Status_Codes
419);
420@end example
421@end ifset
422
423@subheading DIRECTIVE STATUS CODES:
424@code{@value{RPREFIX}SUCCESSFUL} - timer initiated successfully@*
425@code{@value{RPREFIX}INVALID_ID} - invalid timer id@*
426@code{@value{RPREFIX}INVALID_NUMBER} - invalid interval
427
428@subheading DESCRIPTION:
429
430This directive initiates the timer specified by id.
431If the timer is running, it is automatically canceled before
432being initiated.  The timer is scheduled to fire after an
433interval ticks clock ticks has passed.  When the timer fires,
434the timer service routine routine will be invoked with the
435argument user_data.
436
437@subheading NOTES:
438
439This directive will not cause the running task to be
440preempted.
441
442@c
443@c
444@c
445@page
446@subsection TIMER_FIRE_WHEN - Fire timer when specified
447
448@cindex fire a timer at wall time
449
450@subheading CALLING SEQUENCE:
451
452@ifset is-C
453@findex rtems_timer_fire_when
454@example
455rtems_status_code rtems_timer_fire_when(
456  rtems_id                           id,
457  rtems_time_of_day                 *wall_time,
458  rtems_timer_service_routine_entry  routine,
459  void                              *user_data
460);
461@end example
462@end ifset
463
464@ifset is-Ada
465@example
466procedure Timer_Fire_When (
467   ID        : in     RTEMS.ID;
468   Wall_Time : in     RTEMS.Time_Of_Day;
469   Routine   : in     RTEMS.Timer_Service_Routine;
470   User_Data : in     RTEMS.Address;
471   Result    :    out RTEMS.Status_Codes
472);
473@end example
474@end ifset
475
476@subheading DIRECTIVE STATUS CODES:
477@code{@value{RPREFIX}SUCCESSFUL} - timer initiated successfully@*
478@code{@value{RPREFIX}INVALID_ID} - invalid timer id@*
479@code{@value{RPREFIX}NOT_DEFINED} - system date and time is not set@*
480@code{@value{RPREFIX}INVALID_CLOCK} - invalid time of day
481
482@subheading DESCRIPTION:
483
484This directive initiates the timer specified by id.
485If the timer is running, it is automatically canceled before
486being initiated.  The timer is scheduled to fire at the time of
487day specified by wall_time.  When the timer fires, the timer
488service routine routine will be invoked with the argument
489user_data.
490
491@subheading NOTES:
492
493This directive will not cause the running task to be
494preempted.
495
496@c
497@c
498@c
499@page
500@subsection TIMER_INITIATE_SERVER - Initiate server for task-based timers
501
502@cindex initiate the Timer Server
503
504@subheading CALLING SEQUENCE:
505
506@ifset is-C
507@findex rtems_timer_initiate_server
508@example
509rtems_status_code rtems_timer_initiate_server(
510  unsigned32           stack_size,
511  rtems_attribute      attribute_set
512)
513);
514@end example
515@end ifset
516
517@ifset is-Ada
518@example
519procedure Timer_Initiate_Server (
520   Stack_Size    : in     RTEMS.Unsigned32;
521   Attribute_Set : in     RTEMS.Attribute;
522   Result        :    out RTEMS.Status_Codes
523);
524@end example
525@end ifset
526
527@subheading DIRECTIVE STATUS CODES:
528@code{@value{RPREFIX}SUCCESSFUL} - Timer Server initiated successfully@*
529@code{@value{RPREFIX}TOO_MANY} - too many tasks created
530
531@subheading DESCRIPTION:
532
533This directive initiates the Timer Server task.  This task
534is responsible for executing all timers initiated via the
535@code{@value{DIRPREFIX}timer_server_fire_after} or
536@code{@value{DIRPREFIX}timer_server_fire_when} directives.
537
538@subheading NOTES:
539
540This directive could cause the calling task to be preempted.
541
542The Timer Server task is created using the
543@code{@value{DIRPREFIX}task_create} service and must be accounted
544for when configuring the system.
545
546Even through this directive invokes the @code{@value{DIRPREFIX}task_create}
547and @code{@value{DIRPREFIX}task_start} directives, it should only fail
548due to resource allocation problems.
549
550@c
551@c
552@c
553@page
554@subsection TIMER_SERVER_FIRE_AFTER - Fire task-based timer after interval
555
556@cindex fire task-based a timer after an interval
557
558@subheading CALLING SEQUENCE:
559
560@ifset is-C
561@findex rtems_timer_server_fire_after
562@example
563rtems_status_code rtems_timer_server_fire_after(
564  rtems_id                           id,
565  rtems_interval                     ticks,
566  rtems_timer_service_routine_entry  routine,
567  void                              *user_data
568);
569@end example
570@end ifset
571
572@ifset is-Ada
573@example
574procedure Timer_Fire_Server_After (
575   ID        : in     RTEMS.ID;
576   Ticks     : in     RTEMS.Interval;
577   Routine   : in     RTEMS.Timer_Service_Routine;
578   User_Data : in     RTEMS.Address;
579   Result    :    out RTEMS.Status_Codes
580);
581@end example
582@end ifset
583
584@subheading DIRECTIVE STATUS CODES:
585@code{@value{RPREFIX}SUCCESSFUL} - timer initiated successfully@*
586@code{@value{RPREFIX}INVALID_ID} - invalid timer id@*
587@code{@value{RPREFIX}INVALID_NUMBER} - invalid interval@*
588@code{@value{RPREFIX}INCORRECT_STATE} - Timer Server not initiated
589
590@subheading DESCRIPTION:
591
592This directive initiates the timer specified by id and specifies
593that when it fires it will be executed by the Timer Server.
594
595If the timer is running, it is automatically canceled before
596being initiated.  The timer is scheduled to fire after an
597interval ticks clock ticks has passed.  When the timer fires,
598the timer service routine routine will be invoked with the
599argument user_data.
600
601@subheading NOTES:
602
603This directive will not cause the running task to be
604preempted.
605
606@c
607@c
608@c
609@page
610@subsection TIMER_SERVER_FIRE_WHEN - Fire task-based timer when specified
611
612@cindex fire a task-based timer at wall time
613
614@subheading CALLING SEQUENCE:
615
616@ifset is-C
617@findex rtems_timer_server_fire_when
618@example
619rtems_status_code rtems_timer_server_fire_when(
620  rtems_id                           id,
621  rtems_time_of_day                 *wall_time,
622  rtems_timer_service_routine_entry  routine,
623  void                              *user_data
624);
625@end example
626@end ifset
627
628@ifset is-Ada
629@example
630procedure Timer_Fire_Server_When (
631   ID        : in     RTEMS.ID;
632   Wall_Time : in     RTEMS.Time_Of_Day;
633   Routine   : in     RTEMS.Timer_Service_Routine;
634   User_Data : in     RTEMS.Address;
635   Result    :    out RTEMS.Status_Codes
636);
637@end example
638@end ifset
639
640@subheading DIRECTIVE STATUS CODES:
641@code{@value{RPREFIX}SUCCESSFUL} - timer initiated successfully@*
642@code{@value{RPREFIX}INVALID_ID} - invalid timer id@*
643@code{@value{RPREFIX}NOT_DEFINED} - system date and time is not set@*
644@code{@value{RPREFIX}INVALID_CLOCK} - invalid time of day@*
645@code{@value{RPREFIX}INCORRECT_STATE} - Timer Server not initiated
646
647@subheading DESCRIPTION:
648
649This directive initiates the timer specified by id and specifies
650that when it fires it will be executed by the Timer Server.
651
652If the timer is running, it is automatically canceled before
653being initiated.  The timer is scheduled to fire at the time of
654day specified by wall_time.  When the timer fires, the timer
655service routine routine will be invoked with the argument
656user_data.
657
658@subheading NOTES:
659
660This directive will not cause the running task to be
661preempted.
662
663@c
664@c
665@c
666@page
667@subsection TIMER_RESET - Reset an interval timer
668
669@cindex reset a timer
670
671@subheading CALLING SEQUENCE:
672
673@ifset is-C
674@findex rtems_timer_reset
675@example
676rtems_status_code rtems_timer_reset(
677  rtems_id   id
678);
679@end example
680@end ifset
681
682@ifset is-Ada
683@example
684procedure Timer_Reset (
685   ID     : in     RTEMS.ID;
686   Result :    out RTEMS.Status_Codes
687);
688@end example
689@end ifset
690
691@subheading DIRECTIVE STATUS CODES:
692@code{@value{RPREFIX}SUCCESSFUL} - timer reset successfully@*
693@code{@value{RPREFIX}INVALID_ID} - invalid timer id@*
694@code{@value{RPREFIX}NOT_DEFINED} - attempted to reset a when or newly created timer
695
696@subheading DESCRIPTION:
697
698This directive resets the timer associated with id.
699This timer must have been previously initiated with either the
700@code{@value{DIRPREFIX}timer_fire_after} or
701@code{@value{DIRPREFIX}timer_server_fire_after}
702directive.  If active the timer is canceled,
703after which the timer is reinitiated using the same interval and
704timer service routine which the original
705@code{@value{DIRPREFIX}timer_fire_after}
706@code{@value{DIRPREFIX}timer_server_fire_after}
707directive used.
708
709@subheading NOTES:
710
711If the timer has not been used or the last usage of this timer
712was by a @code{@value{DIRPREFIX}timer_fire_when} or
713@code{@value{DIRPREFIX}timer_server_fire_when}
714directive, then the @code{@value{RPREFIX}NOT_DEFINED} error is
715returned.
716
717Restarting a cancelled after timer results in the timer being
718reinitiated with its previous timer service routine and interval.
719
720This directive will not cause the running task to be preempted.
721
Note: See TracBrowser for help on using the repository browser.