rtai-core/include/xenomai/dbridge.h

00001 /*
00002  * Copyright (C) 2001,2002,2003 Philippe Gerum.
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
00007  * USA; either version 2 of the License, or (at your option) any later
00008  * version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018  */
00019 
00020 #ifndef _xenomai_dbridge_h
00021 #define _xenomai_dbridge_h
00022 
00023 #undef DBRIDGE_DEBUG
00024 
00025 #define DBRIDGE_WAIT   0x0
00026 #define DBRIDGE_NOWAIT 0x1
00027 
00028 #define DBRIDGE_NORMAL 0x0
00029 #define DBRIDGE_URGENT 0x1
00030 
00031 #define DBRIDGE_RTK_CONN   0x1
00032 #define DBRIDGE_USR_CONN   0x2
00033 #define DBRIDGE_USR_WOPEN  0x4
00034 #define DBRIDGE_USR_WSEND  0x8
00035 #define DBRIDGE_USR_WPOLL  0x10
00036 #define DBRIDGE_USR_SIGIO  0x20
00037 #define DBRIDGE_USR_ONWAIT 0x40
00038 
00039 #define DBRIDGE_USR_WMASK \
00040 (DBRIDGE_USR_WOPEN|DBRIDGE_USR_WSEND|DBRIDGE_USR_WPOLL)
00041 
00042 #define DBRIDGE_MQ_NDEVS     8  /* message channels */
00043 #define DBRIDGE_EV_NDEVS     8  /* event flags */
00044 #define DBRIDGE_NDEVS        (DBRIDGE_MQ_NDEVS + DBRIDGE_EV_NDEVS + 1)
00045 #define DBRIDGE_MAJOR        150
00046 
00047 #define XIOCURTMODE  0xfbfb
00048 
00049 #ifdef __KERNEL__
00050 
00051 #include <xenomai/queue.h>
00052 #include <xenomai/synch.h>
00053 #include <xenomai/thread.h>
00054 #include <linux/types.h>
00055 #include <linux/poll.h>
00056 
00057 typedef struct dbridge_mh {
00058 
00059     xnholder_t link;
00060 #define link2mh(laddr) \
00061 (laddr ? ((dbridge_mh_t *)(((char *)laddr) - (int)(&((dbridge_mh_t *)0)->link))) : 0)
00062     unsigned size;
00063     
00064 } dbridge_mh_t;
00065 
00066 typedef int dbridge_io_handler(int minor,
00067                                struct dbridge_mh *mh,
00068                                int onerror,
00069                                void *cookie);
00070 
00071 typedef int dbridge_session_handler(int minor,
00072                                     void *cookie);
00073 
00074 typedef void *dbridge_alloc_handler(int minor,
00075                                     size_t size,
00076                                     void *cookie);
00077 struct _dbridge_state;
00078 
00079 typedef struct _dbridge_ops {
00080 
00081     int (*open)(struct _dbridge_state *state,
00082                 struct inode *inode,
00083                 struct file *file);
00084 
00085     int (*close)(struct _dbridge_state *state,
00086                  struct inode *inode,
00087                  struct file *file);
00088 
00089     ssize_t (*read)(struct _dbridge_state *state,
00090                     struct file *file,
00091                     char *buf,
00092                     size_t count,
00093                     loff_t *ppos);
00094 
00095     ssize_t (*write)(struct _dbridge_state *state,
00096                      struct file *file,
00097                      const char *buf,
00098                      size_t count,
00099                      loff_t *ppos);
00100 
00101     int (*ioctl)(struct _dbridge_state *state,
00102                  struct inode *inode,
00103                  struct file *file,
00104                  unsigned cmd,
00105                  unsigned long arg);
00106 
00107     int (*fasync)(struct _dbridge_state *state,
00108                   int fd,
00109                   struct file *file,
00110                   int on);
00111 
00112     unsigned (*poll)(struct _dbridge_state *state,
00113                      struct file *file,
00114                      poll_table *pt);
00115 } dbridge_ops_t;
00116 
00117 typedef struct _dbridge_state {
00118 
00119     dbridge_ops_t *ops;
00120     xnholder_t slink;   /* Link on sleep queue */
00121     xnholder_t alink;   /* Link on async queue */
00122 #define link2dbs(laddr,link) \
00123 ((struct _dbridge_state *)(((char *)laddr) - (int)(&((struct _dbridge_state *)0)->link)))
00124 
00125     union {
00126         struct {
00127             xnqueue_t inq;      /* From user-space to kernel */
00128             xnqueue_t outq;     /* From kernel to user-space */
00129             dbridge_io_handler *o_handler;
00130             dbridge_io_handler *i_handler;
00131             dbridge_alloc_handler *alloc_handler;
00132             xnsynch_t synchbase;
00133             void *cookie;
00134         } mq;
00135 
00136         struct {
00137             unsigned long events;
00138             xnsynch_t synchbase;
00139         } ev;
00140     } u;
00141 
00142     /* Linux kernel part */
00143     int status;
00144     struct semaphore open_sem;
00145     struct semaphore send_sem;
00146     struct semaphore event_sem;
00147     struct semaphore *wchan;    /* any sem */
00148     struct fasync_struct *asyncq;
00149     wait_queue_head_t pollq;
00150 
00151 } dbridge_state_t;
00152 
00153 extern dbridge_state_t dbridge_states[];
00154 
00155 #define minor_from_state(s) (s - dbridge_states)
00156 
00157 static inline void dbridge_schedule_request (void) {
00158     extern unsigned dbridge_wakeup_srq;
00159     rt_pend_linux_srq(dbridge_wakeup_srq);
00160 }
00161 
00162 #ifdef __cplusplus
00163 extern "C" {
00164 #endif
00165 
00166 void dbridge_enqueue_wait(dbridge_state_t *state,
00167                           struct semaphore *wchan,
00168                           int flags);
00169 
00170 void dbridge_dequeue_wait(dbridge_state_t *state,
00171                           int flags);
00172 
00173 /* Entry points of the kernel interface. */
00174 
00175 void dbridge_msetup(dbridge_session_handler *open_handler,
00176                     dbridge_session_handler *close_handler);
00177 
00178 int dbridge_mconnect(int minor,
00179                      dbridge_io_handler *o_handler,
00180                      dbridge_io_handler *i_handler,
00181                      dbridge_alloc_handler *alloc_handler,
00182                      void *cookie);
00183 
00184 int dbridge_mdisconnect(int minor);
00185 
00186 ssize_t dbridge_msend(int minor,
00187                       struct dbridge_mh *mh,
00188                       size_t size,
00189                       int flags);
00190 
00191 ssize_t dbridge_mrecv(int minor,
00192                       struct dbridge_mh **pmh,
00193                       xntime_t timeout);
00194 
00195 int dbridge_minquire(int minor);
00196 
00197 #ifdef __cplusplus
00198 }
00199 #endif
00200 
00201 static inline xnholder_t *dbridge_m_link(dbridge_mh_t *mh) {
00202     return &mh->link;
00203 }
00204 
00205 #else  /* !__KERNEL__ */
00206 
00207 typedef struct dbridge_mh {
00208 
00209     char __opaque[8];
00210     unsigned size;
00211 
00212 } dbridge_mh_t;
00213 
00214 #endif /* __KERNEL__ */
00215 
00216 static inline char *dbridge_m_data(dbridge_mh_t *mh) {
00217     return (char *)(mh + 1);
00218 }
00219 
00220 #define dbridge_m_size(mh) ((mh)->size)
00221 
00222 #endif /* !_xenomai_dbridge_h */

Generated on Sat Jul 24 19:36:04 2004 for RTAI API by doxygen 1.3.4