]> rtime.felk.cvut.cz Git - linux-lin.git/blob - sllin/README.txt
sllin: Documentation.
[linux-lin.git] / sllin / README.txt
1 Intro
2 =====
3 Sllin is TTY discipline enabling you to create LIN Master (and partially
4 LIN Slave) out of your computer.
5 Hardware needed is Hardware UART embedded into the computer + simple
6 voltage level LIN converter.
7
8
9 Compilation
10 ===========
11 To successfully compile sllin, it is necessary to have source code
12 of Linux kernel actually running on the computer.
13
14 To compile, run
15 $ make
16
17
18 First steps
19 ===========
20 To use sllin, it is necessary to set sllin TTY discipline to some
21 existing serial device.
22
23 It is possible to use slightly modified slcan_attach program --
24 particular patch from canutils-patches folder has to be applied.
25
26 After successful compilation and loading of sllin, patching and
27 compiling of slcan_attach, it is possible to run:
28
29 $ sudo slcan_attach -w /dev/ttyS0
30 attached tty /dev/ttyS0 to netdevice sllin0
31 Press any key to detach /dev/ttyS0 ...
32
33 # Run from another terminal
34 $ dmesg
35 [157600.564071] sllin: sllin_kwthread stopped.
36 [157600.572058] netconsole: network logging stopped, interface sllin0 unregistered
37 [157608.437260] sllin: serial line LIN interface driver
38 [157608.437267] sllin: 10 dynamic interface channels.
39 [157608.437271] sllin: Break is generated manually with tiny sleep.
40 [157610.513646] sllin: sllin_open() invoked
41 [157610.519502] sllin: sllin_kwthread started.
42
43 $ ip link show dev sllin0
44 11: sllin0: <NOARP> mtu 16 qdisc noop state DOWN qlen 10
45     link/can
46
47 $ sudo ip link set sllin0 up
48
49 $ sudo ip link set sllin0 up
50 lisovros@pc-lisovy:~/src/lin/pcan_lin/sllin$ ip link show dev sllin0
51 11: sllin0: <NOARP,UP,LOWER_UP> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
52     link/can
53
54 # state UNKNOWN in this case is considered as wanted
55
56
57 Real usage
58 ==========
59 Communication with sllin is done by sending different types of CAN
60 frames into it.
61
62 * EFF non-RTR frame:
63   Configuration on internal "frame cache".
64
65 * SFF RTR frame:
66   Send LIN header with LIN ID corresponding to can_id in this
67   particular CAN frame.
68
69 * SFF non-RTR frame:
70   Send LIN header immediately (with LIN ID corresponding to can_id
71   in this particular CAN frame) followed by LIN response containing
72   same data as this particular CAN frame.
73
74
75 Module parameters
76 =================
77 * maxdev
78    -- Optional
79    -- Possible values: unsigned int
80    -- Maximum number of sllin interfaces.
81       When not set, maxdev = 4.
82       When maxdev < 4, maxdev = 4.
83
84 * master
85    -- Optional
86    -- Possible values: 0 or 1
87    -- Sets if LIN interface will be in Master mode (1 = Master, 0 = Slave).
88       When not set, master = 1.
89
90 * baudrate
91    -- Optional
92    -- Possible values: unsigned int
93    -- Baudrate used by LIN interface on LIN bus.
94       When not set, baudrate = LIN_DEFAULT_BAUDRATE (19200).
95
96
97 Examples
98 ========
99 # Some outputs might be slightly modified for more comfortable reading
100
101 $ ls sllin.c
102 sllin.c
103
104 $ make
105 make -C /lib/modules/2.6.36.2-00398-g504e6a6-dirty/build M=/h.../sllin modules
106 make[1]: Entering directory `/h.../kernel/build/glab-2.6.36'
107 make -C /h.../kernel/2.6.36 O=/h.../kernel/build/glab-2.6.36/. modules ARCH=i386
108   CC [M]  /h.../sllin/sllin.o
109   Building modules, stage 2.
110   MODPOST 1 modules
111   LD [M]  /h.../sllin/sllin.ko
112 make[1]: Leaving directory `/h.../kernel/build/glab-2.6.36'
113
114 $ sudo insmod ./sllin.ko
115
116 $ dmesg | tail -3
117 [158268.949289] sllin: serial line LIN interface driver
118 [158268.949296] sllin: 10 dynamic interface channels.
119 [158268.949300] sllin: Break is generated manually with tiny sleep.
120
121 # Run in another terminal
122 $ sudo slcan_attach -w /dev/ttyS0
123 attached tty /dev/ttyS0 to netdevice sllin0
124 Press any key to detach /dev/ttyS0 ...
125
126 $ sudo ip link set sllin0 up
127
128 $ ip link show dev sllin0
129 12: sllin0: <NOARP,UP,LOWER_UP> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
130     link/can
131
132 # Run "candump sllin0" in another terminal
133
134
135 # ----- Simple RTR CAN frame -----
136 # Patched version of cangen
137 $ cangen sllin0 -r -I 1 -n 1 -L 0
138
139 # Output from candump
140   sllin0    1  [0] remote request
141   sllin0    1  [2] 00 00
142
143 # First line: RTR sent to sllin0
144 # Second line: Response obtained from LIN bus (there was LIN slave
145 #  device on the LIN bus answering to LIN ID 1with data 0x00 0x00).
146
147
148 # ----- RX_TIMEOUT -----
149 $ cangen sllin0 -r -I 8 -n 1 -L 0
150
151 # LIN_ERR_RX_TIMEOUT flag set -- nobody answered to our LIN header
152 #  or CAN RTR frame
153   sllin0    8  [0] remote request
154   sllin0      2000  [0]
155
156 $ ip -s link show dev sllin0
157 14: sllin0: <NOARP,UP,LOWER_UP> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
158     link/can 
159     RX: bytes  packets  errors  dropped overrun mcast   
160     2          4        1       0       0       0      
161     TX: bytes  packets  errors  dropped carrier collsns 
162     0          4        0       0       0       0 
163
164
165
166 # ----- Configure frame cache -----
167 # Configure frame cache to answer on LIN ID = 8
168 $ cangen sllin0 -e -I 0x848 -n 1 -L 2 -D beef
169
170   sllin0       848  [2] BE EF
171
172 # Try RTR CAN frame with ID = 8 again
173 $ cangen sllin0 -r -I 8 -n 1 -L 0
174
175 # Everything went better than expected
176   sllin0    8  [0] remote request
177   sllin0    8  [2] BE EF
178
179
180
181 # ----- non-RTR CAN frame -----
182 $ cangen sllin0 -I 7 -n 1 -L 2 -D f00f
183
184   sllin0    7  [2] F0 0F
185   sllin0    7  [2] F0 0F
186
187
188 # ----- Semi-slave mode -----
189 $ insmod ./sllin.ko master=0
190
191 $ sudo slcan_attach -w /dev/ttyS0
192 attached tty /dev/ttyS0 to netdevice sllin0
193 Press any key to detach /dev/ttyS0 ...
194
195 # run in another terminal
196 $ sudo ip link set sllin0 up
197
198 $ candump -t d sllin0
199  (000.000000)  sllin0    2  [0] remote request
200  (001.003734)  sllin0    1  [0] remote request
201  (000.000017)  sllin0    1  [2] 08 80
202  (000.996027)  sllin0    2  [0] remote request
203  (001.003958)  sllin0    1  [0] remote request
204  (000.000017)  sllin0    1  [2] 08 80
205  (000.996049)  sllin0    2  [0] remote request
206  (001.003930)  sllin0    1  [0] remote request
207  (000.000016)  sllin0    1  [2] 08 80
208  (000.996053)  sllin0    2  [0] remote request
209  (001.003945)  sllin0    1  [0] remote request
210  (000.000017)  sllin0    1  [2] 08 80
211
212 # There is one LIN header without response on the bus (= only RTR can frame)
213 # and another LIN header followed by a response (= RTR + non-RTR CAN frame
214 # with the same ID)
215