source: rtems/cpukit/rtems/include/rtems/rtems/timer.h @ d3b72ca3

4.104.115
Last change on this file since d3b72ca3 was d3b72ca3, checked in by Glenn Humphrey <glenn.humphrey@…>, on 12/15/09 at 18:26:42

2009-12-15 Glenn Humphrey <glenn.humphrey@…>

  • rtems/include/rtems/rtems/dpmem.h, rtems/include/rtems/rtems/event.h, rtems/include/rtems/rtems/message.h, rtems/include/rtems/rtems/part.h, rtems/include/rtems/rtems/ratemon.h, rtems/include/rtems/rtems/region.h, rtems/include/rtems/rtems/semmp.h, rtems/include/rtems/rtems/signal.h, rtems/include/rtems/rtems/signalmp.h, rtems/include/rtems/rtems/tasks.h, rtems/include/rtems/rtems/timer.h, rtems/src/dpmemcreate.c, rtems/src/dpmemdelete.c, rtems/src/dpmemexternal2internal.c, rtems/src/dpmemident.c, rtems/src/dpmeminternal2external.c, rtems/src/eventsend.c, rtems/src/msgqbroadcast.c, rtems/src/msgqcreate.c, rtems/src/msgqdelete.c, rtems/src/msgqflush.c, rtems/src/msgqgetnumberpending.c, rtems/src/msgqident.c, rtems/src/msgqreceive.c, rtems/src/msgqsend.c, rtems/src/msgqurgent.c, rtems/src/partcreate.c, rtems/src/partdelete.c, rtems/src/partgetbuffer.c, rtems/src/partident.c, rtems/src/partreturnbuffer.c, rtems/src/ratemoncancel.c, rtems/src/ratemoncreate.c, rtems/src/ratemondelete.c, rtems/src/ratemongetstatistics.c, rtems/src/ratemongetstatus.c, rtems/src/ratemonident.c, rtems/src/ratemonperiod.c, rtems/src/ratemonresetstatistics.c, rtems/src/regioncreate.c, rtems/src/regiondelete.c, rtems/src/regionextend.c, rtems/src/regiongetfreeinfo.c, rtems/src/regiongetinfo.c, rtems/src/regiongetsegment.c, rtems/src/regiongetsegmentsize.c, rtems/src/regionident.c, rtems/src/regionresizesegment.c, rtems/src/regionreturnsegment.c, rtems/src/signalmp.c, rtems/src/signalsend.c, rtems/src/taskcreate.c, rtems/src/taskdelete.c, rtems/src/taskgetnote.c, rtems/src/taskident.c, rtems/src/taskissuspended.c, rtems/src/taskrestart.c, rtems/src/taskresume.c, rtems/src/tasksetnote.c, rtems/src/tasksetpriority.c, rtems/src/tasksuspend.c, rtems/src/timercancel.c, rtems/src/timercreate.c, rtems/src/timerdelete.c, rtems/src/timerfireafter.c, rtems/src/timerfirewhen.c, rtems/src/timergetinfo.c, rtems/src/timerident.c, rtems/src/timerreset.c, rtems/src/timerserverfireafter.c, rtems/src/timerserverfirewhen.c: Changed Objects_Id to rtems_id in the public API.
  • Property mode set to 100644
File size: 11.5 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-2009.
26 *  On-Line Applications Research Corporation (OAR).
27 *
28 *  Copyright (c) 2009 embedded brains GmbH.
29 *
30 *  The license and distribution terms for this file may be
31 *  found in the file LICENSE in this distribution or at
32 *  http://www.rtems.com/license/LICENSE.
33 *
34 *  $Id$
35 */
36
37#ifndef _RTEMS_RTEMS_TIMER_H
38#define _RTEMS_RTEMS_TIMER_H
39
40/**
41 *  This constant is defined to extern most of the time when using
42 *  this header file.  However by defining it to nothing, the data
43 *  declared in this header file can be instantiated.  This is done
44 *  in a single per manager file.
45 */
46#ifndef RTEMS_TIMER_EXTERN
47#define RTEMS_TIMER_EXTERN extern
48#endif
49
50#ifdef __cplusplus
51extern "C" {
52#endif
53
54#include <rtems/score/object.h>
55#include <rtems/score/watchdog.h>
56#include <rtems/score/thread.h>
57#include <rtems/score/chain.h>
58#include <rtems/rtems/clock.h>
59#include <rtems/rtems/attr.h>
60
61/**
62 *  @defgroup ClassicTimer Timers
63 *
64 *  @ingroup ClassicRTEMS
65 *
66 *  This encapsulates functionality related to the Classic API Timer
67 *  Manager.  This manager provides functionality which allows the
68 *  application to schedule the execution of methods at a specified
69 *  time in the future.  These methods may be scheduled based upon
70 *  interval or wall time and may be executed in either the clock tick
71 *  ISR or in a special dedicated timer server task.
72 */
73/**@{*/
74
75/**
76 *  The following enumerated type details the classes to which a timer
77 *  may belong.
78 */
79typedef enum {
80  /**
81   * This value indicates the timer is currently in use as an interval
82   * timer which will fire in the clock tick ISR.
83   */
84  TIMER_INTERVAL,
85
86  /**
87   * This value indicates the timer is currently in use as an interval
88   * timer which will fire in the timer server task.
89   */
90  TIMER_INTERVAL_ON_TASK,
91
92  /**
93   * This value indicates the timer is currently in use as an time of day
94   * timer which will fire in the clock tick ISR.
95   */
96  TIMER_TIME_OF_DAY,
97
98  /**
99   * This value indicates the timer is currently in use as an time of day
100   * timer which will fire in the timer server task.
101   */
102  TIMER_TIME_OF_DAY_ON_TASK,
103
104  /**
105   * This value indicates the timer is currently not in use.
106   */
107  TIMER_DORMANT
108} Timer_Classes;
109
110/**
111 *  The following types define a pointer to a timer service routine.
112 */
113typedef void rtems_timer_service_routine;
114
115/**
116 *  This type defines the type used to manage and indirectly invoke
117 *  Timer Service Routines (TSRs).  This defines the prototype and interface
118 *  for a function which is to be used as a TSR.
119 */
120typedef rtems_timer_service_routine ( *rtems_timer_service_routine_entry )(
121                 rtems_id,
122                 void *
123             );
124
125/**
126 *  The following records define the control block used to manage
127 *  each timer.
128 */
129typedef struct {
130  /** This field is the object management portion of a Timer instance. */
131  Objects_Control  Object;
132  /** This field is the Watchdog instance which will be the scheduled. */
133  Watchdog_Control Ticker;
134  /** This field indicates what type of timer this currently is. */
135  Timer_Classes    the_class;
136}   Timer_Control;
137
138typedef struct Timer_server_Control Timer_server_Control;
139
140/**
141 * @brief Method used to schedule the insertion of task based timers.
142 */
143typedef void (*Timer_server_Schedule_operation)(
144  Timer_server_Control *timer_server,
145  Timer_Control        *timer
146);
147
148typedef struct {
149  /**
150   * @brief This watchdog that will be registered in the system tick mechanic
151   * for timer server wake-up.
152   */
153  Watchdog_Control System_watchdog;
154
155  /**
156   * @brief Chain for watchdogs which will be triggered by the timer server.
157   */
158  Chain_Control Chain;
159
160  /**
161   * @brief Last known time snapshot of the timer server.
162   *
163   * The units may be ticks or seconds.
164   */
165  Watchdog_Interval volatile last_snapshot;
166} Timer_server_Watchdogs;
167
168struct Timer_server_Control {
169  /**
170   * @brief Timer server thread.
171   */
172  Thread_Control *thread;
173
174  /**
175   * @brief The schedule operation method of the timer server.
176   */
177  Timer_server_Schedule_operation schedule_operation;
178
179  /**
180   * @brief Interval watchdogs triggered by the timer server.
181   */
182  Timer_server_Watchdogs Interval_watchdogs;
183
184  /**
185   * @brief TOD watchdogs triggered by the timer server.
186   */
187  Timer_server_Watchdogs TOD_watchdogs;
188
189  /**
190   * @brief Chain of timers scheduled for insert.
191   *
192   * This pointer is not @c NULL whenever the interval and TOD chains are
193   * processed.  After the processing this list will be checked and if
194   * necessary the processing will be restarted.  Processing of these chains
195   * can be only interrupted through interrupts.
196   */
197  Chain_Control *volatile insert_chain;
198
199  /**
200   * @brief Indicates that the timer server is active or not.
201   *
202   * The server is active after the delay on a system watchdog.  The activity
203   * period of the server ends when no more watchdogs managed by the server
204   * fire.  The system watchdogs must not be manipulated when the server is
205   * active.
206   */
207  bool volatile active;
208};
209
210/**
211 * @brief Pointer to default timer server control block.
212 *
213 * This value is @c NULL when the default timer server is not initialized.
214 */
215RTEMS_TIMER_EXTERN Timer_server_Control *volatile _Timer_server;
216
217/**
218 *  The following defines the information control block used to manage
219 *  this class of objects.
220 */
221RTEMS_TIMER_EXTERN Objects_Information  _Timer_Information;
222
223/**
224 *  @brief _Timer_Manager_initialization
225 *
226 *  This routine performs the initialization necessary for this manager.
227 */
228void _Timer_Manager_initialization(void);
229
230/**
231 *  @brief rtems_timer_create
232 *
233 *  This routine implements the rtems_timer_create directive.  The
234 *  timer will have the name name.  It returns the id of the
235 *  created timer in ID.
236 */
237rtems_status_code rtems_timer_create(
238  rtems_name    name,
239  rtems_id     *id
240);
241
242/**
243 *  @brief rtems_timer_ident
244 *
245 *  This routine implements the rtems_timer_ident directive.
246 *  This directive returns the timer ID associated with name.
247 *  If more than one timer is named name, then the timer
248 *  to which the ID belongs is arbitrary.
249 */
250rtems_status_code rtems_timer_ident(
251  rtems_name    name,
252  rtems_id     *id
253);
254
255/**
256 *  @brief rtems_timer_cancel
257 *
258 *  This routine implements the rtems_timer_cancel directive.  It is used
259 *  to stop the timer associated with ID from firing.
260 */
261rtems_status_code rtems_timer_cancel(
262  rtems_id   id
263);
264
265/**
266 *  @brief rtems_timer_delete
267 *
268 *  This routine implements the rtems_timer_delete directive.  The
269 *  timer indicated by ID is deleted.
270 */
271rtems_status_code rtems_timer_delete(
272  rtems_id   id
273);
274
275/**
276 *  @brief rtems_timer_fire_after
277 *
278 *  This routine implements the rtems_timer_fire_after directive.  It
279 *  initiates the timer associated with ID to fire in ticks clock ticks.
280 *  When the timer fires, the routine will be invoked in the context
281 *  of the rtems_clock_tick directive which is normally invoked as
282 *  part of servicing a periodic interupt.
283 */
284rtems_status_code rtems_timer_fire_after(
285  rtems_id                           id,
286  rtems_interval                     ticks,
287  rtems_timer_service_routine_entry  routine,
288  void                              *user_data
289);
290
291/**
292 *  @brief rtems_timer_server_fire_after
293 *
294 *  This routine implements the rtems_timer_server_fire_after directive.  It
295 *  initiates the timer associated with ID to fire in ticks clock
296 *  ticks.  When the timer fires, the routine will be invoked by the
297 *  Timer Server in the context of a task NOT IN THE CONTEXT of the
298 *  clock tick interrupt.
299 */
300rtems_status_code rtems_timer_server_fire_after(
301  rtems_id                           id,
302  rtems_interval                     ticks,
303  rtems_timer_service_routine_entry  routine,
304  void                              *user_data
305);
306
307/**
308 *  @brief rtems_timer_fire_when
309 *
310 *  This routine implements the rtems_timer_fire_when directive.  It
311 *  initiates the timer associated with ID to fire at wall_time
312 *  When the timer fires, the routine will be invoked in the context
313 *  of the rtems_clock_tick directive which is normally invoked as
314 *  part of servicing a periodic interupt.
315 */
316rtems_status_code rtems_timer_fire_when(
317  rtems_id                            id,
318  rtems_time_of_day                  *wall_time,
319  rtems_timer_service_routine_entry   routine,
320  void                               *user_data
321);
322
323/**
324 *  @brief rtems_timer_server_fire_when
325 *
326 *  This routine implements the rtems_timer_server_fire_when directive.  It
327 *  initiates the timer associated with ID to fire at wall_time
328 *  When the timer fires, the routine will be invoked by the
329 *  Timer Server in the context of a task NOT IN THE CONTEXT of the
330 *  clock tick interrupt.
331 */
332rtems_status_code rtems_timer_server_fire_when(
333  rtems_id                            id,
334  rtems_time_of_day                  *wall_time,
335  rtems_timer_service_routine_entry   routine,
336  void                               *user_data
337);
338
339/**
340 *  @brief rtems_timer_reset
341 *
342 *  This routine implements the rtems_timer_reset directive.  It is used
343 *  to reinitialize the interval timer associated with ID just as if
344 *  rtems_timer_fire_after were re-invoked with the same arguments that
345 *  were used to initiate this timer.
346 */
347rtems_status_code rtems_timer_reset(
348  rtems_id   id
349);
350
351/**
352 *  @brief rtems_timer_initiate_server
353 *
354 *  This routine implements the rtems_timer_initiate_server directive.
355 *  It creates and starts the server that executes task-based timers.
356 *  It must be invoked before any task-based timers can be initiated.
357 */
358rtems_status_code rtems_timer_initiate_server(
359  uint32_t             priority,
360  uint32_t             stack_size,
361  rtems_attribute      attribute_set
362);
363
364/**
365 *  This is the default value for the priority of the Timer Server.
366 *  When given this priority, a special high priority not accessible
367 *  via the Classic API is used.
368 */
369#define RTEMS_TIMER_SERVER_DEFAULT_PRIORITY (uint32_t) -1
370
371/**
372 *  This is the structure filled in by the timer get information
373 *  service.
374 */
375typedef struct {
376  /** This indicates the current type of the timer. */
377  Timer_Classes      the_class;
378  /** This indicates the initial requested interval. */
379  Watchdog_Interval  initial;
380  /** This indicates the time the timer was initially scheduled. */
381  Watchdog_Interval  start_time;
382  /** This indicates the time the timer is scheduled to fire. */
383  Watchdog_Interval  stop_time;
384} rtems_timer_information;
385
386/**
387 *  @brief rtems_timer_get_information
388 *
389 *  This routine implements the rtems_timer_get_information directive.
390 *  This directive returns information about the timer.
391 */
392rtems_status_code rtems_timer_get_information(
393  rtems_id                 id,
394  rtems_timer_information *the_info
395);
396
397#ifndef __RTEMS_APPLICATION__
398#include <rtems/rtems/timer.inl>
399#endif
400
401#ifdef __cplusplus
402}
403#endif
404
405/**@}*/
406
407#endif
408/* end of include file */
Note: See TracBrowser for help on using the repository browser.