3 header file for real-time structures, variables, and constants
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
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.
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.
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.
28 #error comedi_rt.h should only be included by comedidev.h
31 #include <linux/kdev_t.h>
32 #include <linux/slab.h>
33 #include <linux/errno.h>
34 #include <linux/spinlock.h>
35 #include <linux/delay.h>
37 #ifdef CONFIG_COMEDI_RT
39 #ifdef CONFIG_COMEDI_RTAI
41 #include <rtai_sched.h>
42 #include <rtai_version.h>
44 #ifdef CONFIG_COMEDI_RTL
47 /* #ifdef RTLINUX_VERSION_CODE */
50 #define rt_printk rtl_printf
52 #ifdef CONFIG_COMEDI_FUSION
53 #define rt_printk(format, args...) printk(format , ## args)
54 #endif /* CONFIG_COMEDI_FUSION */
55 #ifdef CONFIG_PRIORITY_IRQ
56 #define rt_printk printk
59 int comedi_request_irq(unsigned int irq, irqreturn_t(*handler) (int,
60 void *PT_REGS_ARG), unsigned long flags, const char *device,
61 struct comedi_device *dev_id);
62 void comedi_free_irq(unsigned int irq, struct comedi_device *dev_id);
63 void comedi_rt_init(void);
64 void comedi_rt_cleanup(void);
65 int comedi_switch_to_rt(struct comedi_device *dev);
66 void comedi_switch_to_non_rt(struct comedi_device *dev);
67 void comedi_rt_pend_wakeup(wait_queue_head_t *q);
68 extern int rt_pend_call(void (*func) (int arg1, void *arg2), int arg1,
73 #define comedi_request_irq(a, b, c, d, e) request_irq(a, b, c, d, e)
74 #define comedi_free_irq(a, b) free_irq(a, b)
75 #define comedi_rt_init() do {} while (0)
76 #define comedi_rt_cleanup() do {} while (0)
77 #define comedi_switch_to_rt(a) (-1)
78 #define comedi_switch_to_non_rt(a) do {} while (0)
79 #define comedi_rt_pend_wakeup(a) do {} while (0)
81 #define rt_printk(format, args...) printk(format, ##args)
85 /* Define a spin_lock_irqsave function that will work with rt or without.
86 * Use inline functions instead of just macros to enforce some type checking.
88 #define comedi_spin_lock_irqsave(lock_ptr, flags) \
89 (flags = __comedi_spin_lock_irqsave(lock_ptr))
91 static inline unsigned long __comedi_spin_lock_irqsave(spinlock_t *lock_ptr)
95 #if defined(CONFIG_COMEDI_RTAI)
96 flags = rt_spin_lock_irqsave(lock_ptr);
98 #elif defined(CONFIG_COMEDI_RTL)
99 rtl_spin_lock_irqsave(lock_ptr, flags);
101 #elif defined(CONFIG_COMEDI_RTL_V1)
102 rtl_spin_lock_irqsave(lock_ptr, flags);
104 #elif defined(CONFIG_COMEDI_FUSION)
105 rthal_spin_lock_irqsave(lock_ptr, flags);
107 spin_lock_irqsave(lock_ptr, flags);
114 static inline void comedi_spin_unlock_irqrestore(spinlock_t *lock_ptr,
118 #if defined(CONFIG_COMEDI_RTAI)
119 rt_spin_unlock_irqrestore(flags, lock_ptr);
121 #elif defined(CONFIG_COMEDI_RTL)
122 rtl_spin_unlock_irqrestore(lock_ptr, flags);
124 #elif defined(CONFIG_COMEDI_RTL_V1)
125 rtl_spin_unlock_irqrestore(lock_ptr, flags);
126 #elif defined(CONFIG_COMEDI_FUSION)
127 rthal_spin_unlock_irqrestore(lock_ptr, flags);
129 spin_unlock_irqrestore(lock_ptr, flags);
135 /* define a RT safe udelay */
136 static inline void comedi_udelay(unsigned int usec)
138 #if defined(CONFIG_COMEDI_RTAI)
139 static const int nanosec_per_usec = 1000;
140 rt_busy_sleep(usec * nanosec_per_usec);
141 #elif defined(CONFIG_COMEDI_RTL)
142 static const int nanosec_per_usec = 1000;
143 rtl_delay(usec * nanosec_per_usec);