4 * |
4 * |
5 * Minimalmodul für EtherCAT |
5 * Minimalmodul für EtherCAT |
6 * |
6 * |
7 * $Id$ |
7 * $Id$ |
8 * |
8 * |
9 ******************************************************************************/ |
9 *****************************************************************************/ |
10 |
10 |
11 #include <linux/module.h> |
11 #include <linux/module.h> |
12 #include <linux/delay.h> |
12 #include <linux/delay.h> |
13 #include <linux/timer.h> |
13 #include <linux/timer.h> |
14 |
14 |
15 #include "../drivers/ec_master.h" |
15 #include "../drivers/ec_master.h" |
16 #include "../drivers/ec_device.h" |
16 #include "../drivers/ec_device.h" |
17 #include "../drivers/ec_types.h" |
17 #include "../drivers/ec_types.h" |
18 #include "../drivers/ec_module.h" |
18 #include "../drivers/ec_module.h" |
19 |
19 |
20 /******************************************************************************/ |
20 /*****************************************************************************/ |
21 |
21 |
22 // Auskommentieren, wenn keine zyklischen Daten erwuenscht |
22 // Auskommentieren, wenn keine zyklischen Daten erwuenscht |
23 #define ECAT_CYCLIC_DATA |
23 #define ECAT_CYCLIC_DATA |
24 |
24 |
25 /******************************************************************************/ |
25 /*****************************************************************************/ |
26 |
26 |
27 static EtherCAT_master_t *ecat_master = NULL; |
27 static EtherCAT_master_t *ecat_master = NULL; |
28 |
28 |
29 static EtherCAT_slave_t ecat_slaves[] = |
29 static EtherCAT_slave_t ecat_slaves[] = |
30 { |
30 { |
31 #if 0 |
31 #if 0 |
32 // Block 1 |
32 // Block 1 |
33 ECAT_INIT_SLAVE(Beckhoff_EK1100), |
33 ECAT_INIT_SLAVE(Beckhoff_EK1100, 1), |
34 ECAT_INIT_SLAVE(Beckhoff_EL4102), |
34 ECAT_INIT_SLAVE(Beckhoff_EL4102, 1), |
35 ECAT_INIT_SLAVE(Beckhoff_EL3162), |
35 ECAT_INIT_SLAVE(Beckhoff_EL3162, 1), |
36 ECAT_INIT_SLAVE(Beckhoff_EL1014), |
36 ECAT_INIT_SLAVE(Beckhoff_EL1014, 1), |
37 |
37 |
38 ECAT_INIT_SLAVE(Beckhoff_EL4102), |
38 ECAT_INIT_SLAVE(Beckhoff_EL4102, 1), |
39 ECAT_INIT_SLAVE(Beckhoff_EL4102), |
39 ECAT_INIT_SLAVE(Beckhoff_EL4102, 1), |
40 ECAT_INIT_SLAVE(Beckhoff_EL4102), |
40 ECAT_INIT_SLAVE(Beckhoff_EL4102, 1), |
41 |
41 |
42 ECAT_INIT_SLAVE(Beckhoff_EL3162), |
42 ECAT_INIT_SLAVE(Beckhoff_EL3162, 1), |
43 ECAT_INIT_SLAVE(Beckhoff_EL3162), |
43 ECAT_INIT_SLAVE(Beckhoff_EL3162, 1), |
44 ECAT_INIT_SLAVE(Beckhoff_EL3162), |
44 ECAT_INIT_SLAVE(Beckhoff_EL3162, 1), |
45 ECAT_INIT_SLAVE(Beckhoff_EL3102), |
45 ECAT_INIT_SLAVE(Beckhoff_EL3102, 1), |
46 ECAT_INIT_SLAVE(Beckhoff_EL3102), |
46 ECAT_INIT_SLAVE(Beckhoff_EL3102, 1), |
47 ECAT_INIT_SLAVE(Beckhoff_EL3102), |
47 ECAT_INIT_SLAVE(Beckhoff_EL3102, 1), |
48 |
48 |
49 #endif |
49 #endif |
50 |
50 |
51 #if 1 |
51 #if 1 |
52 // Block 2 |
52 // Block 2 |
53 ECAT_INIT_SLAVE(Beckhoff_EK1100), |
53 ECAT_INIT_SLAVE(Beckhoff_EK1100, 1), |
54 ECAT_INIT_SLAVE(Beckhoff_EL4102), |
54 ECAT_INIT_SLAVE(Beckhoff_EL4102, 1), |
55 ECAT_INIT_SLAVE(Beckhoff_EL1014), |
55 ECAT_INIT_SLAVE(Beckhoff_EL1014, 1), |
56 ECAT_INIT_SLAVE(Beckhoff_EL3162), |
56 ECAT_INIT_SLAVE(Beckhoff_EL3162, 1), |
57 ECAT_INIT_SLAVE(Beckhoff_EL2004), |
57 ECAT_INIT_SLAVE(Beckhoff_EL2004, 1), |
58 ECAT_INIT_SLAVE(Beckhoff_EL3102), |
58 ECAT_INIT_SLAVE(Beckhoff_EL3102, 1), |
59 ECAT_INIT_SLAVE(Beckhoff_EL2004), |
59 ECAT_INIT_SLAVE(Beckhoff_EL2004, 1), |
60 ECAT_INIT_SLAVE(Beckhoff_EL2004), |
60 ECAT_INIT_SLAVE(Beckhoff_EL2004, 1), |
61 ECAT_INIT_SLAVE(Beckhoff_EL2004), |
61 ECAT_INIT_SLAVE(Beckhoff_EL2004, 1), |
62 ECAT_INIT_SLAVE(Beckhoff_EL2004), |
62 ECAT_INIT_SLAVE(Beckhoff_EL2004, 1), |
63 ECAT_INIT_SLAVE(Beckhoff_EL2004), |
63 ECAT_INIT_SLAVE(Beckhoff_EL2004, 1), |
64 |
64 |
65 // Block 3 |
65 // Block 3 |
66 ECAT_INIT_SLAVE(Beckhoff_EK1100), |
66 ECAT_INIT_SLAVE(Beckhoff_EK1100, 1), |
67 ECAT_INIT_SLAVE(Beckhoff_EL1014), |
67 ECAT_INIT_SLAVE(Beckhoff_EL1014, 1), |
68 ECAT_INIT_SLAVE(Beckhoff_EL1014), |
68 ECAT_INIT_SLAVE(Beckhoff_EL1014, 1), |
69 ECAT_INIT_SLAVE(Beckhoff_EL1014), |
69 ECAT_INIT_SLAVE(Beckhoff_EL1014, 1), |
70 ECAT_INIT_SLAVE(Beckhoff_EL1014), |
70 ECAT_INIT_SLAVE(Beckhoff_EL1014, 1), |
71 ECAT_INIT_SLAVE(Beckhoff_EL1014), |
71 ECAT_INIT_SLAVE(Beckhoff_EL1014, 1), |
72 ECAT_INIT_SLAVE(Beckhoff_EL2004), |
72 ECAT_INIT_SLAVE(Beckhoff_EL2004, 1), |
73 ECAT_INIT_SLAVE(Beckhoff_EL2004), |
73 ECAT_INIT_SLAVE(Beckhoff_EL2004, 1), |
74 ECAT_INIT_SLAVE(Beckhoff_EL2004), |
74 ECAT_INIT_SLAVE(Beckhoff_EL2004, 1), |
75 ECAT_INIT_SLAVE(Beckhoff_EL2004), |
75 ECAT_INIT_SLAVE(Beckhoff_EL2004, 1), |
76 ECAT_INIT_SLAVE(Beckhoff_EL1014), |
76 ECAT_INIT_SLAVE(Beckhoff_EL1014, 1), |
77 ECAT_INIT_SLAVE(Beckhoff_EL1014), |
77 ECAT_INIT_SLAVE(Beckhoff_EL1014, 1), |
78 ECAT_INIT_SLAVE(Beckhoff_EL1014) |
78 ECAT_INIT_SLAVE(Beckhoff_EL1014, 1) |
79 #endif |
79 #endif |
80 }; |
80 }; |
81 |
81 |
82 #define ECAT_SLAVES_COUNT (sizeof(ecat_slaves) / sizeof(EtherCAT_slave_t)) |
82 #define ECAT_SLAVES_COUNT (sizeof(ecat_slaves) / sizeof(EtherCAT_slave_t)) |
83 |
83 |
222 |
184 |
223 /****************************************************************************** |
185 /****************************************************************************** |
224 * |
186 * |
225 * Function: init |
187 * Function: init |
226 * |
188 * |
227 ******************************************************************************/ |
189 *****************************************************************************/ |
228 |
190 |
229 int __init init_module() |
191 int __init init_module() |
230 { |
192 { |
|
193 unsigned int i; |
|
194 |
231 printk(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n"); |
195 printk(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n"); |
232 |
196 |
233 if ((ecat_master = EtherCAT_request(0)) == NULL) { |
197 if ((ecat_master = EtherCAT_request(0)) == NULL) { |
234 printk(KERN_ERR "EtherCAT master 0 not available!\n"); |
198 printk(KERN_ERR "EtherCAT master 0 not available!\n"); |
235 goto out_return; |
199 goto out_return; |
236 } |
200 } |
237 |
201 |
238 printk("Checking EtherCAT slaves.\n"); |
202 printk("Checking EtherCAT slaves.\n"); |
239 |
203 |
240 if (EtherCAT_check_slaves(ecat_master, ecat_slaves, ECAT_SLAVES_COUNT) != 0) { |
204 if (EtherCAT_check_slaves(ecat_master, ecat_slaves, |
|
205 ECAT_SLAVES_COUNT) != 0) { |
241 printk(KERN_ERR "EtherCAT: Could not init slaves!\n"); |
206 printk(KERN_ERR "EtherCAT: Could not init slaves!\n"); |
242 goto out_release_master; |
207 goto out_release_master; |
243 } |
208 } |
244 |
209 |
245 printk("Activating all EtherCAT slaves.\n"); |
210 printk("Activating all EtherCAT slaves.\n"); |
246 |
211 |
247 if (EtherCAT_activate_all_slaves(ecat_master) != 0) |
212 for (i = 0; i < ECAT_SLAVES_COUNT; i++) { |
248 { |
213 if (EtherCAT_activate_slave(ecat_master, &ecat_slaves[i]) != 0) { |
249 printk(KERN_ERR "EtherCAT: Could not activate slaves!\n"); |
214 printk(KERN_ERR "EtherCAT: Could not activate slave %i!\n", i); |
250 goto out_release_master; |
215 goto out_release_master; |
|
216 } |
251 } |
217 } |
252 |
218 |
253 #ifdef ECAT_CYCLIC_DATA |
219 #ifdef ECAT_CYCLIC_DATA |
254 printk("Starting cyclic sample thread.\n"); |
220 printk("Starting cyclic sample thread.\n"); |
255 |
221 |