|
1 /****************************************************************************** |
|
2 * |
|
3 * $Id$ |
|
4 * |
|
5 * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH |
|
6 * |
|
7 * This file is part of the IgH EtherCAT Master. |
|
8 * |
|
9 * The IgH EtherCAT Master is free software; you can redistribute it and/or |
|
10 * modify it under the terms of the GNU General Public License version 2, as |
|
11 * published by the Free Software Foundation. |
|
12 * |
|
13 * The IgH EtherCAT Master is distributed in the hope that it will be useful, |
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
16 * Public License for more details. |
|
17 * |
|
18 * You should have received a copy of the GNU General Public License along |
|
19 * with the IgH EtherCAT Master; if not, write to the Free Software |
|
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
21 * |
|
22 * --- |
|
23 * |
|
24 * The license mentioned above concerns the source code only. Using the |
|
25 * EtherCAT technology and brand is only permitted in compliance with the |
|
26 * industrial property and similar rights of Beckhoff Automation GmbH. |
|
27 * |
|
28 *****************************************************************************/ |
|
29 |
|
30 #include <linux/version.h> |
|
31 #include <linux/module.h> |
|
32 #include <linux/timer.h> |
|
33 #include <linux/interrupt.h> |
|
34 #include <linux/err.h> |
|
35 |
|
36 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27) |
|
37 #include <linux/semaphore.h> |
|
38 #else |
|
39 #include <asm/semaphore.h> |
|
40 #endif |
|
41 |
|
42 #include "../../include/ecrt.h" // EtherCAT realtime interface |
|
43 #include "../../include/ectty.h" // EtherCAT TTY interface |
|
44 |
|
45 /*****************************************************************************/ |
|
46 |
|
47 // Module parameters |
|
48 #define FREQUENCY 100 |
|
49 |
|
50 // Optional features |
|
51 |
|
52 #define PFX "ec_tty_example: " |
|
53 |
|
54 /*****************************************************************************/ |
|
55 |
|
56 // EtherCAT |
|
57 static ec_master_t *master = NULL; |
|
58 static ec_master_state_t master_state = {}; |
|
59 struct semaphore master_sem; |
|
60 |
|
61 static ec_domain_t *domain1 = NULL; |
|
62 static ec_domain_state_t domain1_state = {}; |
|
63 |
|
64 // Timer |
|
65 static struct timer_list timer; |
|
66 |
|
67 /*****************************************************************************/ |
|
68 |
|
69 // process data |
|
70 static uint8_t *domain1_pd; // process data memory |
|
71 |
|
72 #define BusCouplerPos 0, 0 |
|
73 #define SerialPos 0, 1 |
|
74 |
|
75 #define Beckhoff_EK1100 0x00000002, 0x044c2c52 |
|
76 #define Beckhoff_EL6002 0x00000002, 0x17723052 |
|
77 |
|
78 // offsets for PDO entries |
|
79 static unsigned int off_ctrl; |
|
80 static unsigned int off_tx; |
|
81 static unsigned int off_status; |
|
82 static unsigned int off_rx; |
|
83 |
|
84 const static ec_pdo_entry_reg_t domain1_regs[] = { |
|
85 {SerialPos, Beckhoff_EL6002, 0x7001, 0x01, &off_ctrl}, |
|
86 {SerialPos, Beckhoff_EL6002, 0x7000, 0x11, &off_tx}, |
|
87 {SerialPos, Beckhoff_EL6002, 0x6001, 0x01, &off_status}, |
|
88 {SerialPos, Beckhoff_EL6002, 0x6000, 0x11, &off_rx}, |
|
89 {} |
|
90 }; |
|
91 |
|
92 static unsigned int counter = 0; |
|
93 |
|
94 typedef enum { |
|
95 SER_REQUEST_INIT, |
|
96 SER_WAIT_FOR_INIT_RESPONSE, |
|
97 SER_READY |
|
98 } serial_state_t; |
|
99 |
|
100 typedef struct { |
|
101 size_t max_tx_data_size; |
|
102 size_t max_rx_data_size; |
|
103 |
|
104 uint8_t *tx_data; |
|
105 uint8_t tx_data_size; |
|
106 |
|
107 serial_state_t state; |
|
108 |
|
109 uint8_t tx_request_toggle; |
|
110 uint8_t tx_accepted_toggle; |
|
111 |
|
112 uint8_t rx_request_toggle; |
|
113 uint8_t rx_accepted_toggle; |
|
114 |
|
115 uint16_t control; |
|
116 } serial_device_t; |
|
117 |
|
118 static serial_device_t *ser = NULL; |
|
119 static ec_tty_t *tty = NULL; |
|
120 |
|
121 /*****************************************************************************/ |
|
122 |
|
123 /* Slave 1, "EL6002" |
|
124 * Vendor ID: 0x00000002 |
|
125 * Product code: 0x17723052 |
|
126 * Revision number: 0x00100000 |
|
127 */ |
|
128 |
|
129 ec_pdo_entry_info_t slave_1_pdo_entries[] = { |
|
130 {0x7001, 0x01, 16}, /* Ctrl */ |
|
131 {0x7000, 0x11, 8}, /* Data Out 0 */ |
|
132 {0x7000, 0x12, 8}, /* Data Out 1 */ |
|
133 {0x7000, 0x13, 8}, /* Data Out 2 */ |
|
134 {0x7000, 0x14, 8}, /* Data Out 3 */ |
|
135 {0x7000, 0x15, 8}, /* Data Out 4 */ |
|
136 {0x7000, 0x16, 8}, /* Data Out 5 */ |
|
137 {0x7000, 0x17, 8}, /* Data Out 6 */ |
|
138 {0x7000, 0x18, 8}, /* Data Out 7 */ |
|
139 {0x7000, 0x19, 8}, /* Data Out 8 */ |
|
140 {0x7000, 0x1a, 8}, /* Data Out 9 */ |
|
141 {0x7000, 0x1b, 8}, /* Data Out 10 */ |
|
142 {0x7000, 0x1c, 8}, /* Data Out 11 */ |
|
143 {0x7000, 0x1d, 8}, /* Data Out 12 */ |
|
144 {0x7000, 0x1e, 8}, /* Data Out 13 */ |
|
145 {0x7000, 0x1f, 8}, /* Data Out 14 */ |
|
146 {0x7000, 0x20, 8}, /* Data Out 15 */ |
|
147 {0x7000, 0x21, 8}, /* Data Out 16 */ |
|
148 {0x7000, 0x22, 8}, /* Data Out 17 */ |
|
149 {0x7000, 0x23, 8}, /* Data Out 18 */ |
|
150 {0x7000, 0x24, 8}, /* Data Out 19 */ |
|
151 {0x7000, 0x25, 8}, /* Data Out 20 */ |
|
152 {0x7000, 0x26, 8}, /* Data Out 21 */ |
|
153 {0x7011, 0x01, 16}, /* Ctrl */ |
|
154 {0x7010, 0x11, 8}, /* Data Out 0 */ |
|
155 {0x7010, 0x12, 8}, /* Data Out 1 */ |
|
156 {0x7010, 0x13, 8}, /* Data Out 2 */ |
|
157 {0x7010, 0x14, 8}, /* Data Out 3 */ |
|
158 {0x7010, 0x15, 8}, /* Data Out 4 */ |
|
159 {0x7010, 0x16, 8}, /* Data Out 5 */ |
|
160 {0x7010, 0x17, 8}, /* Data Out 6 */ |
|
161 {0x7010, 0x18, 8}, /* Data Out 7 */ |
|
162 {0x7010, 0x19, 8}, /* Data Out 8 */ |
|
163 {0x7010, 0x1a, 8}, /* Data Out 9 */ |
|
164 {0x7010, 0x1b, 8}, /* Data Out 10 */ |
|
165 {0x7010, 0x1c, 8}, /* Data Out 11 */ |
|
166 {0x7010, 0x1d, 8}, /* Data Out 12 */ |
|
167 {0x7010, 0x1e, 8}, /* Data Out 13 */ |
|
168 {0x7010, 0x1f, 8}, /* Data Out 14 */ |
|
169 {0x7010, 0x20, 8}, /* Data Out 15 */ |
|
170 {0x7010, 0x21, 8}, /* Data Out 16 */ |
|
171 {0x7010, 0x22, 8}, /* Data Out 17 */ |
|
172 {0x7010, 0x23, 8}, /* Data Out 18 */ |
|
173 {0x7010, 0x24, 8}, /* Data Out 19 */ |
|
174 {0x7010, 0x25, 8}, /* Data Out 20 */ |
|
175 {0x7010, 0x26, 8}, /* Data Out 21 */ |
|
176 {0x6001, 0x01, 16}, /* Status */ |
|
177 {0x6000, 0x11, 8}, /* Data In 0 */ |
|
178 {0x6000, 0x12, 8}, /* Data In 1 */ |
|
179 {0x6000, 0x13, 8}, /* Data In 2 */ |
|
180 {0x6000, 0x14, 8}, /* Data In 3 */ |
|
181 {0x6000, 0x15, 8}, /* Data In 4 */ |
|
182 {0x6000, 0x16, 8}, /* Data In 5 */ |
|
183 {0x6000, 0x17, 8}, /* Data In 6 */ |
|
184 {0x6000, 0x18, 8}, /* Data In 7 */ |
|
185 {0x6000, 0x19, 8}, /* Data In 8 */ |
|
186 {0x6000, 0x1a, 8}, /* Data In 9 */ |
|
187 {0x6000, 0x1b, 8}, /* Data In 10 */ |
|
188 {0x6000, 0x1c, 8}, /* Data In 11 */ |
|
189 {0x6000, 0x1d, 8}, /* Data In 12 */ |
|
190 {0x6000, 0x1e, 8}, /* Data In 13 */ |
|
191 {0x6000, 0x1f, 8}, /* Data In 14 */ |
|
192 {0x6000, 0x20, 8}, /* Data In 15 */ |
|
193 {0x6000, 0x21, 8}, /* Data In 16 */ |
|
194 {0x6000, 0x22, 8}, /* Data In 17 */ |
|
195 {0x6000, 0x23, 8}, /* Data In 18 */ |
|
196 {0x6000, 0x24, 8}, /* Data In 19 */ |
|
197 {0x6000, 0x25, 8}, /* Data In 20 */ |
|
198 {0x6000, 0x26, 8}, /* Data In 21 */ |
|
199 {0x6011, 0x01, 16}, /* Status */ |
|
200 {0x6010, 0x11, 8}, /* Data In 0 */ |
|
201 {0x6010, 0x12, 8}, /* Data In 1 */ |
|
202 {0x6010, 0x13, 8}, /* Data In 2 */ |
|
203 {0x6010, 0x14, 8}, /* Data In 3 */ |
|
204 {0x6010, 0x15, 8}, /* Data In 4 */ |
|
205 {0x6010, 0x16, 8}, /* Data In 5 */ |
|
206 {0x6010, 0x17, 8}, /* Data In 6 */ |
|
207 {0x6010, 0x18, 8}, /* Data In 7 */ |
|
208 {0x6010, 0x19, 8}, /* Data In 8 */ |
|
209 {0x6010, 0x1a, 8}, /* Data In 9 */ |
|
210 {0x6010, 0x1b, 8}, /* Data In 10 */ |
|
211 {0x6010, 0x1c, 8}, /* Data In 11 */ |
|
212 {0x6010, 0x1d, 8}, /* Data In 12 */ |
|
213 {0x6010, 0x1e, 8}, /* Data In 13 */ |
|
214 {0x6010, 0x1f, 8}, /* Data In 14 */ |
|
215 {0x6010, 0x20, 8}, /* Data In 15 */ |
|
216 {0x6010, 0x21, 8}, /* Data In 16 */ |
|
217 {0x6010, 0x22, 8}, /* Data In 17 */ |
|
218 {0x6010, 0x23, 8}, /* Data In 18 */ |
|
219 {0x6010, 0x24, 8}, /* Data In 19 */ |
|
220 {0x6010, 0x25, 8}, /* Data In 20 */ |
|
221 {0x6010, 0x26, 8}, /* Data In 21 */ |
|
222 }; |
|
223 |
|
224 ec_pdo_info_t slave_1_pdos[] = { |
|
225 {0x1604, 23, slave_1_pdo_entries + 0}, /* COM RxPDO-Map Outputs Ch.1 */ |
|
226 {0x1605, 23, slave_1_pdo_entries + 23}, /* COM RxPDO-Map Outputs Ch.2 */ |
|
227 {0x1a04, 23, slave_1_pdo_entries + 46}, /* COM TxPDO-Map Inputs Ch.1 */ |
|
228 {0x1a05, 23, slave_1_pdo_entries + 69}, /* COM TxPDO-Map Inputs Ch.2 */ |
|
229 }; |
|
230 |
|
231 ec_sync_info_t slave_1_syncs[] = { |
|
232 {0, EC_DIR_OUTPUT, 0, NULL, EC_WD_DISABLE}, |
|
233 {1, EC_DIR_INPUT, 0, NULL, EC_WD_DISABLE}, |
|
234 {2, EC_DIR_OUTPUT, 2, slave_1_pdos + 0, EC_WD_DISABLE}, |
|
235 {3, EC_DIR_INPUT, 2, slave_1_pdos + 2, EC_WD_DISABLE}, |
|
236 {0xff} |
|
237 }; |
|
238 |
|
239 /****************************************************************************/ |
|
240 |
|
241 int serial_init(serial_device_t *ser, size_t max_tx, size_t max_rx) |
|
242 { |
|
243 ser->max_tx_data_size = max_tx; |
|
244 ser->max_rx_data_size = max_rx; |
|
245 ser->tx_data = NULL; |
|
246 ser->tx_data_size = 0; |
|
247 ser->state = SER_REQUEST_INIT; |
|
248 ser->tx_request_toggle = 0; |
|
249 ser->rx_accepted_toggle = 0; |
|
250 ser->control = 0x0000; |
|
251 |
|
252 if (max_tx > 0) { |
|
253 ser->tx_data = kmalloc(max_tx, GFP_KERNEL); |
|
254 if (ser->tx_data == NULL) { |
|
255 return -ENOMEM; |
|
256 } |
|
257 } |
|
258 |
|
259 return 0; |
|
260 } |
|
261 |
|
262 /****************************************************************************/ |
|
263 |
|
264 void serial_clear(serial_device_t *ser) |
|
265 { |
|
266 if (ser->tx_data) { |
|
267 kfree(ser->tx_data); |
|
268 } |
|
269 } |
|
270 |
|
271 /****************************************************************************/ |
|
272 |
|
273 void serial_run(serial_device_t *ser, uint16_t status, uint8_t *rx_data) |
|
274 { |
|
275 uint8_t tx_accepted_toggle, rx_request_toggle; |
|
276 |
|
277 switch (ser->state) { |
|
278 case SER_READY: |
|
279 |
|
280 /* Send data */ |
|
281 |
|
282 tx_accepted_toggle = status & 0x0001; |
|
283 if (tx_accepted_toggle != ser->tx_accepted_toggle) { // ready |
|
284 ser->tx_data_size = |
|
285 ectty_tx_data(tty, ser->tx_data, ser->max_tx_data_size); |
|
286 if (ser->tx_data_size) { |
|
287 printk(KERN_INFO PFX "Sending %u bytes.\n", ser->tx_data_size); |
|
288 ser->tx_request_toggle = !ser->tx_request_toggle; |
|
289 ser->tx_accepted_toggle = tx_accepted_toggle; |
|
290 } |
|
291 } |
|
292 |
|
293 /* Receive data */ |
|
294 |
|
295 rx_request_toggle = status & 0x0002; |
|
296 if (rx_request_toggle != ser->rx_request_toggle) { |
|
297 uint8_t rx_data_size = status >> 8; |
|
298 ser->rx_request_toggle = rx_request_toggle; |
|
299 printk(KERN_INFO PFX "Received %u bytes.\n", rx_data_size); |
|
300 ectty_rx_data(tty, rx_data, rx_data_size); |
|
301 ser->rx_accepted_toggle = !ser->rx_accepted_toggle; |
|
302 } |
|
303 |
|
304 ser->control = |
|
305 ser->tx_request_toggle | |
|
306 ser->rx_accepted_toggle << 1 | |
|
307 ser->tx_data_size << 8; |
|
308 break; |
|
309 |
|
310 case SER_REQUEST_INIT: |
|
311 if (status & (1 << 2)) { |
|
312 ser->control = 0x0000; |
|
313 ser->state = SER_WAIT_FOR_INIT_RESPONSE; |
|
314 } else { |
|
315 ser->control = 1 << 2; // CW.2, request initialization |
|
316 } |
|
317 break; |
|
318 |
|
319 case SER_WAIT_FOR_INIT_RESPONSE: |
|
320 if (!(status & (1 << 2))) { |
|
321 printk(KERN_INFO PFX "Init successful.\n"); |
|
322 ser->tx_accepted_toggle = 1; |
|
323 ser->control = 0x0000; |
|
324 ser->state = SER_READY; |
|
325 } |
|
326 break; |
|
327 } |
|
328 |
|
329 } |
|
330 |
|
331 /*****************************************************************************/ |
|
332 |
|
333 void check_domain1_state(void) |
|
334 { |
|
335 ec_domain_state_t ds; |
|
336 |
|
337 down(&master_sem); |
|
338 ecrt_domain_state(domain1, &ds); |
|
339 up(&master_sem); |
|
340 |
|
341 if (ds.working_counter != domain1_state.working_counter) |
|
342 printk(KERN_INFO PFX "Domain1: WC %u.\n", ds.working_counter); |
|
343 if (ds.wc_state != domain1_state.wc_state) |
|
344 printk(KERN_INFO PFX "Domain1: State %u.\n", ds.wc_state); |
|
345 |
|
346 domain1_state = ds; |
|
347 } |
|
348 |
|
349 /*****************************************************************************/ |
|
350 |
|
351 void check_master_state(void) |
|
352 { |
|
353 ec_master_state_t ms; |
|
354 |
|
355 down(&master_sem); |
|
356 ecrt_master_state(master, &ms); |
|
357 up(&master_sem); |
|
358 |
|
359 if (ms.slaves_responding != master_state.slaves_responding) |
|
360 printk(KERN_INFO PFX "%u slave(s).\n", ms.slaves_responding); |
|
361 if (ms.al_states != master_state.al_states) |
|
362 printk(KERN_INFO PFX "AL states: 0x%02X.\n", ms.al_states); |
|
363 if (ms.link_up != master_state.link_up) |
|
364 printk(KERN_INFO PFX "Link is %s.\n", ms.link_up ? "up" : "down"); |
|
365 |
|
366 master_state = ms; |
|
367 } |
|
368 |
|
369 /*****************************************************************************/ |
|
370 |
|
371 void cyclic_task(unsigned long data) |
|
372 { |
|
373 // receive process data |
|
374 down(&master_sem); |
|
375 ecrt_master_receive(master); |
|
376 ecrt_domain_process(domain1); |
|
377 up(&master_sem); |
|
378 |
|
379 // check process data state (optional) |
|
380 check_domain1_state(); |
|
381 |
|
382 if (counter) { |
|
383 counter--; |
|
384 } else { // do this at 1 Hz |
|
385 counter = FREQUENCY; |
|
386 |
|
387 // check for master state (optional) |
|
388 check_master_state(); |
|
389 } |
|
390 |
|
391 serial_run(ser, EC_READ_U16(domain1_pd + off_status), domain1_pd + off_rx); |
|
392 EC_WRITE_U16(domain1_pd + off_ctrl, ser->control); |
|
393 memcpy(domain1_pd + off_tx, ser->tx_data, 22); |
|
394 |
|
395 // send process data |
|
396 down(&master_sem); |
|
397 ecrt_domain_queue(domain1); |
|
398 ecrt_master_send(master); |
|
399 up(&master_sem); |
|
400 |
|
401 // restart timer |
|
402 timer.expires += HZ / FREQUENCY; |
|
403 add_timer(&timer); |
|
404 } |
|
405 |
|
406 /*****************************************************************************/ |
|
407 |
|
408 void send_callback(void *cb_data) |
|
409 { |
|
410 ec_master_t *m = (ec_master_t *) cb_data; |
|
411 down(&master_sem); |
|
412 ecrt_master_send_ext(m); |
|
413 up(&master_sem); |
|
414 } |
|
415 |
|
416 /*****************************************************************************/ |
|
417 |
|
418 void receive_callback(void *cb_data) |
|
419 { |
|
420 ec_master_t *m = (ec_master_t *) cb_data; |
|
421 down(&master_sem); |
|
422 ecrt_master_receive(m); |
|
423 up(&master_sem); |
|
424 } |
|
425 |
|
426 /*****************************************************************************/ |
|
427 |
|
428 int __init init_mini_module(void) |
|
429 { |
|
430 int ret = -1; |
|
431 ec_slave_config_t *sc; |
|
432 |
|
433 printk(KERN_INFO PFX "Starting...\n"); |
|
434 |
|
435 ser = kmalloc(sizeof(*ser), GFP_KERNEL); |
|
436 if (!ser) { |
|
437 printk(KERN_ERR PFX "Failed to allocate serial device object.\n"); |
|
438 ret = -ENOMEM; |
|
439 goto out_return; |
|
440 } |
|
441 |
|
442 ret = serial_init(ser, 22, 22); |
|
443 if (ret) { |
|
444 printk(KERN_ERR PFX "Failed to init serial device object.\n"); |
|
445 goto out_free_serial; |
|
446 } |
|
447 |
|
448 tty = ectty_create(); |
|
449 if (IS_ERR(tty)) { |
|
450 printk(KERN_ERR PFX "Failed to create tty.\n"); |
|
451 ret = PTR_ERR(tty); |
|
452 goto out_serial; |
|
453 } |
|
454 |
|
455 master = ecrt_request_master(0); |
|
456 if (!master) { |
|
457 ret = -EBUSY; |
|
458 printk(KERN_ERR PFX "Requesting master 0 failed.\n"); |
|
459 goto out_tty; |
|
460 } |
|
461 |
|
462 sema_init(&master_sem, 1); |
|
463 ecrt_master_callbacks(master, send_callback, receive_callback, master); |
|
464 |
|
465 printk(KERN_INFO PFX "Registering domain...\n"); |
|
466 if (!(domain1 = ecrt_master_create_domain(master))) { |
|
467 printk(KERN_ERR PFX "Domain creation failed!\n"); |
|
468 goto out_release_master; |
|
469 } |
|
470 |
|
471 // Create configuration for bus coupler |
|
472 sc = ecrt_master_slave_config(master, BusCouplerPos, Beckhoff_EK1100); |
|
473 if (!sc) |
|
474 return -1; |
|
475 |
|
476 if (!(sc = ecrt_master_slave_config( |
|
477 master, SerialPos, Beckhoff_EL6002))) { |
|
478 printk(KERN_ERR PFX "Failed to get slave configuration.\n"); |
|
479 return -1; |
|
480 } |
|
481 |
|
482 printk("Configuring PDOs...\n"); |
|
483 if (ecrt_slave_config_pdos(sc, EC_END, slave_1_syncs)) { |
|
484 printk(KERN_ERR PFX "Failed to configure PDOs.\n"); |
|
485 return -1; |
|
486 } |
|
487 |
|
488 if (ecrt_domain_reg_pdo_entry_list(domain1, domain1_regs)) { |
|
489 printk(KERN_ERR PFX "PDO entry registration failed!\n"); |
|
490 return -1; |
|
491 } |
|
492 |
|
493 printk(KERN_INFO PFX "Activating master...\n"); |
|
494 if (ecrt_master_activate(master)) { |
|
495 printk(KERN_ERR PFX "Failed to activate master!\n"); |
|
496 goto out_release_master; |
|
497 } |
|
498 |
|
499 // Get internal process data for domain |
|
500 domain1_pd = ecrt_domain_data(domain1); |
|
501 |
|
502 printk(KERN_INFO PFX "Starting cyclic sample thread.\n"); |
|
503 init_timer(&timer); |
|
504 timer.function = cyclic_task; |
|
505 timer.expires = jiffies + 10; |
|
506 add_timer(&timer); |
|
507 |
|
508 printk(KERN_INFO PFX "Started.\n"); |
|
509 return 0; |
|
510 |
|
511 out_release_master: |
|
512 printk(KERN_ERR PFX "Releasing master...\n"); |
|
513 ecrt_release_master(master); |
|
514 out_tty: |
|
515 ectty_free(tty); |
|
516 out_serial: |
|
517 serial_clear(ser); |
|
518 out_free_serial: |
|
519 kfree(ser); |
|
520 out_return: |
|
521 printk(KERN_ERR PFX "Failed to load. Aborting.\n"); |
|
522 return ret; |
|
523 } |
|
524 |
|
525 /*****************************************************************************/ |
|
526 |
|
527 void __exit cleanup_mini_module(void) |
|
528 { |
|
529 printk(KERN_INFO PFX "Stopping...\n"); |
|
530 |
|
531 del_timer_sync(&timer); |
|
532 |
|
533 printk(KERN_INFO PFX "Releasing master...\n"); |
|
534 ecrt_release_master(master); |
|
535 |
|
536 ectty_free(tty); |
|
537 serial_clear(ser); |
|
538 kfree(ser); |
|
539 |
|
540 printk(KERN_INFO PFX "Unloading.\n"); |
|
541 } |
|
542 |
|
543 /*****************************************************************************/ |
|
544 |
|
545 MODULE_LICENSE("GPL"); |
|
546 MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>"); |
|
547 MODULE_DESCRIPTION("EtherCAT minimal test environment"); |
|
548 |
|
549 module_init(init_mini_module); |
|
550 module_exit(cleanup_mini_module); |
|
551 |
|
552 /*****************************************************************************/ |