]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/src/select.c
Actual driver code for directly mapped SJA1000 into PCI mem region 0.
[lincan.git] / lincan / src / select.c
1 /**************************************************************************/
2 /* File: select.c - systemcall to wait for new messages and free Tx slots */
3 /*                                                                        */
4 /* LinCAN - (Not only) Linux CAN bus driver                               */
5 /* Copyright (C) 2002-2009 DCE FEE CTU Prague <http://dce.felk.cvut.cz>   */
6 /* Copyright (C) 2002-2009 Pavel Pisa <pisa@cmp.felk.cvut.cz>             */
7 /* Funded by OCERA and FRESCOR IST projects                               */
8 /* Based on CAN driver code by Arnaud Westenberg <arnaud@wanadoo.nl>      */
9 /*                                                                        */
10 /* LinCAN is free software; you can redistribute it and/or modify it      */
11 /* under terms of the GNU General Public License as published by the      */
12 /* Free Software Foundation; either version 2, or (at your option) any    */
13 /* later version.  LinCAN is distributed in the hope that it will be      */
14 /* useful, but WITHOUT ANY WARRANTY; without even the implied warranty    */
15 /* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU    */
16 /* General Public License for more details. You should have received a    */
17 /* copy of the GNU General Public License along with LinCAN; see file     */
18 /* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,  */
19 /* Cambridge, MA 02139, USA.                                              */
20 /*                                                                        */
21 /* To allow use of LinCAN in the compact embedded systems firmware        */
22 /* and RT-executives (RTEMS for example), main authors agree with next    */
23 /* special exception:                                                     */
24 /*                                                                        */
25 /* Including LinCAN header files in a file, instantiating LinCAN generics */
26 /* or templates, or linking other files with LinCAN objects to produce    */
27 /* an application image/executable, does not by itself cause the          */
28 /* resulting application image/executable to be covered by                */
29 /* the GNU General Public License.                                        */
30 /* This exception does not however invalidate any other reasons           */
31 /* why the executable file might be covered by the GNU Public License.    */
32 /* Publication of enhanced or derived LinCAN files is required although.  */
33 /**************************************************************************/
34
35 #include "../include/can.h"
36 #include "../include/can_sysdep.h"
37 #include "../include/main.h"
38
39 #include <linux/poll.h>
40 #include "../include/select.h"
41
42 unsigned int can_poll(struct file *file, poll_table *wait)
43 {
44         struct canuser_t *canuser = (struct canuser_t*)(file->private_data);
45         struct canque_ends_t *qends;
46         struct msgobj_t *obj;
47         unsigned int mask = 0;
48         struct canque_edge_t *edge;
49         int full=0;
50         int i;
51
52         if(!canuser || (canuser->magic != CAN_USER_MAGIC)){
53                 CANMSG("can_close: bad canuser magic\n");
54                 return -ENODEV;
55         }
56
57         obj = canuser->msgobj;
58         qends = canuser->qends;
59
60         if (file->f_mode & FMODE_READ) {
61                 poll_wait(file, &qends->endinfo.fileinfo.readq, wait);
62                 for(i=CANQUEUE_PRIO_NR;--i>=0;) {
63                         if(!list_empty(&qends->active[i]))
64                                 mask |= POLLIN | POLLRDNORM;
65                 }
66         }
67
68         if ((file->f_mode & FMODE_WRITE) && !(file->f_flags & O_SYNC)) {
69                 poll_wait(file, &qends->endinfo.fileinfo.writeq, wait);
70
71                 canque_for_each_inedge(qends, edge) {
72                         if(canque_fifo_test_fl(&edge->fifo,FULL))
73                                 full=1;
74                 }
75
76                 if(!full)
77                         mask |= POLLOUT | POLLWRNORM;
78         }
79
80         if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_SYNC)) {
81                 poll_wait(file, &qends->endinfo.fileinfo.emptyq, wait);
82
83                 canque_for_each_inedge(qends, edge) {
84                         if(!canque_fifo_test_fl(&edge->fifo,EMPTY))
85                                 full=1;
86                 }
87
88                 if(!full)
89                         mask |= POLLOUT | POLLWRNORM;
90         }
91         return mask;
92 }