41 /*****************************************************************************/ |
41 /*****************************************************************************/ |
42 |
42 |
43 // Module parameters |
43 // Module parameters |
44 #define FREQUENCY 100 |
44 #define FREQUENCY 100 |
45 |
45 |
46 // Optional features |
46 // Optional features (comment to disable) |
47 #define CONFIGURE_PDOS |
47 #define CONFIGURE_PDOS |
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 |
|
53 #define AnaInPos 0, 1 |
|
54 #define DigOutPos 0, 3 |
|
55 |
52 |
56 /*****************************************************************************/ |
53 /*****************************************************************************/ |
57 |
54 |
58 // EtherCAT |
55 // EtherCAT |
59 static ec_master_t *master = NULL; |
56 static ec_master_t *master = NULL; |
64 static ec_domain_state_t domain1_state = {}; |
61 static ec_domain_state_t domain1_state = {}; |
65 |
62 |
66 static ec_slave_config_t *sc_ana_in = NULL; |
63 static ec_slave_config_t *sc_ana_in = NULL; |
67 static ec_slave_config_state_t sc_ana_in_state = {}; |
64 static ec_slave_config_state_t sc_ana_in_state = {}; |
68 |
65 |
|
66 // Timer |
69 static struct timer_list timer; |
67 static struct timer_list timer; |
70 static unsigned int counter = 0; |
|
71 |
68 |
72 /*****************************************************************************/ |
69 /*****************************************************************************/ |
73 |
70 |
74 // process data |
71 // process data |
75 static uint8_t *domain1_pd; // process data memory |
72 static uint8_t *domain1_pd; // process data memory |
76 |
73 |
|
74 #define AnaInSlavePos 0, 1 |
|
75 #define DigOutSlavePos 0, 3 |
|
76 |
|
77 #define Beckhoff_EL2004 0x00000002, 0x07D43052 |
|
78 #define Beckhoff_EL3162 0x00000002, 0x0C5A3052 |
|
79 |
77 static unsigned int off_ana_in; // offsets for Pdo entries |
80 static unsigned int off_ana_in; // offsets for Pdo entries |
78 static unsigned int off_dig_out; |
81 static unsigned int off_dig_out; |
79 |
82 |
|
83 const static ec_pdo_entry_reg_t domain1_regs[] = { |
|
84 {AnaInSlavePos, Beckhoff_EL3162, 0x3101, 2, &off_ana_in}, |
|
85 {DigOutSlavePos, Beckhoff_EL2004, 0x3001, 1, &off_dig_out}, |
|
86 {} |
|
87 }; |
|
88 |
|
89 static unsigned int counter = 0; |
80 static unsigned int blink = 0; |
90 static unsigned int blink = 0; |
81 |
|
82 #define Beckhoff_EL2004 0x00000002, 0x07D43052 |
|
83 #define Beckhoff_EL3162 0x00000002, 0x0C5A3052 |
|
84 |
|
85 const static ec_pdo_entry_reg_t domain1_regs[] = { |
|
86 {AnaInPos, Beckhoff_EL3162, 0x3101, 2, &off_ana_in}, |
|
87 {DigOutPos, Beckhoff_EL2004, 0x3001, 1, &off_dig_out}, |
|
88 {} |
|
89 }; |
|
90 |
91 |
91 /*****************************************************************************/ |
92 /*****************************************************************************/ |
92 |
93 |
93 #ifdef CONFIGURE_PDOS |
94 #ifdef CONFIGURE_PDOS |
94 static ec_pdo_entry_info_t el3162_channel1[] = { |
95 static ec_pdo_entry_info_t el3162_channel1[] = { |
310 printk(KERN_ERR PFX "Domain creation failed!\n"); |
311 printk(KERN_ERR PFX "Domain creation failed!\n"); |
311 goto out_release_master; |
312 goto out_release_master; |
312 } |
313 } |
313 |
314 |
314 if (!(sc_ana_in = ecrt_master_slave_config( |
315 if (!(sc_ana_in = ecrt_master_slave_config( |
315 master, AnaInPos, Beckhoff_EL3162))) { |
316 master, AnaInSlavePos, Beckhoff_EL3162))) { |
316 printk(KERN_ERR PFX "Failed to get slave configuration.\n"); |
317 printk(KERN_ERR PFX "Failed to get slave configuration.\n"); |
317 goto out_release_master; |
318 goto out_release_master; |
318 } |
319 } |
319 |
320 |
320 #ifdef CONFIGURE_PDOS |
321 #ifdef CONFIGURE_PDOS |
322 if (ecrt_slave_config_sync_managers(sc_ana_in, EC_END, el3162_syncs)) { |
323 if (ecrt_slave_config_sync_managers(sc_ana_in, EC_END, el3162_syncs)) { |
323 printk(KERN_ERR PFX "Failed to configure Pdos.\n"); |
324 printk(KERN_ERR PFX "Failed to configure Pdos.\n"); |
324 goto out_release_master; |
325 goto out_release_master; |
325 } |
326 } |
326 |
327 |
327 if (!(sc = ecrt_master_slave_config(master, DigOutPos, Beckhoff_EL2004))) { |
328 if (!(sc = ecrt_master_slave_config( |
|
329 master, DigOutSlavePos, Beckhoff_EL2004))) { |
328 printk(KERN_ERR PFX "Failed to get slave configuration.\n"); |
330 printk(KERN_ERR PFX "Failed to get slave configuration.\n"); |
329 goto out_release_master; |
331 goto out_release_master; |
330 } |
332 } |
331 |
333 |
332 if (ecrt_slave_config_sync_managers(sc, EC_END, el2004_syncs)) { |
334 if (ecrt_slave_config_sync_managers(sc, EC_END, el2004_syncs)) { |