]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/src/read.c
The first enhanced version of Linux CAN-bus driver for OCERA project
[lincan.git] / lincan / src / read.c
index 4e02801e31e8eac3c6eb61ce0c8fa68b90235ab9..111140103bbe7ab6da6fc1c7f8176440edc318dc 100644 (file)
@@ -5,6 +5,9 @@
  * Version 0.7  6 Aug 2001
  */
 
  * Version 0.7  6 Aug 2001
  */
 
+#define __NO_VERSION__
+#include <linux/module.h> 
+
 #include <linux/autoconf.h>
 #if defined (CONFIG_MODVERSIONS) && !defined (MODVERSIONS)
 #define MODVERSIONS
 #include <linux/autoconf.h>
 #if defined (CONFIG_MODVERSIONS) && !defined (MODVERSIONS)
 #define MODVERSIONS
 #include <linux/modversions.h>
 #endif
 
 #include <linux/modversions.h>
 #endif
 
+#include <linux/version.h>
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
 #include <linux/malloc.h>
 #include <linux/malloc.h>
+#else
+#include <linux/slab.h>
+#endif
 #include <linux/version.h>
 #include <asm/uaccess.h>
 #include <asm/irq.h>
 #include <linux/version.h>
 #include <asm/uaccess.h>
 #include <asm/irq.h>
@@ -45,8 +53,8 @@ inline ssize_t can_std_read(struct file *file, struct canfifo_t *fifo,
                        return -EINTR;
                }
                if (!can_timeout) {
                        return -EINTR;
                }
                if (!can_timeout) {
-                       DEBUGMSG("Rx timeout\n");
-                       return -EIO;
+                       DEBUGMSG("no data received\n");
+                       return 0;
                }
                if (obj->ret < 0)
                        return obj->ret;
                }
                if (obj->ret < 0)
                        return obj->ret;
@@ -62,14 +70,24 @@ inline ssize_t can_std_read(struct file *file, struct canfifo_t *fifo,
        bytes_to_copy = (length < bytes_avail) ? length : bytes_avail;
        ret = bytes_to_copy;
 
        bytes_to_copy = (length < bytes_avail) ? length : bytes_avail;
        ret = bytes_to_copy;
 
+       /* printk(KERN_CRIT "can RxFIFO b:%x e:%x bs:%x msg:%x rp:%x wp:%x btc:%x\n",
+              fifo->buf_rx_entry, fifo->buf_rx_entry+MAX_BUF_LENGTH,
+              fifo->rx_size, sizeof(struct canmsg_t),
+              fifo->rx_readp, fifo->rx_writep, bytes_to_copy); */
+
+
        /* Copy the data to user space */
        while (bytes_to_copy > 0) {
        /* Copy the data to user space */
        while (bytes_to_copy > 0) {
+                      
+               
                copy_to_user(buffer, fifo->rx_readp, sizeof(struct canmsg_t));
                buffer += sizeof(struct canmsg_t);
                bytes_to_copy -= sizeof(struct canmsg_t);
                fifo->rx_readp++;
                if (fifo->rx_readp >= fifo->buf_rx_entry + MAX_BUF_LENGTH)
                        fifo->rx_readp = fifo->buf_rx_entry;
                copy_to_user(buffer, fifo->rx_readp, sizeof(struct canmsg_t));
                buffer += sizeof(struct canmsg_t);
                bytes_to_copy -= sizeof(struct canmsg_t);
                fifo->rx_readp++;
                if (fifo->rx_readp >= fifo->buf_rx_entry + MAX_BUF_LENGTH)
                        fifo->rx_readp = fifo->buf_rx_entry;
+
+               /* printk(KERN_CRIT "can RxFIFO rp%x\n",fifo->rx_readp); */
        }
 
        return ret;
        }
 
        return ret;
@@ -101,7 +119,7 @@ inline ssize_t can_rtr_read(struct chip_t *chip, struct msgobj_t *obj,
                new_rtr_entry=(struct rtr_id *)kmalloc(sizeof(struct rtr_id),GFP_ATOMIC);
                rtr_current->next=new_rtr_entry;
        }
                new_rtr_entry=(struct rtr_id *)kmalloc(sizeof(struct rtr_id),GFP_ATOMIC);
                rtr_current->next=new_rtr_entry;
        }
-#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,2,19))
+#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,0))
        init_waitqueue(&new_rtr_entry->rtr_wq);
 #else
        init_waitqueue_head(&new_rtr_entry->rtr_wq);
        init_waitqueue(&new_rtr_entry->rtr_wq);
 #else
        init_waitqueue_head(&new_rtr_entry->rtr_wq);