00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00029 #define XNTIMER_WHEELSIZE 64
00030 #define XNTIMER_WHEELMASK (XNTIMER_WHEELSIZE - 1)
00031 #else
00032 #define XNTIMER_WHEELSIZE 1
00033 #endif
00034
00035 #define XNTIMER_ENABLED 0x00000001
00036 #define XNTIMER_DEQUEUED 0x00000002
00037 #define XNTIMER_KILLED 0x00000004
00038
00039
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;
00065
00066 xnticks_t date;
00067
00068 xnticks_t interval;
00069
00070 int prio;
00071
00072 struct xnsched *sched;
00073
00074
00075 void (*handler)(void *cookie);
00076
00077 void *cookie;
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
00087 #define xntimer_sched(t) xnpod_current_sched()
00088 #endif
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
00174 #define xntimer_set_sched(timer,sched)
00175 #endif
00176
00177 #ifdef __cplusplus
00178 }
00179 #endif
00180
00181 #endif
00182
00183 #endif