blob: 2701ae6f5bff918672d802bdbcd08fbfd9ebd9c7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#!/bin/bash
#
# gpsinit - initialize kernel-CAN interfaces
#
# This file is Copyright (c) 2012 by the GPSD project.
# BSD terms apply: see the file COPYING in the distribution root for details.
#
speed=38400
net=0
version()
{
echo `basename $0`" : Version v0.20";
}
usage()
{
version; echo;
echo "usage :" `basename $0` "[-n <netnumber>] [-s <serial speed>] <can_module_name> [<interface_name>]";
echo " :" `basename $0` "-v";
echo " :" `basename $0` "-h";
echo " Options include:";
echo " -n = CAN network number, 0 if not given.";
echo " -s = Speed of the slcan hardware port, 38400 if not given.";
echo " = Needed for some slcan modules only.";
echo " -v = Print version of this script and exit.";
echo " -h = Print this help message and exit.";
echo " can_module_name = One out of plx_pci, esd_usb2, usb_8dev, vcan, slcan, beaglebone.";
echo " interface_name = The interface, the SLCAN module is connected to, i.e. /dev/ttyS0 or /dev/ttyUSB0.";
echo " = Needed for the slcan module only. The default is /dev/ttyUSB0.";
echo "Root permissions are needed for the first calling option (Enforced by socketCAN subsystem).";
}
while getopts :n:s:vh opt
do
case ${opt} in
n) net=${OPTARG};;
s) speed=${OPTARG};;
v) version; exit 0;;
h) usage; exit 0;;
\?) usage; exit 1;;
esac
done
shift $((${OPTIND} - 1))
candevice=$1
case ${candevice} in
plx_pci)
# For the SJA1000 based PCI or PCI-Express CAN interface
modprobe plx_pci;
ip link set can${net} type can tq 250 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1;
ip link set can${net} up;;
esd_usb2)
# For an esd usb/2 CAN interface
modprobe esd_usb2;
ip link set can${net} type can tq 250 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1;
ip link set can${net} up;;
usb_8dev)
# For an 8devices usb2can CAN interface
modprobe usb_8dev;
ip link set can${net} type can tq 250 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1;
ip link set can${net} up;;
vcan)
# With this setup, CAN frames can be injected into vcan0 by a test
modprobe vcan;
ip link add type vcan;
ip link set vcan${net} up;;
slcan)
# For a serial line CAN device
# No support for devices, that need a setup of the baudrate yet
device=${2:-/dev/ttyUSB0};
modprobe slcan;
slcan_attach -f -s5 -o ${device};
slcand `basename ${device}`;
ip link set slcan${net} up;;
beaglebone)
# For CAN interface on a BeagleBone
# The d_can driver is part of the kernel
ip link set can${net} type can bitrate 250000 sjw 1;
ip link set can${net} up;;
*)
echo `basename ${0}` ": invalid CAN interface ${1} net${net} device ${2:-(none)}"
echo;
usage;
exit 1
esac
|