]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/src/select.c
27b2d22c0f433cfd790c6b0fdb809952ab1f1a65
[lincan.git] / lincan / src / select.c
1 /* select.c
2  * Header file for the Linux CAN-bus driver.
3  * Written by Arnaud Westenberg email:arnaud@wanadoo.nl
4  * This software is released under the GPL-License.
5  * Version 0.7.1-pi2  15 Nov 2002
6  * 
7  * added by Pavel Pisa pisa@cmp.felk.cvut.cz
8  */
9
10 #include <linux/autoconf.h>
11 #if defined (CONFIG_MODVERSIONS) && !defined (MODVERSIONS)
12 #define MODVERSIONS
13 #endif
14
15 #if defined (MODVERSIONS)
16 #include <linux/modversions.h>
17 #endif
18
19 #include <linux/version.h>
20 #include <linux/poll.h>
21
22 #include "../include/main.h"
23 #include "../include/select.h"
24
25 unsigned int can_poll(struct file *file, poll_table *wait)
26 {
27         unsigned int mask = 0;
28         struct msgobj_t *obj;
29         struct canfifo_t *fifo;
30
31         /* Initialize hardware pointers */
32         if ( (obj = objects_p[MINOR_NR]) == NULL) {
33                 CANMSG("Could not assign buffer structure\n");
34                 return 0;
35         }
36         if ( (fifo = obj->fifo) == NULL) {
37                 CANMSG("Could not assign buffer memory.\n");
38                 return 0;
39         }
40
41         if (file->f_mode & FMODE_WRITE) {
42                 poll_wait(file, &fifo->writeq, wait);
43         }
44         if (file->f_mode & FMODE_READ) {
45                 poll_wait(file, &fifo->readq, wait);
46         }
47         if ((file->f_mode & FMODE_READ)&&
48             (fifo->rx_readp != fifo->rx_writep)) {
49                  mask |= POLLIN | POLLRDNORM;
50         }
51         if ((file->f_mode & FMODE_WRITE)&&
52             (fifo->tx_readp == fifo->tx_writep)) {
53                  mask |= POLLOUT | POLLWRNORM;
54         }
55         return mask;
56 }