timer.h

00001 /*
00002  * Copyright (C) 2001,2002,2003 Philippe Gerum <rpm@xenomai.org>.
00003  *
00004  * Xenomai is free software; you can redistribute it and/or modify it
00005  * under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * Xenomai is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with Xenomai; if not, write to the Free Software Foundation,
00016  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  *
00018  * As a special exception, the RTAI project gives permission
00019  * for additional uses of the text contained in its release of
00020  * Xenomai.
00021  *
00022  * The exception is that, if you link the Xenomai libraries with other
00023  * files to produce an executable, this does not by itself cause the
00024  * resulting executable to be covered by the GNU General Public License.
00025  * Your use of that executable is in no way restricted on account of
00026  * linking the Xenomai libraries code into it.
00027  *
00028  * This exception does not however invalidate any other reasons why
00029  * the executable file might be covered by the GNU General Public
00030  * License.
00031  *
00032  * This exception applies only to the code released by the
00033  * RTAI project under the name Xenomai.  If you copy code from other
00034  * RTAI project releases into a copy of Xenomai, as the General Public
00035  * License permits, the exception does not apply to the code that you
00036  * add in this way.  To avoid misleading anyone as to the status of
00037  * such modified files, you must delete this exception notice from
00038  * them.
00039  *
00040  * If you write modifications of your own for Xenomai, it is your
00041  * choice whether to permit this exception to apply to your
00042  * modifications. If you do not wish that, delete this exception
00043  * notice.
00044  */
00045 
00046 #ifndef _RTAI_NUCLEUS_TIMER_H
00047 #define _RTAI_NUCLEUS_TIMER_H
00048 
00049 #include <nucleus/queue.h>
00050 
00051 #define XNPOD_APERIODIC_TICK       0
00052 #define XNPOD_NO_TICK              ((xnticks_t)-1)
00053 
00054 #if defined(__KERNEL__) || defined(__RTAI_UVM__) || defined(__RTAI_SIM__)
00055 
00056 /* Number of outstanding timers (hint only) -- must be ^2 */
00057 #define XNTIMER_WHEELSIZE 128
00058 #define XNTIMER_WHEELMASK (XNTIMER_WHEELSIZE - 1)
00059 
00060 #define XNTIMER_ENABLED   0x00000001
00061 #define XNTIMER_DEQUEUED  0x00000002
00062 #define XNTIMER_KILLED    0x00000004
00063 
00064 /* These flags are available to the real-time interfaces */
00065 #define XNTIMER_SPARE0  0x01000000
00066 #define XNTIMER_SPARE1  0x02000000
00067 #define XNTIMER_SPARE2  0x04000000
00068 #define XNTIMER_SPARE3  0x08000000
00069 #define XNTIMER_SPARE4  0x10000000
00070 #define XNTIMER_SPARE5  0x20000000
00071 #define XNTIMER_SPARE6  0x40000000
00072 #define XNTIMER_SPARE7  0x80000000
00073 
00074 #define XNTIMER_LOPRIO  (-999999999)
00075 #define XNTIMER_STDPRIO 0
00076 #define XNTIMER_HIPRIO  999999999
00077 
00078 typedef struct xntimer {
00079 
00080     xnholder_t link;
00081 
00082 #define link2timer(laddr) \
00083 ((xntimer_t *)(((char *)laddr) - (int)(&((xntimer_t *)0)->link)))
00084 
00085     xnflags_t status;           /* !< Timer status. */
00086 
00087     xnticks_t date;             /* !< Absolute timeout date (in ticks). */
00088 
00089     xnticks_t interval;         /* !< Periodic interval (in ticks, 0 == one shot). */
00090 
00091     int prio;                   /* !< Internal priority. */
00092 
00093     void (*handler)(void *cookie); /* !< Timeout handler. */
00094 
00095     void *cookie;       /* !< Cookie to pass to the timeout handler. */
00096 
00097     XNARCH_DECL_DISPLAY_CONTEXT();
00098 
00099 } xntimer_t;
00100 
00101 #define xntimer_date(t)           ((t)->date)
00102 #define xntimer_interval(t)       ((t)->interval)
00103 #define xntimer_set_cookie(t,c)   ((t)->cookie = (c))
00104 #define xntimer_set_priority(t,p) ((t)->prio = (p))
00105 
00106 static inline int xntimer_active_p (xntimer_t *timer) {
00107     return !testbits(timer->status,XNTIMER_DEQUEUED);
00108 }
00109 
00110 #ifdef __cplusplus
00111 extern "C" {
00112 #endif
00113 
00114 void xntimer_init(xntimer_t *timer,
00115                   void (*handler)(void *cookie),
00116                   void *cookie);
00117 
00118 void xntimer_destroy(xntimer_t *timer);
00119 
00120 void xntimer_do_timers(void);
00121 
00122 int xntimer_start(xntimer_t *timer,
00123                   xnticks_t value,
00124                   xnticks_t interval);
00125 
00126 void xntimer_stop(xntimer_t *timer);
00127 
00128 void xntimer_freeze(void);
00129 
00130 xnticks_t xntimer_get_date(xntimer_t *timer);
00131 
00132 xnticks_t xntimer_get_timeout(xntimer_t *timer);
00133 
00134 #ifdef __cplusplus
00135 }
00136 #endif
00137 
00138 #endif /* __KERNEL__ || __RTAI_UVM__ || __RTAI_SIM__ */
00139 
00140 #endif /* !_RTAI_NUCLEUS_TIMER_H */

Generated on Mon Dec 13 09:49:49 2004 for RTAI API by  doxygen 1.3.9.1