source: rtems/c/src/exec/rtems/include/rtems/rtems/timer.h @ 894d01c

4.104.114.84.95
Last change on this file since 894d01c was 894d01c, checked in by Joel Sherrill <joel.sherrill@…>, on 03/29/02 at 15:32:18

2001-03-29 Joel Sherrill <joel@…>

  • Per PR147 addressed problems when reseting and inserting a timer into a timer chain that did not honor time passage since the last time the timer server was scheduled and the new insertion.
  • include/rtems/rtems/timer.h, src/timerreset.c, src/timerserver.c, src/timerserverfireafter.c, src/timerserverfirewhen.c: Broke up the "reset server" routine into a set of very specific routines that allowed the server to be unscheduled, timer chains to be "synchronized" with the current time before inserting a new timer.
  • Property mode set to 100644
File size: 9.4 KB
Line 
1/*  timer.h
2 *
3 *  This include file contains all the constants, structures, and
4 *  prototypes associated with the Timer Manager.  This manager provides
5 *  facilities to configure, initiate, cancel, and delete timers which will
6 *  fire at specified intervals of time.
7 *
8 *  Directives provided are:
9 *
10 *     + create a timer
11 *     + get an ID of a timer
12 *     + delete a timer
13 *     + set timer to fire in context of clock tick
14 *        - after a number of ticks have passed
15 *        - when a specified date and time has been reached
16 *     + initiate the timer server task
17 *     + set timer to fire in context of the timer server task
18 *        - after a number of ticks have passed
19 *        - when a specified date and time has been reached
20 *     + reset a timer
21 *     + cancel a time
22 *
23 *  COPYRIGHT (c) 1989-2002.
24 *  On-Line Applications Research Corporation (OAR).
25 *
26 *  The license and distribution terms for this file may be
27 *  found in the file LICENSE in this distribution or at
28 *  http://www.OARcorp.com/rtems/license.html.
29 *
30 *  $Id$
31 */
32
33#ifndef __RTEMS_TIMER_h
34#define __RTEMS_TIMER_h
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40#include <rtems/score/object.h>
41#include <rtems/score/tod.h>
42#include <rtems/score/watchdog.h>
43#include <rtems/rtems/attr.h>
44
45/*
46 *  The following enumerated type details the classes to which a timer
47 *  may belong.
48 */
49
50typedef enum {
51  TIMER_INTERVAL,
52  TIMER_INTERVAL_ON_TASK,
53  TIMER_TIME_OF_DAY,
54  TIMER_TIME_OF_DAY_ON_TASK,
55  TIMER_DORMANT
56} Timer_Classes;
57
58/*
59 *  The following types define a pointer to a timer service routine.
60 */
61 
62typedef void rtems_timer_service_routine;
63 
64typedef rtems_timer_service_routine ( *rtems_timer_service_routine_entry )(
65                 rtems_id,
66                 void *
67             );
68
69/*
70 *  The following defines the information control block used to manage
71 *  this class of objects.
72 */
73
74RTEMS_EXTERN Objects_Information  _Timer_Information;
75
76/*
77 *  Pointer to TCB of the Timer Server.  This is NULL before the
78 *  server is executing and task-based timers are not allowed to be
79 *  initiated until the server is started.
80 */
81
82RTEMS_EXTERN Thread_Control *_Timer_Server;
83
84/* 
85 *  The following chains contain the list of interval timers that are
86 *  executed in the context of the Timer Server.
87 *
88 *  NOTE: These are extern'ed because they do not have to be in the
89 *        minimum footprint.  They are only really required when
90 *        task-based timers are used.  Since task-based timers can
91 *        not be started until the server is initiated, these structures
92 *        do not have to be initialized until then.  They are declared
93 *        in the same file as _Timer_Server_body.
94 */   
95
96extern Chain_Control _Timer_Ticks_chain;
97extern Chain_Control _Timer_Seconds_chain;
98
99/*
100 *  The following records define the control block used to manage
101 *  each timer.
102 */
103
104typedef struct {
105  Objects_Control  Object;
106  Watchdog_Control Ticker;
107  Timer_Classes    the_class;
108}   Timer_Control;
109
110/*
111 *  _Timer_Manager_initialization
112 *
113 *  DESCRIPTION:
114 *
115 *  This routine performs the initialization necessary for this manager.
116 */
117
118void _Timer_Manager_initialization(
119  unsigned32 maximum_timers
120);
121
122/*
123 *  _Timer_Server_body
124 *
125 *  DESCRIPTION:
126 *
127 *  This is the server for task based timers.  This task executes whenever
128 *  a task-based timer should fire.  It services both "after" and "when"
129 *  timers.  It is not created automatically but must be created explicitly
130 *  by the application before task-based timers may be initiated.
131 */
132
133Thread _Timer_Server_body(
134  unsigned32 ignored
135);
136
137/*
138 *  rtems_timer_create
139 *
140 *  DESCRIPTION:
141 *
142 *  This routine implements the rtems_timer_create directive.  The
143 *  timer will have the name name.  It returns the id of the
144 *  created timer in ID.
145 */
146
147rtems_status_code rtems_timer_create(
148  rtems_name    name,
149  Objects_Id   *id
150);
151
152/*
153 *  rtems_timer_ident
154 *
155 *  DESCRIPTION:
156 *
157 *  This routine implements the rtems_timer_ident directive.
158 *  This directive returns the timer ID associated with name.
159 *  If more than one timer is named name, then the timer
160 *  to which the ID belongs is arbitrary.
161 */
162
163rtems_status_code rtems_timer_ident(
164  rtems_name    name,
165  Objects_Id   *id
166);
167
168/*
169 *  rtems_timer_cancel
170 *
171 *  DESCRIPTION:
172 *
173 *  This routine implements the rtems_timer_cancel directive.  It is used
174 *  to stop the timer associated with ID from firing.
175 */
176
177rtems_status_code rtems_timer_cancel(
178  Objects_Id id
179);
180
181/*
182 *  rtems_timer_delete
183 *
184 *  DESCRIPTION:
185 *
186 *  This routine implements the rtems_timer_delete directive.  The
187 *  timer indicated by ID is deleted.
188 */
189
190rtems_status_code rtems_timer_delete(
191  Objects_Id id
192);
193
194/*
195 *  rtems_timer_fire_after
196 *
197 *  DESCRIPTION:
198 *
199 *  This routine implements the rtems_timer_fire_after directive.  It
200 *  initiates the timer associated with ID to fire in ticks clock ticks.
201 *  When the timer fires, the routine will be invoked in the context
202 *  of the rtems_clock_tick directive which is normally invoked as
203 *  part of servicing a periodic interupt.
204 */
205
206rtems_status_code rtems_timer_fire_after(
207  Objects_Id                         id,
208  rtems_interval                     ticks,
209  rtems_timer_service_routine_entry  routine,
210  void                              *user_data
211);
212
213/*
214 *  rtems_timer_server_fire_after
215 *
216 *  DESCRIPTION:
217 *
218 *  This routine implements the rtems_timer_server_fire_after directive.  It
219 *  initiates the timer associated with ID to fire in ticks clock
220 *  ticks.  When the timer fires, the routine will be invoked by the
221 *  Timer Server in the context of a task NOT IN THE CONTEXT of the
222 *  clock tick interrupt.
223 */
224
225rtems_status_code rtems_timer_server_fire_after(
226  Objects_Id                         id,
227  rtems_interval                     ticks,
228  rtems_timer_service_routine_entry  routine,
229  void                              *user_data
230);
231
232/*
233 *  rtems_timer_fire_when
234 *
235 *  DESCRIPTION:
236 *
237 *  This routine implements the rtems_timer_fire_when directive.  It
238 *  initiates the timer associated with ID to fire at wall_time
239 *  When the timer fires, the routine will be invoked in the context
240 *  of the rtems_clock_tick directive which is normally invoked as
241 *  part of servicing a periodic interupt.
242 */
243
244rtems_status_code rtems_timer_fire_when(
245  Objects_Id                          id,
246  rtems_time_of_day                  *wall_time,
247  rtems_timer_service_routine_entry   routine,
248  void                               *user_data
249);
250
251/*
252 *  rtems_timer_server_fire_when
253 *
254 *  DESCRIPTION:
255 *
256 *  This routine implements the rtems_timer_server_fire_when directive.  It
257 *  initiates the timer associated with ID to fire at wall_time
258 *  When the timer fires, the routine will be invoked by the
259 *  Timer Server in the context of a task NOT IN THE CONTEXT of the
260 *  clock tick interrupt.
261 */
262
263rtems_status_code rtems_timer_server_fire_when(
264  Objects_Id                          id,
265  rtems_time_of_day                  *wall_time,
266  rtems_timer_service_routine_entry   routine,
267  void                               *user_data
268);
269
270/*
271 *  rtems_timer_reset
272 *
273 *  DESCRIPTION:
274 *
275 *  This routine implements the rtems_timer_reset directive.  It is used
276 *  to reinitialize the interval timer associated with ID just as if
277 *  rtems_timer_fire_after were re-invoked with the same arguments that
278 *  were used to initiate this timer.
279 */
280
281rtems_status_code rtems_timer_reset(
282  Objects_Id id
283);
284
285/*
286 *  rtems_timer_initiate_server
287 *
288 *  DESCRIPTION:
289 *
290 *  This routine implements the rtems_timer_initiate_server directive.
291 *  It creates and starts the server that executes task-based timers.
292 *  It must be invoked before any task-based timers can be initiated.
293 */
294
295#define RTEMS_TIMER_SERVER_DEFAULT_PRIORITY -1
296
297rtems_status_code rtems_timer_initiate_server(
298  unsigned32           priority,
299  unsigned32           stack_size,
300  rtems_attribute      attribute_set
301);
302
303/*
304 *  rtems_timer_get_information
305 *
306 *  DESCRIPTION:
307 *
308 *  This routine implements the rtems_timer_get_information directive.
309 *  This directive returns information about the timer.
310 */
311
312typedef struct {
313  Timer_Classes      the_class;
314  Watchdog_Interval  initial;
315  Watchdog_Interval  start_time;
316  Watchdog_Interval  stop_time;
317} rtems_timer_information;
318
319rtems_status_code rtems_timer_get_information(
320  Objects_Id               id,
321  rtems_timer_information *the_info
322);
323
324/*
325 *  Macros and routines that expose the mechanisms required to service
326 *  the Timer Server timer.  These stop the timer, synchronize it with
327 *  the current time, and restart it.
328 */
329
330extern Watchdog_Control _Timer_Seconds_timer;
331
332#define _Timer_Server_stop_ticks_timer() \
333      _Watchdog_Remove( &_Timer_Server->Timer )
334
335#define _Timer_Server_stop_seconds_timer() \
336      _Watchdog_Remove( &_Timer_Seconds_timer );
337
338void _Timer_Server_process_ticks_chain(void);
339void _Timer_Server_process_seconds_chain(void);
340
341#define _Timer_Server_reset_ticks_timer() \
342   do { \
343      if ( !_Chain_Is_empty( &_Timer_Ticks_chain ) ) { \
344        _Watchdog_Insert_ticks( &_Timer_Server->Timer, \
345           ((Watchdog_Control *)_Timer_Ticks_chain.first)->delta_interval ); \
346      } \
347   } while (0)
348
349#define _Timer_Server_reset_seconds_timer() \
350   do { \
351      if ( !_Chain_Is_empty( &_Timer_Seconds_chain ) ) { \
352        _Watchdog_Insert_seconds( &_Timer_Seconds_timer, \
353          ((Watchdog_Control *)_Timer_Seconds_chain.first)->delta_interval ); \
354      } \
355   } while (0)
356
357#ifndef __RTEMS_APPLICATION__
358#include <rtems/rtems/timer.inl>
359#endif
360
361#ifdef __cplusplus
362}
363#endif
364
365#endif
366/* end of include file */
Note: See TracBrowser for help on using the repository browser.