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 #ifdef CONFIG_RTAI_HW_PERIODIC_TIMER
00028 /* Number of outstanding timers (hint only) -- must be ^2 */
00029 #define XNTIMER_WHEELSIZE 64
00030 #define XNTIMER_WHEELMASK (XNTIMER_WHEELSIZE - 1)
00031 #else /* !CONFIG_RTAI_HW_PERIODIC_TIMER */
00032 #define XNTIMER_WHEELSIZE 1
00033 #endif /* CONFIG_RTAI_HW_PERIODIC_TIMER */
00034 
00035 #define XNTIMER_ENABLED   0x00000001
00036 #define XNTIMER_DEQUEUED  0x00000002
00037 #define XNTIMER_KILLED    0x00000004
00038 
00039 /* These flags are available to the real-time interfaces */
00040 #define XNTIMER_SPARE0  0x01000000
00041 #define XNTIMER_SPARE1  0x02000000
00042 #define XNTIMER_SPARE2  0x04000000
00043 #define XNTIMER_SPARE3  0x08000000
00044 #define XNTIMER_SPARE4  0x10000000
00045 #define XNTIMER_SPARE5  0x20000000
00046 #define XNTIMER_SPARE6  0x40000000
00047 #define XNTIMER_SPARE7  0x80000000
00048 
00049 #define XNTIMER_LOPRIO  (-999999999)
00050 #define XNTIMER_STDPRIO 0
00051 #define XNTIMER_HIPRIO  999999999
00052 
00053 #define XNTIMER_KEEPER_ID 0
00054 
00055 struct xnsched;
00056 
00057 typedef struct xntimer {
00058 
00059     xnholder_t link;
00060 
00061 #define link2timer(laddr) \
00062 ((xntimer_t *)(((char *)laddr) - (int)(&((xntimer_t *)0)->link)))
00063 
00064     xnflags_t status;           /* !< Timer status. */
00065 
00066     xnticks_t date;             /* !< Absolute timeout date (in ticks). */
00067 
00068     xnticks_t interval;         /* !< Periodic interval (in ticks, 0 == one shot). */
00069 
00070     int prio;                   /* !< Internal priority. */
00071 
00072     struct xnsched *sched;      /* !< Sched structure to which the timer is
00073                                    attached. */
00074 
00075     void (*handler)(void *cookie); /* !< Timeout handler. */
00076 
00077     void *cookie;       /* !< Cookie to pass to the timeout handler. */
00078 
00079     XNARCH_DECL_DISPLAY_CONTEXT();
00080 
00081 } xntimer_t;
00082 
00083 #define xntimer_date(t)           ((t)->date)
00084 #if defined(CONFIG_SMP)
00085 #define xntimer_sched(t)          ((t)->sched)
00086 #else /* !CONFIG_SMP */
00087 #define xntimer_sched(t)          xnpod_current_sched()
00088 #endif /* !CONFIG_SMP */
00089 #define xntimer_interval(t)       ((t)->interval)
00090 #define xntimer_set_cookie(t,c)   ((t)->cookie = (c))
00091 #define xntimer_set_priority(t,p) ((t)->prio = (p))
00092 
00093 static inline int xntimer_active_p (xntimer_t *timer) {
00094     return timer->sched != NULL;
00095 }
00096 
00097 static inline int xntimer_running_p (xntimer_t *timer) {
00098     return !testbits(timer->status,XNTIMER_DEQUEUED);
00099 }
00100 
00101 typedef struct xntmops {
00102 
00103     void (*do_tick)(void);
00104     xnticks_t (*get_jiffies)(void);
00105     void (*do_timer_start)(xntimer_t *timer,
00106                            xnticks_t value,
00107                            xnticks_t interval);
00108     void (*do_timer_stop)(xntimer_t *timer);
00109     xnticks_t (*get_timer_date)(xntimer_t *timer);
00110     xnticks_t (*get_timer_timeout)(xntimer_t *timer);
00111     void (*set_timer_remote)(xntimer_t *timer);
00112     const char *(*get_type)(void);
00113 
00114 } xntmops_t;
00115 
00116 #ifdef __cplusplus
00117 extern "C" {
00118 #endif
00119 
00120 extern xntmops_t *nktimer;
00121 
00122 void xntimer_init(xntimer_t *timer,
00123                   void (*handler)(void *cookie),
00124                   void *cookie);
00125 
00126 void xntimer_destroy(xntimer_t *timer);
00127 
00128 void xntimer_start(xntimer_t *timer,
00129                    xnticks_t value,
00130                    xnticks_t interval);
00131 
00155 static inline void xntimer_stop(xntimer_t *timer)
00156 {
00157     if (!testbits(timer->status,XNTIMER_DEQUEUED))
00158         nktimer->do_timer_stop(timer);
00159 }
00160 
00161 void xntimer_freeze(void);
00162 
00163 xnticks_t xntimer_get_date(xntimer_t *timer);
00164 
00165 xnticks_t xntimer_get_timeout(xntimer_t *timer);
00166 
00167 void xntimer_set_periodic_mode(void);
00168 
00169 void xntimer_set_aperiodic_mode(void);
00170 
00171 #if defined(CONFIG_SMP)
00172 int xntimer_set_sched(xntimer_t *timer, struct xnsched *sched);
00173 #else /* ! CONFIG_SMP */
00174 #define xntimer_set_sched(timer,sched)
00175 #endif /* CONFIG_SMP */
00176 
00177 #ifdef __cplusplus
00178 }
00179 #endif
00180 
00181 #endif /* __KERNEL__ || __RTAI_UVM__ || __RTAI_SIM__ */
00182 
00183 #endif /* !_RTAI_NUCLEUS_TIMER_H */

Generated on Sat Sep 3 12:32:47 2005 for RTAI Fusion API by  doxygen 1.4.2