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/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>
38 #ifdef CONFIG_COMEDI_RT
40 #ifdef CONFIG_COMEDI_RTAI
42 #include <rtai_sched.h>
43 #include <rtai_version.h>
45 #ifdef CONFIG_COMEDI_RTL
48 /* #ifdef RTLINUX_VERSION_CODE */
51 #define rt_printk rtl_printf
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
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,
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)
82 #define rt_printk(format, args...) printk(format, ##args)
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.
89 #define comedi_spin_lock_irqsave(lock_ptr, flags) \
90 (flags = __comedi_spin_lock_irqsave(lock_ptr))
92 static inline unsigned long __comedi_spin_lock_irqsave(spinlock_t *lock_ptr)
96 #if defined(CONFIG_COMEDI_RTAI)
97 flags = rt_spin_lock_irqsave(lock_ptr);
99 #elif defined(CONFIG_COMEDI_RTL)
100 rtl_spin_lock_irqsave(lock_ptr, flags);
102 #elif defined(CONFIG_COMEDI_RTL_V1)
103 rtl_spin_lock_irqsave(lock_ptr, flags);
105 #elif defined(CONFIG_COMEDI_FUSION)
106 rthal_spin_lock_irqsave(lock_ptr, flags);
108 spin_lock_irqsave(lock_ptr, flags);
115 static inline void comedi_spin_unlock_irqrestore(spinlock_t *lock_ptr,
119 #if defined(CONFIG_COMEDI_RTAI)
120 rt_spin_unlock_irqrestore(flags, lock_ptr);
122 #elif defined(CONFIG_COMEDI_RTL)
123 rtl_spin_unlock_irqrestore(lock_ptr, flags);
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);
130 spin_unlock_irqrestore(lock_ptr, flags);
136 /* define a RT safe udelay */
137 static inline void comedi_udelay(unsigned int usec)
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);