]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/src/ioctl_rtl.c
The LinCAN driver license unified according to DCE FEE CTU head and superiors request.
[lincan.git] / lincan / src / ioctl_rtl.c
1 /**************************************************************************/
2 /* File: ioctl_rtl.c - RT-Linux variant of IOCTL system call              */
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 #ifdef CAN_WITH_RTL
36
37 #include "../include/can.h"
38 #include "../include/can_sysdep.h"
39 #include "../include/main.h"
40
41 #include <rtl_posixio.h>
42 #include "../include/ioctl.h"
43 #include "../include/can_iortl.h"
44
45
46 int can_ioctl_rtl_posix(struct rtl_file *fptr, unsigned int cmd, unsigned long arg)
47 {
48         struct canuser_t *canuser =
49                 (struct canuser_t *)can_get_rtl_file_private_data(fptr);
50         int i=0;
51         unsigned short channel=0;
52         unsigned btr0=0, btr1=0;
53         struct msgobj_t *obj;
54         struct canchip_t *chip;
55         struct canque_ends_t *qends;
56         
57         if(!canuser || (canuser->magic != CAN_USER_MAGIC)){
58                 CANMSG("can_ioctl_: bad canuser magic\n");
59                 return -ENODEV;
60         }
61         
62         obj = canuser->msgobj;
63         if (obj == NULL) {
64                 CANMSG("Could not assign buffer structure\n");
65                 return -1;
66         }
67
68         qends = canuser->qends;
69         chip = obj->hostchip;
70         if (chip == NULL) {
71                 CANMSG("Device is not correctly configured.\n");
72                 CANMSG("Please reload the driver.\n");
73                 return -1;
74         }
75
76         switch (cmd) {
77                 case CAN_DRV_QUERY: {
78                         return can_ioctl_query(canuser, arg);
79                 }
80                 case STAT: {
81                         for (i=0x0; i<0x100; i++)
82                                 CANMSG("0x%x is 0x%x\n",i,can_read_reg(chip,i));
83                         break;
84                 }
85                 case CMD_START: {
86                         if (chip->chipspecops->start_chip(chip))
87                                 return -1;
88                         break;
89                 }
90                 case CMD_STOP: {
91                         if (chip->chipspecops->stop_chip(chip))
92                                 return -1;
93                         break;
94                 }
95                 case CANQUE_FLUSH: {
96                         canque_flush(canuser->rx_edge0);
97                         break;
98                 }
99                 case CONF_FILTER: {
100                         if(canuser->rx_edge0){
101                                 canque_set_filt(canuser->rx_edge0, arg, ~0, 0);
102                         }
103
104                         break;
105                 }
106                 
107                 case CANQUE_FILTER: {
108                         struct canfilt_t canfilt=*(struct canfilt_t *)arg;
109                         if(canuser->rx_edge0){
110                                 canque_set_filt(canuser->rx_edge0, canfilt.id, canfilt.mask, canfilt.flags);
111                         }
112                         break;
113                 }
114
115                 case CONF_BAUD: {
116                         channel = arg & 0xff;
117                         btr0 = (arg >> 8) & 0xff;
118                         btr1 = (arg >> 16) & 0xff;
119
120                         if (chip->chipspecops->set_btregs(chip, btr0, btr1)) {
121                                 CANMSG("Error setting bit timing registers\n");
122                                 return -1;
123                         }
124                         break;
125                 }
126                 default: {
127                         CANMSG("Not a valid ioctl command\n");
128                         return -EINVAL;
129                 }
130                 
131         }
132
133         return 0;
134 }
135
136 #endif /*CAN_WITH_RTL*/