timer.h

00001 /*
00002  * Copyright (C) 2001,2002,2003 Philippe Gerum <rpm@xenomai.org>.
00003  *
00004  * RTAI/fusion is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published
00006  * by the Free Software Foundation; either version 2 of the License,
00007  * or (at your option) any later version.
00008  *
00009  * RTAI/fusion 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 RTAI/fusion; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00017  * 02111-1307, USA.
00018  */
00019 
00020 #ifndef _RTAI_NUCLEUS_TIMER_H
00021 #define _RTAI_NUCLEUS_TIMER_H
00022 
00023 #include <nucleus/queue.h>
00024 
00025 #if defined(__KERNEL__) || defined(__RTAI_UVM__) || defined(__RTAI_SIM__)
00026 
00027 /* Number of outstanding timers (hint only) -- must be ^2 */
00028 #define XNTIMER_WHEELSIZE 64
00029 #define XNTIMER_WHEELMASK (XNTIMER_WHEELSIZE - 1)
00030 
00031 #define XNTIMER_ENABLED   0x00000001
00032 #define XNTIMER_DEQUEUED  0x00000002
00033 #define XNTIMER_KILLED    0x00000004
00034 
00035 /* These flags are available to the real-time interfaces */
00036 #define XNTIMER_SPARE0  0x01000000
00037 #define XNTIMER_SPARE1  0x02000000
00038 #define XNTIMER_SPARE2  0x04000000
00039 #define XNTIMER_SPARE3  0x08000000
00040 #define XNTIMER_SPARE4  0x10000000
00041 #define XNTIMER_SPARE5  0x20000000
00042 #define XNTIMER_SPARE6  0x40000000
00043 #define XNTIMER_SPARE7  0x80000000
00044 
00045 #define XNTIMER_LOPRIO  (-999999999)
00046 #define XNTIMER_STDPRIO 0
00047 #define XNTIMER_HIPRIO  999999999
00048 
00049 #define XNTIMER_KEEPER_ID 0
00050 
00051 struct xnsched;
00052 
00053 typedef struct xntimer {
00054 
00055     xnholder_t link;
00056 
00057 #define link2timer(laddr) \
00058 ((xntimer_t *)(((char *)laddr) - (int)(&((xntimer_t *)0)->link)))
00059 
00060     xnflags_t status;           /* !< Timer status. */
00061 
00062     xnticks_t date;             /* !< Absolute timeout date (in ticks). */
00063 
00064     xnticks_t interval;         /* !< Periodic interval (in ticks, 0 == one shot). */
00065 
00066     int prio;                   /* !< Internal priority. */
00067 
00068     struct xnsched *sched;      /* !< Sched structure to which the timer is
00069                                    attached. */
00070 
00071     void (*handler)(void *cookie); /* !< Timeout handler. */
00072 
00073     void *cookie;       /* !< Cookie to pass to the timeout handler. */
00074 
00075     XNARCH_DECL_DISPLAY_CONTEXT();
00076 
00077 } xntimer_t;
00078 
00079 #define xntimer_date(t)           ((t)->date)
00080 #if defined(CONFIG_SMP) && defined(CONFIG_RTAI_OPT_PERCPU_TIMER)
00081 #define xntimer_sched(t)          ((t)->sched)
00082 #elif defined(CONFIG_SMP)
00083 #define xntimer_sched(t)          (xnpod_sched_slot(XNTIMER_KEEPER_ID))
00084 #else /* !CONFIG_SMP */
00085 #define xntimer_sched(t)          xnpod_current_sched()
00086 #endif /* CONFIG_SMP && CONFIG_RTAI_OPT_PERCPU_TIMER*/
00087 #define xntimer_interval(t)       ((t)->interval)
00088 #define xntimer_set_cookie(t,c)   ((t)->cookie = (c))
00089 #define xntimer_set_priority(t,p) ((t)->prio = (p))
00090 
00091 static inline int xntimer_active_p (xntimer_t *timer) {
00092     return !testbits(timer->status,XNTIMER_DEQUEUED);
00093 }
00094 
00095 #ifdef __cplusplus
00096 extern "C" {
00097 #endif
00098 
00099 void xntimer_init(xntimer_t *timer,
00100                   void (*handler)(void *cookie),
00101                   void *cookie);
00102 
00103 void xntimer_destroy(xntimer_t *timer);
00104 
00105 void xntimer_do_timers(void);
00106 
00107 int xntimer_start(xntimer_t *timer,
00108                   xnticks_t value,
00109                   xnticks_t interval);
00110 
00111 void xntimer_stop_timer_inner(xntimer_t *timer);
00112 
00136 static inline void xntimer_stop(xntimer_t *timer)
00137 {
00138     if (!testbits(timer->status,XNTIMER_DEQUEUED))
00139         xntimer_stop_timer_inner(timer);
00140 }
00141 
00142 void xntimer_freeze(void);
00143 
00144 xnticks_t xntimer_get_date(xntimer_t *timer);
00145 
00146 xnticks_t xntimer_get_timeout(xntimer_t *timer);
00147 
00148 #if defined(CONFIG_SMP) && defined(CONFIG_RTAI_OPT_PERCPU_TIMER)
00149 int xntimer_set_sched(xntimer_t *timer, struct xnsched *sched);
00150 #else /* ! CONFIG_SMP || ! CONFIG_OPT_PERCPU_TIMER */
00151 #define xntimer_set_sched(timer,sched)
00152 #endif /* CONFIG_SMP && CONFIG_OPT_PERCPU_TIMER */
00153 
00154 #ifdef __cplusplus
00155 }
00156 #endif
00157 
00158 #endif /* __KERNEL__ || __RTAI_UVM__ || __RTAI_SIM__ */
00159 
00160 #endif /* !_RTAI_NUCLEUS_TIMER_H */

Generated on Wed Jun 22 22:54:02 2005 for RTAI Fusion API by  doxygen 1.4.1