source: rtems/cpukit/rtems/include/rtems/rtems/timer.h @ 8c8fd64

4.104.114.95
Last change on this file since 8c8fd64 was 8c8fd64, checked in by Joel Sherrill <joel.sherrill@…>, on 06/06/08 at 18:03:45

2008-06-06 Joel Sherrill <joel.sherrill@…>

  • rtems/include/rtems.h, rtems/include/rtems/rtems/clock.h, rtems/include/rtems/rtems/config.h, rtems/include/rtems/rtems/dpmem.h, rtems/include/rtems/rtems/eventset.h, rtems/include/rtems/rtems/object.h, rtems/include/rtems/rtems/part.h, rtems/include/rtems/rtems/ratemon.h, rtems/include/rtems/rtems/region.h, rtems/include/rtems/rtems/sem.h, rtems/include/rtems/rtems/tasks.h, rtems/include/rtems/rtems/timer.h, rtems/include/rtems/rtems/types.h, rtems/src/ratemonperiod.c: Improve Classic API Doxygen.
  • Property mode set to 100644
File size: 12.6 KB
Line 
1/**
2 * @file rtems/rtems/timer.h
3 *
4 *  This include file contains all the constants, structures, and
5 *  prototypes associated with the Timer Manager.  This manager provides
6 *  facilities to configure, initiate, cancel, and delete timers which will
7 *  fire at specified intervals of time.
8 *
9 *  Directives provided are:
10 *
11 *     - create a timer
12 *     - get an ID of a timer
13 *     - delete a timer
14 *     - set timer to fire in context of clock tick
15 *        - after a number of ticks have passed
16 *        - when a specified date and time has been reached
17 *     - initiate the timer server task
18 *     - set timer to fire in context of the timer server task
19 *        - after a number of ticks have passed
20 *        - when a specified date and time has been reached
21 *     - reset a timer
22 *     - cancel a time
23 */
24
25/*  COPYRIGHT (c) 1989-2008.
26 *  On-Line Applications Research Corporation (OAR).
27 *
28 *  The license and distribution terms for this file may be
29 *  found in the file LICENSE in this distribution or at
30 *  http://www.rtems.com/license/LICENSE.
31 *
32 *  $Id$
33 */
34
35#ifndef _RTEMS_RTEMS_TIMER_H
36#define _RTEMS_RTEMS_TIMER_H
37
38/**
39 *  This constant is defined to extern most of the time when using
40 *  this header file.  However by defining it to nothing, the data
41 *  declared in this header file can be instantiated.  This is done
42 *  in a single per manager file.
43 */
44#ifndef RTEMS_TIMER_EXTERN
45#define RTEMS_TIMER_EXTERN extern
46#endif
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52#include <rtems/score/object.h>
53#include <rtems/score/watchdog.h>
54#include <rtems/score/thread.h>
55#include <rtems/rtems/clock.h>
56#include <rtems/rtems/attr.h>
57
58/**
59 *  @defgroup ClassicTimer Classic API Timer
60 *
61 *  This encapsulates functionality which XXX
62 */
63/**@{*/
64
65/**
66 *  The following enumerated type details the classes to which a timer
67 *  may belong.
68 */
69typedef enum {
70  /**
71   * This value indicates the timer is currently in use as an interval
72   * timer which will fire in the clock tick ISR.
73   */
74  TIMER_INTERVAL,
75
76  /**
77   * This value indicates the timer is currently in use as an interval
78   * timer which will fire in the timer server task.
79   */
80  TIMER_INTERVAL_ON_TASK,
81
82  /**
83   * This value indicates the timer is currently in use as an time of day
84   * timer which will fire in the clock tick ISR.
85   */
86  TIMER_TIME_OF_DAY,
87
88  /**
89   * This value indicates the timer is currently in use as an time of day
90   * timer which will fire in the timer server task.
91   */
92  TIMER_TIME_OF_DAY_ON_TASK,
93
94  /**
95   * This value indicates the timer is currently not in use.
96   */
97  TIMER_DORMANT
98} Timer_Classes;
99
100/**
101 *  The following types define a pointer to a timer service routine.
102 */
103typedef void rtems_timer_service_routine;
104
105/**
106 *  This type defines the type used to manage and indirectly invoke
107 *  Timer Service Routines (TSRs).  This defines the prototype and interface
108 *  for a function which is to be used as a TSR.
109 */
110typedef rtems_timer_service_routine ( *rtems_timer_service_routine_entry )(
111                 rtems_id,
112                 void *
113             );
114
115/**
116 *  The following defines the information control block used to manage
117 *  this class of objects.
118 */
119RTEMS_TIMER_EXTERN Objects_Information  _Timer_Information;
120
121/**
122 *  Pointer to TCB of the Timer Server.  This is NULL before the
123 *  server is executing and task-based timers are not allowed to be
124 *  initiated until the server is started.
125 */
126RTEMS_TIMER_EXTERN Thread_Control *_Timer_Server;
127
128/**
129 *  This chain contains the list of interval timers that are
130 *  executed in the context of the Timer Server.
131 *
132 *  @note This is extern'ed because they do not have to be in the
133 *        minimum footprint.  It is only really required when
134 *        task-based timers are used.  Since task-based timers can
135 *        not be started until the server is initiated, this structure
136 *        does not have to be initialized until then.  This is declared
137 *        in the same file as _Timer_Server_body.
138 */
139extern Chain_Control _Timer_Ticks_chain;
140
141/**
142 *  This chain contains the list of time of day timers that are
143 *  executed in the context of the Timer Server.
144 *
145 *  @note This is extern'ed because they do not have to be in the
146 *        minimum footprint.  It is only really required when
147 *        task-based timers are used.  Since task-based timers can
148 *        not be started until the server is initiated, this structure
149 *        does not have to be initialized until then.  This is declared
150 *        in the same file as _Timer_Server_body.
151 */
152extern Chain_Control _Timer_Seconds_chain;
153
154/**
155 *  The following records define the control block used to manage
156 *  each timer.
157 */
158typedef struct {
159  /** This field is the object management portion of a Timer instance. */
160  Objects_Control  Object;
161  /** This field is the Watchdog instance which will be the scheduled. */
162  Watchdog_Control Ticker;
163  /** This field indicates what type of timer this currently is. */
164  Timer_Classes    the_class;
165}   Timer_Control;
166
167/**
168 *  @brief _Timer_Manager_initialization
169 *
170 *  This routine performs the initialization necessary for this manager.
171 */
172void _Timer_Manager_initialization(
173  uint32_t   maximum_timers
174);
175
176/**
177 *  @brief _Timer_Server_body
178 *
179 *  This is the server for task based timers.  This task executes whenever
180 *  a task-based timer should fire.  It services both "after" and "when"
181 *  timers.  It is not created automatically but must be created explicitly
182 *  by the application before task-based timers may be initiated.
183 */
184Thread _Timer_Server_body(
185  uint32_t   ignored
186);
187
188/**
189 *  @brief rtems_timer_create
190 *
191 *  This routine implements the rtems_timer_create directive.  The
192 *  timer will have the name name.  It returns the id of the
193 *  created timer in ID.
194 */
195rtems_status_code rtems_timer_create(
196  rtems_name    name,
197  Objects_Id   *id
198);
199
200/**
201 *  @brief rtems_timer_ident
202 *
203 *  This routine implements the rtems_timer_ident directive.
204 *  This directive returns the timer ID associated with name.
205 *  If more than one timer is named name, then the timer
206 *  to which the ID belongs is arbitrary.
207 */
208rtems_status_code rtems_timer_ident(
209  rtems_name    name,
210  Objects_Id   *id
211);
212
213/**
214 *  @brief rtems_timer_cancel
215 *
216 *  This routine implements the rtems_timer_cancel directive.  It is used
217 *  to stop the timer associated with ID from firing.
218 */
219rtems_status_code rtems_timer_cancel(
220  Objects_Id id
221);
222
223/**
224 *  @brief rtems_timer_delete
225 *
226 *  This routine implements the rtems_timer_delete directive.  The
227 *  timer indicated by ID is deleted.
228 */
229rtems_status_code rtems_timer_delete(
230  Objects_Id id
231);
232
233/**
234 *  @brief rtems_timer_fire_after
235 *
236 *  This routine implements the rtems_timer_fire_after directive.  It
237 *  initiates the timer associated with ID to fire in ticks clock ticks.
238 *  When the timer fires, the routine will be invoked in the context
239 *  of the rtems_clock_tick directive which is normally invoked as
240 *  part of servicing a periodic interupt.
241 */
242rtems_status_code rtems_timer_fire_after(
243  Objects_Id                         id,
244  rtems_interval                     ticks,
245  rtems_timer_service_routine_entry  routine,
246  void                              *user_data
247);
248
249/**
250 *  @brief rtems_timer_server_fire_after
251 *
252 *  This routine implements the rtems_timer_server_fire_after directive.  It
253 *  initiates the timer associated with ID to fire in ticks clock
254 *  ticks.  When the timer fires, the routine will be invoked by the
255 *  Timer Server in the context of a task NOT IN THE CONTEXT of the
256 *  clock tick interrupt.
257 */
258rtems_status_code rtems_timer_server_fire_after(
259  Objects_Id                         id,
260  rtems_interval                     ticks,
261  rtems_timer_service_routine_entry  routine,
262  void                              *user_data
263);
264
265/**
266 *  @brief rtems_timer_fire_when
267 *
268 *  This routine implements the rtems_timer_fire_when directive.  It
269 *  initiates the timer associated with ID to fire at wall_time
270 *  When the timer fires, the routine will be invoked in the context
271 *  of the rtems_clock_tick directive which is normally invoked as
272 *  part of servicing a periodic interupt.
273 */
274rtems_status_code rtems_timer_fire_when(
275  Objects_Id                          id,
276  rtems_time_of_day                  *wall_time,
277  rtems_timer_service_routine_entry   routine,
278  void                               *user_data
279);
280
281/**
282 *  @brief rtems_timer_server_fire_when
283 *
284 *  This routine implements the rtems_timer_server_fire_when directive.  It
285 *  initiates the timer associated with ID to fire at wall_time
286 *  When the timer fires, the routine will be invoked by the
287 *  Timer Server in the context of a task NOT IN THE CONTEXT of the
288 *  clock tick interrupt.
289 */
290rtems_status_code rtems_timer_server_fire_when(
291  Objects_Id                          id,
292  rtems_time_of_day                  *wall_time,
293  rtems_timer_service_routine_entry   routine,
294  void                               *user_data
295);
296
297/**
298 *  @brief rtems_timer_reset
299 *
300 *  This routine implements the rtems_timer_reset directive.  It is used
301 *  to reinitialize the interval timer associated with ID just as if
302 *  rtems_timer_fire_after were re-invoked with the same arguments that
303 *  were used to initiate this timer.
304 */
305rtems_status_code rtems_timer_reset(
306  Objects_Id id
307);
308
309/**
310 *  @brief rtems_timer_initiate_server
311 *
312 *  This routine implements the rtems_timer_initiate_server directive.
313 *  It creates and starts the server that executes task-based timers.
314 *  It must be invoked before any task-based timers can be initiated.
315 */
316rtems_status_code rtems_timer_initiate_server(
317  uint32_t             priority,
318  uint32_t             stack_size,
319  rtems_attribute      attribute_set
320);
321
322/**
323 *  This is the default value for the priority of the Timer Server.
324 *  When given this priority, a special high priority not accessible
325 *  via the Classic API is used.
326 */
327#define RTEMS_TIMER_SERVER_DEFAULT_PRIORITY -1
328
329/**
330 *  This is the structure filled in by the timer get information
331 *  service.
332 */
333typedef struct {
334  /** This indicates the current type of the timer. */
335  Timer_Classes      the_class;
336  /** This indicates the initial requested interval. */
337  Watchdog_Interval  initial;
338  /** This indicates the time the timer was initially scheduled. */
339  Watchdog_Interval  start_time;
340  /** This indicates the time the timer is scheduled to fire. */
341  Watchdog_Interval  stop_time;
342} rtems_timer_information;
343
344/**
345 *  @brief rtems_timer_get_information
346 *
347 *  This routine implements the rtems_timer_get_information directive.
348 *  This directive returns information about the timer.
349 */
350rtems_status_code rtems_timer_get_information(
351  Objects_Id               id,
352  rtems_timer_information *the_info
353);
354
355/**
356 *  Macros and routines that expose the mechanisms required to service
357 *  the Timer Server timer.  These stop the timer, synchronize it with
358 *  the current time, and restart it.
359 */
360extern Watchdog_Control _Timer_Seconds_timer;
361
362/**
363 *  This method is used to temporarily disable updates to the
364 *  Ticks Timer Chain managed by the Timer Server.
365 */
366#define _Timer_Server_stop_ticks_timer() \
367      _Watchdog_Remove( &_Timer_Server->Timer )
368
369/**
370 *  This method is used to temporarily disable updates to the
371 *  Seconds Timer Chain managed by the Timer Server.
372 */
373#define _Timer_Server_stop_seconds_timer() \
374      _Watchdog_Remove( &_Timer_Seconds_timer );
375
376/**
377 *  This is a helper function which processes the ticks chain when
378 *  needed.  It advances time for the ticks chain which results in
379 *  timers firing.
380 */
381void _Timer_Server_process_ticks_chain(void);
382
383/**
384 *  This is a helper function which processes the seconds chain when
385 *  needed.  It advances time for the seconds chain which results in
386 *  timers firing.
387 */
388void _Timer_Server_process_seconds_chain(void);
389
390/**
391 *  This method resets a timer and places it on the Ticks chain.  It
392 *  is assumed that the timer has already been canceled.
393 */
394#define _Timer_Server_reset_ticks_timer() \
395   do { \
396      if ( !_Chain_Is_empty( &_Timer_Ticks_chain ) ) { \
397        _Watchdog_Insert_ticks( &_Timer_Server->Timer, \
398           ((Watchdog_Control *)_Timer_Ticks_chain.first)->delta_interval ); \
399      } \
400   } while (0)
401
402/**
403 *  This method resets a timer and places it on the Seconds chain.  It
404 *  is assumed that the timer has already been canceled.
405 */
406#define _Timer_Server_reset_seconds_timer() \
407   do { \
408      if ( !_Chain_Is_empty( &_Timer_Seconds_chain ) ) { \
409        _Watchdog_Insert_seconds( &_Timer_Seconds_timer, \
410          ((Watchdog_Control *)_Timer_Seconds_chain.first)->delta_interval ); \
411      } \
412   } while (0)
413
414#ifndef __RTEMS_APPLICATION__
415#include <rtems/rtems/timer.inl>
416#endif
417
418#ifdef __cplusplus
419}
420#endif
421
422/**@}*/
423
424#endif
425/* end of include file */
Note: See TracBrowser for help on using the repository browser.