equal
deleted
inserted
replaced
39 #include "../../include/ecrt.h" // EtherCAT realtime interface |
39 #include "../../include/ecrt.h" // EtherCAT realtime interface |
40 #include "../../include/ecdb.h" // EtherCAT slave database |
40 #include "../../include/ecdb.h" // EtherCAT slave database |
41 |
41 |
42 /*****************************************************************************/ |
42 /*****************************************************************************/ |
43 |
43 |
44 // module parameters |
44 // Module parameters |
45 #define FREQUENCY 100 |
45 #define FREQUENCY 100 |
|
46 |
|
47 // Optional features |
46 #define CONFIGURE_MAPPING |
48 #define CONFIGURE_MAPPING |
47 #define EXTERNAL_MEMORY |
49 #define EXTERNAL_MEMORY |
|
50 #define SDO_ACCESS |
48 |
51 |
49 #define PFX "ec_mini: " |
52 #define PFX "ec_mini: " |
50 |
53 |
51 /*****************************************************************************/ |
54 /*****************************************************************************/ |
52 |
55 |
110 }; |
113 }; |
111 #endif |
114 #endif |
112 |
115 |
113 /*****************************************************************************/ |
116 /*****************************************************************************/ |
114 |
117 |
|
118 #ifdef SDO_ACCESS |
|
119 static ec_sdo_request_t *sdo; |
|
120 static int not_first_time = 0; |
|
121 #endif |
|
122 |
|
123 /*****************************************************************************/ |
|
124 |
115 void check_domain1_state(void) |
125 void check_domain1_state(void) |
116 { |
126 { |
117 ec_domain_state_t ds; |
127 ec_domain_state_t ds; |
118 |
128 |
119 ecrt_domain_state(domain1, &ds); |
129 ecrt_domain_state(domain1, &ds); |
150 ms.slaves_responding); |
160 ms.slaves_responding); |
151 } |
161 } |
152 |
162 |
153 master_state = ms; |
163 master_state = ms; |
154 } |
164 } |
|
165 |
|
166 /*****************************************************************************/ |
|
167 |
|
168 #ifdef SDO_ACCESS |
|
169 void read_sdo(void) |
|
170 { |
|
171 switch (ecrt_sdo_request_state(sdo)) { |
|
172 case EC_REQUEST_COMPLETE: |
|
173 if (not_first_time) { |
|
174 printk(KERN_INFO PFX "Sdo value: 0x%04X\n", |
|
175 EC_READ_U16(ecrt_sdo_request_data(sdo))); |
|
176 } else { |
|
177 not_first_time = 1; |
|
178 } |
|
179 ecrt_sdo_request_read(sdo); |
|
180 break; |
|
181 case EC_REQUEST_FAILURE: |
|
182 printk(KERN_INFO PFX "Failed to read Sdo!\n"); |
|
183 ecrt_sdo_request_read(sdo); |
|
184 break; |
|
185 default: |
|
186 printk(KERN_INFO PFX "Still busy...\n"); |
|
187 break; |
|
188 } |
|
189 } |
|
190 #endif |
155 |
191 |
156 /*****************************************************************************/ |
192 /*****************************************************************************/ |
157 |
193 |
158 void cyclic_task(unsigned long data) |
194 void cyclic_task(unsigned long data) |
159 { |
195 { |
166 // check process data state (optional) |
202 // check process data state (optional) |
167 check_domain1_state(); |
203 check_domain1_state(); |
168 |
204 |
169 if (counter) { |
205 if (counter) { |
170 counter--; |
206 counter--; |
171 } else { // do this at FREQUENCY |
207 } else { // do this at 1 Hz |
172 counter = FREQUENCY; |
208 counter = FREQUENCY; |
173 |
209 |
174 // calculate new process data |
210 // calculate new process data |
175 blink = !blink; |
211 blink = !blink; |
176 |
212 |
177 // check for master state (optional) |
213 // check for master state (optional) |
178 check_master_state(); |
214 check_master_state(); |
|
215 |
|
216 #ifdef SDO_ACCESS |
|
217 // read process data Sdo |
|
218 read_sdo(); |
|
219 #endif |
179 } |
220 } |
180 |
221 |
181 // write process data |
222 // write process data |
182 EC_WRITE_U8(domain1_pd + off_dig_out, blink ? 0x06 : 0x09); |
223 EC_WRITE_U8(domain1_pd + off_dig_out, blink ? 0x06 : 0x09); |
183 |
224 |
250 goto out_release_master; |
291 goto out_release_master; |
251 } |
292 } |
252 |
293 |
253 if (ecrt_slave_config_mapping(sc, 4, el2004_mapping)) { |
294 if (ecrt_slave_config_mapping(sc, 4, el2004_mapping)) { |
254 printk(KERN_ERR PFX "Failed to configure Pdo mapping.\n"); |
295 printk(KERN_ERR PFX "Failed to configure Pdo mapping.\n"); |
|
296 goto out_release_master; |
|
297 } |
|
298 #endif |
|
299 |
|
300 #ifdef SDO_ACCESS |
|
301 printk(KERN_INFO PFX "Creating Sdo requests...\n"); |
|
302 if (!(sc = ecrt_master_slave_config(master, 0, 1, Beckhoff_EL3162))) { |
|
303 printk(KERN_ERR PFX "Failed to get slave configuration.\n"); |
|
304 goto out_release_master; |
|
305 } |
|
306 |
|
307 if (!(sdo = ecrt_slave_config_create_sdo_request(sc, 0x3102, 2, 2))) { |
|
308 printk(KERN_ERR PFX "Failed to create Sdo request.\n"); |
255 goto out_release_master; |
309 goto out_release_master; |
256 } |
310 } |
257 #endif |
311 #endif |
258 |
312 |
259 printk(KERN_INFO PFX "Registering Pdo entries...\n"); |
313 printk(KERN_INFO PFX "Registering Pdo entries...\n"); |