]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/staging/comedi/comedi_rt.h
Staging: comedi: fix up a lot of checkpatch.pl warnings
[linux-2.6-omap-h63xx.git] / drivers / staging / comedi / comedi_rt.h
1 /*
2     module/comedi_rt.h
3     header file for real-time structures, variables, and constants
4
5     COMEDI - Linux Control and Measurement Device Interface
6     Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
7
8     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation; either version 2 of the License, or
11     (at your option) any later version.
12
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17
18     You should have received a copy of the GNU General Public License
19     along with this program; if not, write to the Free Software
20     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 */
23
24 #ifndef _COMEDI_RT_H
25 #define _COMEDI_RT_H
26
27 #ifndef _COMEDIDEV_H
28 #error comedi_rt.h should only be included by comedidev.h
29 #endif
30
31 #include <linux/version.h>
32 #include <linux/kdev_t.h>
33 #include <linux/slab.h>
34 #include <linux/errno.h>
35 #include <linux/spinlock.h>
36 #include <linux/delay.h>
37
38 #ifdef CONFIG_COMEDI_RT
39
40 #ifdef CONFIG_COMEDI_RTAI
41 #include <rtai.h>
42 #include <rtai_sched.h>
43 #include <rtai_version.h>
44 #endif
45 #ifdef CONFIG_COMEDI_RTL
46 #include <rtl_core.h>
47 #include <rtl_time.h>
48 /* #ifdef RTLINUX_VERSION_CODE */
49 #include <rtl_sync.h>
50 /* #endif */
51 #define rt_printk rtl_printf
52 #endif
53 #ifdef CONFIG_COMEDI_FUSION
54 #define rt_printk(format, args...) printk(format , ## args)
55 #endif /* CONFIG_COMEDI_FUSION */
56 #ifdef CONFIG_PRIORITY_IRQ
57 #define rt_printk printk
58 #endif
59
60 int comedi_request_irq(unsigned int irq, irqreturn_t(*handler) (int,
61                 void *PT_REGS_ARG), unsigned long flags, const char *device,
62                 comedi_device *dev_id);
63 void comedi_free_irq(unsigned int irq, comedi_device *dev_id);
64 void comedi_rt_init(void);
65 void comedi_rt_cleanup(void);
66 int comedi_switch_to_rt(comedi_device *dev);
67 void comedi_switch_to_non_rt(comedi_device *dev);
68 void comedi_rt_pend_wakeup(wait_queue_head_t *q);
69 extern int rt_pend_call(void (*func) (int arg1, void *arg2), int arg1,
70         void *arg2);
71
72 #else
73
74 #define comedi_request_irq(a, b, c, d, e) request_irq(a, b, c, d, e)
75 #define comedi_free_irq(a, b) free_irq(a, b)
76 #define comedi_rt_init() do {} while (0)
77 #define comedi_rt_cleanup() do {} while (0)
78 #define comedi_switch_to_rt(a) (-1)
79 #define comedi_switch_to_non_rt(a) do {} while (0)
80 #define comedi_rt_pend_wakeup(a) do {} while (0)
81
82 #define rt_printk(format, args...)      printk(format, ##args)
83
84 #endif
85
86 /* Define a spin_lock_irqsave function that will work with rt or without.
87  * Use inline functions instead of just macros to enforce some type checking.
88  */
89 #define comedi_spin_lock_irqsave(lock_ptr, flags) \
90         (flags = __comedi_spin_lock_irqsave(lock_ptr))
91
92 static inline unsigned long __comedi_spin_lock_irqsave(spinlock_t *lock_ptr)
93 {
94         unsigned long flags;
95
96 #if defined(CONFIG_COMEDI_RTAI)
97         flags = rt_spin_lock_irqsave(lock_ptr);
98
99 #elif defined(CONFIG_COMEDI_RTL)
100         rtl_spin_lock_irqsave(lock_ptr, flags);
101
102 #elif defined(CONFIG_COMEDI_RTL_V1)
103         rtl_spin_lock_irqsave(lock_ptr, flags);
104
105 #elif defined(CONFIG_COMEDI_FUSION)
106         rthal_spin_lock_irqsave(lock_ptr, flags);
107 #else
108         spin_lock_irqsave(lock_ptr, flags);
109
110 #endif
111
112         return flags;
113 }
114
115 static inline void comedi_spin_unlock_irqrestore(spinlock_t *lock_ptr,
116         unsigned long flags)
117 {
118
119 #if defined(CONFIG_COMEDI_RTAI)
120         rt_spin_unlock_irqrestore(flags, lock_ptr);
121
122 #elif defined(CONFIG_COMEDI_RTL)
123         rtl_spin_unlock_irqrestore(lock_ptr, flags);
124
125 #elif defined(CONFIG_COMEDI_RTL_V1)
126         rtl_spin_unlock_irqrestore(lock_ptr, flags);
127 #elif defined(CONFIG_COMEDI_FUSION)
128         rthal_spin_unlock_irqrestore(lock_ptr, flags);
129 #else
130         spin_unlock_irqrestore(lock_ptr, flags);
131
132 #endif
133
134 }
135
136 /* define a RT safe udelay */
137 static inline void comedi_udelay(unsigned int usec)
138 {
139 #if defined(CONFIG_COMEDI_RTAI)
140         static const int nanosec_per_usec = 1000;
141         rt_busy_sleep(usec * nanosec_per_usec);
142 #elif defined(CONFIG_COMEDI_RTL)
143         static const int nanosec_per_usec = 1000;
144         rtl_delay(usec * nanosec_per_usec);
145 #else
146         udelay(usec);
147 #endif
148 }
149
150 #endif