]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/src/select.c
The first enhanced version of Linux CAN-bus driver for OCERA project
[lincan.git] / lincan / src / select.c
diff --git a/lincan/src/select.c b/lincan/src/select.c
new file mode 100644 (file)
index 0000000..27b2d22
--- /dev/null
@@ -0,0 +1,56 @@
+/* select.c
+ * Header file for the Linux CAN-bus driver.
+ * Written by Arnaud Westenberg email:arnaud@wanadoo.nl
+ * This software is released under the GPL-License.
+ * Version 0.7.1-pi2  15 Nov 2002
+ * 
+ * added by Pavel Pisa pisa@cmp.felk.cvut.cz
+ */
+
+#include <linux/autoconf.h>
+#if defined (CONFIG_MODVERSIONS) && !defined (MODVERSIONS)
+#define MODVERSIONS
+#endif
+
+#if defined (MODVERSIONS)
+#include <linux/modversions.h>
+#endif
+
+#include <linux/version.h>
+#include <linux/poll.h>
+
+#include "../include/main.h"
+#include "../include/select.h"
+
+unsigned int can_poll(struct file *file, poll_table *wait)
+{
+        unsigned int mask = 0;
+       struct msgobj_t *obj;
+       struct canfifo_t *fifo;
+
+       /* Initialize hardware pointers */
+       if ( (obj = objects_p[MINOR_NR]) == NULL) {
+               CANMSG("Could not assign buffer structure\n");
+               return 0;
+       }
+       if ( (fifo = obj->fifo) == NULL) {
+               CANMSG("Could not assign buffer memory.\n");
+               return 0;
+       }
+
+        if (file->f_mode & FMODE_WRITE) {
+                poll_wait(file, &fifo->writeq, wait);
+        }
+        if (file->f_mode & FMODE_READ) {
+                poll_wait(file, &fifo->readq, wait);
+        }
+        if ((file->f_mode & FMODE_READ)&&
+           (fifo->rx_readp != fifo->rx_writep)) {
+                 mask |= POLLIN | POLLRDNORM;
+        }
+        if ((file->f_mode & FMODE_WRITE)&&
+           (fifo->tx_readp == fifo->tx_writep)) {
+                 mask |= POLLOUT | POLLWRNORM;
+       }
+       return mask;
+}