-/* 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>
+/**************************************************************************/
+/* File: select.c - systemcall to wait for new messages and free Tx slots */
+/* */
+/* LinCAN - (Not only) Linux CAN bus driver */
+/* Copyright (C) 2002-2009 DCE FEE CTU Prague <http://dce.felk.cvut.cz> */
+/* Copyright (C) 2002-2009 Pavel Pisa <pisa@cmp.felk.cvut.cz> */
+/* Funded by OCERA and FRESCOR IST projects */
+/* Based on CAN driver code by Arnaud Westenberg <arnaud@wanadoo.nl> */
+/* */
+/* LinCAN is free software; you can redistribute it and/or modify it */
+/* under terms of the GNU General Public License as published by the */
+/* Free Software Foundation; either version 2, or (at your option) any */
+/* later version. LinCAN is distributed in the hope that it will be */
+/* useful, but WITHOUT ANY WARRANTY; without even the implied warranty */
+/* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
+/* General Public License for more details. You should have received a */
+/* copy of the GNU General Public License along with LinCAN; see file */
+/* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, */
+/* Cambridge, MA 02139, USA. */
+/* */
+/* To allow use of LinCAN in the compact embedded systems firmware */
+/* and RT-executives (RTEMS for example), main authors agree with next */
+/* special exception: */
+/* */
+/* Including LinCAN header files in a file, instantiating LinCAN generics */
+/* or templates, or linking other files with LinCAN objects to produce */
+/* an application image/executable, does not by itself cause the */
+/* resulting application image/executable to be covered by */
+/* the GNU General Public License. */
+/* This exception does not however invalidate any other reasons */
+/* why the executable file might be covered by the GNU Public License. */
+/* Publication of enhanced or derived LinCAN files is required although. */
+/**************************************************************************/
+#include "../include/can.h"
+#include "../include/can_sysdep.h"
#include "../include/main.h"
+
+#include <linux/poll.h>
#include "../include/select.h"
unsigned int can_poll(struct file *file, poll_table *wait)
{
- unsigned int mask = 0;
+ struct canuser_t *canuser = (struct canuser_t*)(file->private_data);
+ struct canque_ends_t *qends;
struct msgobj_t *obj;
- struct canfifo_t *fifo;
+ unsigned int mask = 0;
+ struct canque_edge_t *edge;
+ int full=0;
+ int i;
- /* 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(!canuser || (canuser->magic != CAN_USER_MAGIC)){
+ CANMSG("can_close: bad canuser magic\n");
+ return -ENODEV;
}
- if (file->f_mode & FMODE_WRITE) {
- poll_wait(file, &fifo->writeq, wait);
- }
+ obj = canuser->msgobj;
+ qends = canuser->qends;
+
if (file->f_mode & FMODE_READ) {
- poll_wait(file, &fifo->readq, wait);
+ poll_wait(file, &qends->endinfo.fileinfo.readq, wait);
+ for(i=CANQUEUE_PRIO_NR;--i>=0;) {
+ if(!list_empty(&qends->active[i]))
+ mask |= POLLIN | POLLRDNORM;
+ }
}
- 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;
+
+ if ((file->f_mode & FMODE_WRITE) && !(file->f_flags & O_SYNC)) {
+ poll_wait(file, &qends->endinfo.fileinfo.writeq, wait);
+
+ canque_for_each_inedge(qends, edge) {
+ if(canque_fifo_test_fl(&edge->fifo,FULL))
+ full=1;
+ }
+
+ if(!full)
+ mask |= POLLOUT | POLLWRNORM;
+ }
+
+ if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_SYNC)) {
+ poll_wait(file, &qends->endinfo.fileinfo.emptyq, wait);
+
+ canque_for_each_inedge(qends, edge) {
+ if(!canque_fifo_test_fl(&edge->fifo,EMPTY))
+ full=1;
+ }
+
+ if(!full)
+ mask |= POLLOUT | POLLWRNORM;
}
return mask;
}