226 * |
226 * |
227 ******************************************************************************/ |
227 ******************************************************************************/ |
228 |
228 |
229 int __init init_module() |
229 int __init init_module() |
230 { |
230 { |
231 printk(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n"); |
231 printk(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n"); |
232 |
232 |
233 if ((ecat_master = EtherCAT_request(0)) == NULL) |
233 if ((ecat_master = EtherCAT_request(0)) == NULL) { |
234 { |
234 printk(KERN_ERR "EtherCAT master 0 not available!\n"); |
235 printk(KERN_ERR "EtherCAT master 0 not available!\n"); |
235 goto out_return; |
236 return -1; |
236 } |
237 } |
237 |
238 |
238 printk("Checking EtherCAT slaves.\n"); |
239 printk("Checking EtherCAT slaves.\n"); |
239 |
240 |
240 if (EtherCAT_check_slaves(ecat_master, ecat_slaves, ECAT_SLAVES_COUNT) != 0) { |
241 if (EtherCAT_check_slaves(ecat_master, ecat_slaves, ECAT_SLAVES_COUNT) != 0) |
241 printk(KERN_ERR "EtherCAT: Could not init slaves!\n"); |
242 { |
242 goto out_release_master; |
243 printk(KERN_ERR "EtherCAT: Could not init slaves!\n"); |
243 } |
244 return -1; |
244 |
245 } |
245 printk("Activating all EtherCAT slaves.\n"); |
246 |
246 |
247 printk("Activating all EtherCAT slaves.\n"); |
247 if (EtherCAT_activate_all_slaves(ecat_master) != 0) |
248 |
248 { |
249 if (EtherCAT_activate_all_slaves(ecat_master) != 0) |
249 printk(KERN_ERR "EtherCAT: Could not activate slaves!\n"); |
250 { |
250 goto out_release_master; |
251 printk(KERN_ERR "EtherCAT: Could not activate slaves!\n"); |
251 } |
252 return -1; |
252 |
253 } |
253 #ifdef ECAT_CYCLIC_DATA |
254 |
254 printk("Starting cyclic sample thread.\n"); |
255 #ifdef ECAT_CYCLIC_DATA |
255 |
256 printk("Starting cyclic sample thread.\n"); |
256 init_timer(&timer); |
257 |
257 |
258 init_timer(&timer); |
258 timer.function = run; |
259 |
259 timer.data = 0; |
260 timer.function = run; |
260 timer.expires = jiffies+10; // Das erste Mal sofort feuern |
261 timer.data = 0; |
261 last_start_jiffies = timer.expires; |
262 timer.expires = jiffies+10; // Das erste Mal sofort feuern |
262 add_timer(&timer); |
263 last_start_jiffies = timer.expires; |
263 |
264 add_timer(&timer); |
264 printk("Initialised sample thread.\n"); |
265 |
265 #endif |
266 printk("Initialised sample thread.\n"); |
266 |
267 #endif |
267 printk(KERN_INFO "=== Minimal EtherCAT environment started. ===\n"); |
268 |
268 |
269 printk(KERN_INFO "=== Minimal EtherCAT environment started. ===\n"); |
269 return 0; |
270 |
270 |
271 return 0; |
271 out_release_master: |
|
272 EtherCAT_release(ecat_master); |
|
273 |
|
274 out_return: |
|
275 return -1; |
272 } |
276 } |
273 |
277 |
274 /****************************************************************************** |
278 /****************************************************************************** |
275 * |
279 * |
276 * Function: cleanup |
280 * Function: cleanup |
282 printk(KERN_INFO "=== Stopping Minimal EtherCAT environment... ===\n"); |
286 printk(KERN_INFO "=== Stopping Minimal EtherCAT environment... ===\n"); |
283 |
287 |
284 if (ecat_master) |
288 if (ecat_master) |
285 { |
289 { |
286 #ifdef ECAT_CYCLIC_DATA |
290 #ifdef ECAT_CYCLIC_DATA |
287 del_timer_sync(&timer); |
291 del_timer_sync(&timer); |
288 EtherCAT_clear_process_data(ecat_master); |
292 EtherCAT_clear_process_data(ecat_master); |
289 #endif // ECAT_CYCLIC_DATA |
293 #endif // ECAT_CYCLIC_DATA |
290 |
294 |
291 printk(KERN_INFO "Deactivating slaves.\n"); |
295 printk(KERN_INFO "Deactivating slaves.\n"); |
292 EtherCAT_deactivate_all_slaves(ecat_master); |
296 EtherCAT_deactivate_all_slaves(ecat_master); |
293 |
297 |
294 EtherCAT_release(ecat_master); |
298 EtherCAT_release(ecat_master); |
295 } |
299 } |
296 |
300 |
297 printk(KERN_INFO "=== Minimal EtherCAT environment stopped. ===\n"); |
301 printk(KERN_INFO "=== Minimal EtherCAT environment stopped. ===\n"); |
298 } |
302 } |
299 |
303 |