48 #define EXTERNAL_MEMORY |
48 #define EXTERNAL_MEMORY |
49 #define SDO_ACCESS |
49 #define SDO_ACCESS |
50 |
50 |
51 #define PFX "ec_mini: " |
51 #define PFX "ec_mini: " |
52 |
52 |
|
53 #define AnaInPos 0, 5 |
|
54 #define DigOutPos 0, 3 |
|
55 |
53 /*****************************************************************************/ |
56 /*****************************************************************************/ |
54 |
57 |
55 // EtherCAT |
58 // EtherCAT |
56 static ec_master_t *master = NULL; |
59 static ec_master_t *master = NULL; |
57 static ec_master_state_t master_state = {}; |
60 static ec_master_state_t master_state = {}; |
78 |
81 |
79 #define Beckhoff_EL2004 0x00000002, 0x07D43052 |
82 #define Beckhoff_EL2004 0x00000002, 0x07D43052 |
80 #define Beckhoff_EL3162 0x00000002, 0x0C5A3052 |
83 #define Beckhoff_EL3162 0x00000002, 0x0C5A3052 |
81 |
84 |
82 const static ec_pdo_entry_reg_t domain1_regs[] = { |
85 const static ec_pdo_entry_reg_t domain1_regs[] = { |
83 {0, 1, Beckhoff_EL3162, 0x3101, 2, &off_ana_in}, |
86 {AnaInPos, Beckhoff_EL3162, 0x3101, 2, &off_ana_in}, |
84 {0, 3, Beckhoff_EL2004, 0x3001, 1, &off_dig_out}, |
87 {DigOutPos, Beckhoff_EL2004, 0x3001, 1, &off_dig_out}, |
85 {} |
88 {} |
86 }; |
89 }; |
87 |
90 |
88 /*****************************************************************************/ |
91 /*****************************************************************************/ |
89 |
92 |
114 static ec_pdo_info_t el2004_pdos[] = { |
117 static ec_pdo_info_t el2004_pdos[] = { |
115 {EC_DIR_OUTPUT, 0x1600, 1, &el2004_channels[0]}, |
118 {EC_DIR_OUTPUT, 0x1600, 1, &el2004_channels[0]}, |
116 {EC_DIR_OUTPUT, 0x1601, 1, &el2004_channels[1]}, |
119 {EC_DIR_OUTPUT, 0x1601, 1, &el2004_channels[1]}, |
117 {EC_DIR_OUTPUT, 0x1602, 1, &el2004_channels[2]}, |
120 {EC_DIR_OUTPUT, 0x1602, 1, &el2004_channels[2]}, |
118 {EC_DIR_OUTPUT, 0x1603, 1, &el2004_channels[3]}, |
121 {EC_DIR_OUTPUT, 0x1603, 1, &el2004_channels[3]}, |
|
122 {EC_END} |
119 }; |
123 }; |
120 #endif |
124 #endif |
121 |
125 |
122 /*****************************************************************************/ |
126 /*****************************************************************************/ |
123 |
127 |
189 #ifdef SDO_ACCESS |
193 #ifdef SDO_ACCESS |
190 void read_sdo(void) |
194 void read_sdo(void) |
191 { |
195 { |
192 switch (ecrt_sdo_request_state(sdo)) { |
196 switch (ecrt_sdo_request_state(sdo)) { |
193 case EC_SDO_REQUEST_UNUSED: // request was not used yet |
197 case EC_SDO_REQUEST_UNUSED: // request was not used yet |
194 ecrt_sdo_request_timeout(sdo, 500); // ms |
|
195 ecrt_sdo_request_read(sdo); // trigger first read |
198 ecrt_sdo_request_read(sdo); // trigger first read |
196 break; |
199 break; |
197 case EC_SDO_REQUEST_BUSY: |
200 case EC_SDO_REQUEST_BUSY: |
198 printk(KERN_INFO PFX "Still busy...\n"); |
201 printk(KERN_INFO PFX "Still busy...\n"); |
199 break; |
202 break; |
297 printk(KERN_ERR PFX "Domain creation failed!\n"); |
300 printk(KERN_ERR PFX "Domain creation failed!\n"); |
298 goto out_release_master; |
301 goto out_release_master; |
299 } |
302 } |
300 |
303 |
301 if (!(sc_ana_in = ecrt_master_slave_config( |
304 if (!(sc_ana_in = ecrt_master_slave_config( |
302 master, 0, 1, Beckhoff_EL3162))) { |
305 master, AnaInPos, Beckhoff_EL3162))) { |
303 printk(KERN_ERR PFX "Failed to get slave configuration.\n"); |
306 printk(KERN_ERR PFX "Failed to get slave configuration.\n"); |
304 goto out_release_master; |
307 goto out_release_master; |
305 } |
308 } |
306 |
309 |
307 #ifdef CONFIGURE_PDOS |
310 #ifdef CONFIGURE_PDOS |
309 if (ecrt_slave_config_pdos(sc_ana_in, EC_END, el3162_pdos)) { |
312 if (ecrt_slave_config_pdos(sc_ana_in, EC_END, el3162_pdos)) { |
310 printk(KERN_ERR PFX "Failed to configure Pdos.\n"); |
313 printk(KERN_ERR PFX "Failed to configure Pdos.\n"); |
311 goto out_release_master; |
314 goto out_release_master; |
312 } |
315 } |
313 |
316 |
314 if (!(sc = ecrt_master_slave_config(master, 0, 3, Beckhoff_EL2004))) { |
317 if (!(sc = ecrt_master_slave_config(master, DigOutPos, Beckhoff_EL2004))) { |
315 printk(KERN_ERR PFX "Failed to get slave configuration.\n"); |
318 printk(KERN_ERR PFX "Failed to get slave configuration.\n"); |
316 goto out_release_master; |
319 goto out_release_master; |
317 } |
320 } |
318 |
321 |
319 if (ecrt_slave_config_pdos(sc, 4, el2004_pdos)) { |
322 if (ecrt_slave_config_pdos(sc, EC_END, el2004_pdos)) { |
320 printk(KERN_ERR PFX "Failed to configure Pdos.\n"); |
323 printk(KERN_ERR PFX "Failed to configure Pdos.\n"); |
321 goto out_release_master; |
324 goto out_release_master; |
322 } |
325 } |
323 #endif |
326 #endif |
324 |
327 |
325 #ifdef SDO_ACCESS |
328 #ifdef SDO_ACCESS |
326 printk(KERN_INFO PFX "Creating Sdo requests...\n"); |
329 printk(KERN_INFO PFX "Creating Sdo requests...\n"); |
327 if (!(sc = ecrt_master_slave_config(master, 0, 1, Beckhoff_EL3162))) { |
330 if (!(sdo = ecrt_slave_config_create_sdo_request(sc_ana_in, 0x3102, 2, 2))) { |
328 printk(KERN_ERR PFX "Failed to get slave configuration.\n"); |
|
329 goto out_release_master; |
|
330 } |
|
331 |
|
332 if (!(sdo = ecrt_slave_config_create_sdo_request(sc, 0x3102, 2, 2))) { |
|
333 printk(KERN_ERR PFX "Failed to create Sdo request.\n"); |
331 printk(KERN_ERR PFX "Failed to create Sdo request.\n"); |
334 goto out_release_master; |
332 goto out_release_master; |
335 } |
333 } |
|
334 ecrt_sdo_request_timeout(sdo, 500); // ms |
336 #endif |
335 #endif |
337 |
336 |
338 printk(KERN_INFO PFX "Registering Pdo entries...\n"); |
337 printk(KERN_INFO PFX "Registering Pdo entries...\n"); |
339 if (ecrt_domain_reg_pdo_entry_list(domain1, domain1_regs)) { |
338 if (ecrt_domain_reg_pdo_entry_list(domain1, domain1_regs)) { |
340 printk(KERN_ERR PFX "Pdo entry registration failed!\n"); |
339 printk(KERN_ERR PFX "Pdo entry registration failed!\n"); |