2 * Linux CAN-bus device driver.
3 * Written by Arnaud Westenberg email:arnaud@wanadoo.nl
4 * Rewritten for new CAN queues by Pavel Pisa - OCERA team member
5 * email:pisa@cmp.felk.cvut.cz
6 * This software is released under the GPL-License.
7 * Version lincan-0.3 17 Jun 2004
12 #include "../include/can.h"
13 #include "../include/can_sysdep.h"
14 #include "../include/main.h"
16 #include <rtl_posixio.h>
17 #include "../include/can_iortl.h"
19 /* This is the 'Normal' read handler for normal transmission messages */
21 ssize_t can_std_read_rtl(struct canque_ends_t *qends, int nonblock_fl,
22 char *buffer, size_t length)
25 struct canmsg_t *msg_buff = (struct canmsg_t *)buffer;
27 struct canque_edge_t *qedge;
28 struct canque_slot_t *slot;
30 ret=canque_test_outslot(qends, &qedge, &slot);
35 ret=canque_get_outslot_wait_rtl(qends, &qedge, &slot);
38 DEBUGMSG("Rx interrupted\n");
45 *(msg_buff++)=slot->msg;
46 canque_free_outslot(qends, qedge, slot);
47 bytes_to_copy = length-sizeof(struct canmsg_t);
49 while (bytes_to_copy > 0) {
50 ret=canque_test_outslot(qends, &qedge, &slot);
53 *(msg_buff++)=slot->msg;
54 canque_free_outslot(qends, qedge, slot);
55 bytes_to_copy -= sizeof(struct canmsg_t);
58 return length-bytes_to_copy;
62 ssize_t can_read_rtl_posix(struct rtl_file *fptr, char *buffer,
63 size_t length, loff_t *ppos)
65 struct canuser_t *canuser =
66 (struct canuser_t *)can_get_rtl_file_private_data(fptr);
67 struct canque_ends_t *qends;
70 if(!canuser || (canuser->magic != CAN_USER_MAGIC)){
71 CANMSG("can_read_rtl_posix: bad canuser magic\n");
75 if (length < sizeof(struct canmsg_t)) {
76 DEBUGMSG("Trying to read less bytes than a CAN message, \n");
77 DEBUGMSG("this will always return zero.\n");
81 qends = canuser->qends;
83 /*if (((struct canmsg_t *)buffer)->flags & MSG_RTR)
84 ret = can_rtr_read(chip, obj, buffer);
86 ret = can_std_read_rtl(qends, fptr->f_flags & O_NONBLOCK,
92 #endif /*CAN_WITH_RTL*/