]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/src/ioctl_rtl.c
6c116a300bb8c01aa3a1178ad0bb385372c823fa
[lincan.git] / lincan / src / ioctl_rtl.c
1 /* ioctl.c
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.2  9 Jul 2003
8  */
9
10 #ifdef CAN_WITH_RTL
11
12 #include "../include/can.h"
13 #include "../include/can_sysdep.h"
14 #include "../include/main.h"
15
16 #include <rtl_posixio.h>
17 #include "../include/can_iortl.h"
18
19
20 int can_ioctl_rtl_posix(struct rtl_file *fptr, unsigned int cmd, unsigned long arg)
21 {
22         struct canuser_t *canuser =
23                 (struct canuser_t *)can_get_rtl_file_private_data(fptr);
24         int i=0;
25         unsigned short channel=0;
26         unsigned btr0=0, btr1=0;
27         struct msgobj_t *obj;
28         struct chip_t *chip;
29         struct canque_ends_t *qends;
30         
31         if(!canuser || (canuser->magic != CAN_USER_MAGIC)){
32                 CANMSG("can_ioctl_: bad canuser magic\n");
33                 return -ENODEV;
34         }
35         
36         obj = canuser->msgobj;
37         if (obj == NULL) {
38                 CANMSG("Could not assign buffer structure\n");
39                 return -1;
40         }
41
42         qends = canuser->qends;
43         chip = obj->hostchip;
44         if (chip == NULL) {
45                 CANMSG("Device is not correctly configured.\n");
46                 CANMSG("Please reload the driver.\n");
47                 return -1;
48         }
49
50         switch (cmd) {
51                 case STAT: {
52                         for (i=0x0; i<0x100; i++)
53                                 CANMSG("0x%x is 0x%x\n",i,can_read_reg(chip,i));
54                         break;
55                 }
56                 case CMD_START: {
57                         if (chip->chipspecops->start_chip(chip))
58                                 return -1;
59                         break;
60                 }
61                 case CMD_STOP: {
62                         if (chip->chipspecops->stop_chip(chip))
63                                 return -1;
64                         break;
65                 }
66                 case CANQUE_FLUSH: {
67                         canque_flush(canuser->rx_edge0);
68                         break;
69                 }
70                 case CONF_FILTER: {
71                         if(canuser->rx_edge0){
72                                 canque_set_filt(canuser->rx_edge0, arg, ~0, 0);
73                         }
74
75                         break;
76                 }
77                 
78                 case CANQUE_FILTER: {
79                         struct canfilt_t canfilt=*(struct canfilt_t *)arg;
80                         if(canuser->rx_edge0){
81                                 canque_set_filt(canuser->rx_edge0, canfilt.id, canfilt.mask, canfilt.flags);
82                         }
83                         break;
84                 }
85
86                 case CONF_BAUD: {
87                         channel = arg & 0xff;
88                         btr0 = (arg >> 8) & 0xff;
89                         btr1 = (arg >> 16) & 0xff;
90
91                         if (chip->chipspecops->set_btregs(chip, btr0, btr1)) {
92                                 CANMSG("Error setting bit timing registers\n");
93                                 return -1;
94                         }
95                         break;
96                 }
97                 default: {
98                         CANMSG("Not a valid ioctl command\n");
99                         return -EINVAL;
100                 }
101                 
102         }
103
104         return 0;
105 }
106
107 #endif /*CAN_WITH_RTL*/