44 #include "ethernet.h" |
44 #include "ethernet.h" |
45 |
45 |
46 /*****************************************************************************/ |
46 /*****************************************************************************/ |
47 |
47 |
48 void ec_master_freerun(unsigned long); |
48 void ec_master_freerun(unsigned long); |
|
49 void ec_master_run_eoe(void *); |
49 ssize_t ec_show_master_attribute(struct kobject *, struct attribute *, char *); |
50 ssize_t ec_show_master_attribute(struct kobject *, struct attribute *, char *); |
50 void ec_master_process_watch_command(ec_master_t *); |
51 void ec_master_process_watch_command(ec_master_t *); |
51 |
52 |
52 /*****************************************************************************/ |
53 /*****************************************************************************/ |
53 |
54 |
110 // init freerun timer |
111 // init freerun timer |
111 init_timer(&master->freerun_timer); |
112 init_timer(&master->freerun_timer); |
112 master->freerun_timer.function = ec_master_freerun; |
113 master->freerun_timer.function = ec_master_freerun; |
113 master->freerun_timer.data = (unsigned long) master; |
114 master->freerun_timer.data = (unsigned long) master; |
114 |
115 |
|
116 master->eoe_wq = NULL; |
|
117 INIT_WORK(&master->eoe_work, ec_master_run_eoe, master); |
|
118 |
115 ec_command_init(&master->simple_command); |
119 ec_command_init(&master->simple_command); |
116 ec_command_init(&master->watch_command); |
120 ec_command_init(&master->watch_command); |
117 |
121 |
118 ec_master_reset(master); |
122 ec_master_reset(master); |
119 return 0; |
123 return 0; |
142 kfree(master->device); |
146 kfree(master->device); |
143 } |
147 } |
144 |
148 |
145 ec_command_clear(&master->simple_command); |
149 ec_command_clear(&master->simple_command); |
146 ec_command_clear(&master->watch_command); |
150 ec_command_clear(&master->watch_command); |
|
151 |
|
152 if (master->eoe_wq) destroy_workqueue(master->eoe_wq); |
147 |
153 |
148 EC_INFO("Master %i cleared.\n", master->index); |
154 EC_INFO("Master %i cleared.\n", master->index); |
149 } |
155 } |
150 |
156 |
151 /*****************************************************************************/ |
157 /*****************************************************************************/ |
160 { |
166 { |
161 ec_slave_t *slave, *next_s; |
167 ec_slave_t *slave, *next_s; |
162 ec_command_t *command, *next_c; |
168 ec_command_t *command, *next_c; |
163 ec_domain_t *domain, *next_d; |
169 ec_domain_t *domain, *next_d; |
164 ec_eoe_t *eoe, *next_eoe; |
170 ec_eoe_t *eoe, *next_eoe; |
|
171 |
|
172 // stop EoE processing |
|
173 if (master->eoe_wq && !cancel_delayed_work(&master->eoe_work)) { |
|
174 flush_workqueue(master->eoe_wq); |
|
175 } |
165 |
176 |
166 ec_master_freerun_stop(master); |
177 ec_master_freerun_stop(master); |
167 |
178 |
168 // remove all slaves |
179 // remove all slaves |
169 list_for_each_entry_safe(slave, next_s, &master->slaves, list) { |
180 list_for_each_entry_safe(slave, next_s, &master->slaves, list) { |
483 { |
494 { |
484 ec_slave_t *slave, *next; |
495 ec_slave_t *slave, *next; |
485 ec_slave_ident_t *ident; |
496 ec_slave_ident_t *ident; |
486 unsigned int i; |
497 unsigned int i; |
487 ec_command_t *command; |
498 ec_command_t *command; |
488 ec_eoe_t *eoe; |
|
489 uint16_t coupler_index, coupler_subindex; |
499 uint16_t coupler_index, coupler_subindex; |
490 uint16_t reverse_coupler_index, current_coupler_index; |
500 uint16_t reverse_coupler_index, current_coupler_index; |
491 |
501 |
492 if (!list_empty(&master->slaves)) { |
502 if (!list_empty(&master->slaves)) { |
493 EC_ERR("Slave scan already done!\n"); |
503 EC_ERR("Slave scan already done!\n"); |
568 } |
578 } |
569 |
579 |
570 slave->coupler_index = current_coupler_index; |
580 slave->coupler_index = current_coupler_index; |
571 slave->coupler_subindex = coupler_subindex; |
581 slave->coupler_subindex = coupler_subindex; |
572 coupler_subindex++; |
582 coupler_subindex++; |
573 |
|
574 // does the slave support EoE? |
|
575 if (slave->sii_mailbox_protocols & EC_MBOX_EOE) { |
|
576 if (!(eoe = (ec_eoe_t *) kmalloc(sizeof(ec_eoe_t), GFP_KERNEL))) { |
|
577 EC_ERR("Failed to allocate EoE-Object.\n"); |
|
578 goto out_free; |
|
579 } |
|
580 |
|
581 if (ec_eoe_init(eoe, slave)) { |
|
582 kfree(eoe); |
|
583 goto out_free; |
|
584 } |
|
585 list_add_tail(&eoe->list, &master->eoe_slaves); |
|
586 } |
|
587 } |
583 } |
588 |
584 |
589 return 0; |
585 return 0; |
590 |
586 |
591 out_free: |
587 out_free: |
846 |
842 |
847 /** |
843 /** |
848 Does the Ethernet-over-EtherCAT processing. |
844 Does the Ethernet-over-EtherCAT processing. |
849 */ |
845 */ |
850 |
846 |
851 void ec_master_run_eoe(ec_master_t *master /**< EtherCAT master */) |
847 void ec_master_run_eoe(void *data /**< work data (= master pointer) */) |
852 { |
848 { |
|
849 ec_master_t *master = (ec_master_t *) data; |
|
850 |
|
851 #if 0 |
853 ec_eoe_t *eoe; |
852 ec_eoe_t *eoe; |
854 |
853 |
855 list_for_each_entry(eoe, &master->eoe_slaves, list) { |
854 list_for_each_entry(eoe, &master->eoe_slaves, list) { |
856 ec_eoe_run(eoe); |
855 ec_eoe_run(eoe); |
857 } |
856 } |
|
857 #endif |
|
858 |
|
859 queue_delayed_work(master->eoe_wq, &master->eoe_work, HZ); |
858 } |
860 } |
859 |
861 |
860 /****************************************************************************** |
862 /****************************************************************************** |
861 * Realtime interface |
863 * Realtime interface |
862 *****************************************************************************/ |
864 *****************************************************************************/ |
1296 ec_master_output_stats(master); |
1298 ec_master_output_stats(master); |
1297 |
1299 |
1298 // watchdog command |
1300 // watchdog command |
1299 ec_master_process_watch_command(master); |
1301 ec_master_process_watch_command(master); |
1300 ec_master_queue_command(master, &master->watch_command); |
1302 ec_master_queue_command(master, &master->watch_command); |
1301 |
|
1302 // Ethernet-over-EtherCAT |
|
1303 ec_master_run_eoe(master); |
|
1304 } |
1303 } |
1305 |
1304 |
1306 /*****************************************************************************/ |
1305 /*****************************************************************************/ |
1307 |
1306 |
1308 /** |
1307 /** |
1430 } |
1429 } |
1431 |
1430 |
1432 /*****************************************************************************/ |
1431 /*****************************************************************************/ |
1433 |
1432 |
1434 /** |
1433 /** |
|
1434 Starts Ethernet-over-EtherCAT processing for all EoE-capable slaves. |
|
1435 \ingroup RealtimeInterface |
|
1436 */ |
|
1437 |
|
1438 int ecrt_master_start_eoe(ec_master_t *master /**< EtherCAT master */) |
|
1439 { |
|
1440 ec_eoe_t *eoe; |
|
1441 ec_slave_t *slave; |
|
1442 |
|
1443 if (!master->request_cb || !master->release_cb) { |
|
1444 EC_ERR("EoE requires master callbacks to be set!\n"); |
|
1445 return -1; |
|
1446 } |
|
1447 |
|
1448 list_for_each_entry(slave, &master->slaves, list) { |
|
1449 // does the slave support EoE? |
|
1450 if (!(slave->sii_mailbox_protocols & EC_MBOX_EOE)) continue; |
|
1451 |
|
1452 if (!(eoe = (ec_eoe_t *) kmalloc(sizeof(ec_eoe_t), GFP_KERNEL))) { |
|
1453 EC_ERR("Failed to allocate EoE-Object.\n"); |
|
1454 return -1; |
|
1455 } |
|
1456 if (ec_eoe_init(eoe, slave)) { |
|
1457 kfree(eoe); |
|
1458 return -1; |
|
1459 } |
|
1460 list_add_tail(&eoe->list, &master->eoe_slaves); |
|
1461 } |
|
1462 |
|
1463 if (list_empty(&master->eoe_slaves)) { |
|
1464 EC_WARN("start_eoe: no EoE-capable slaves present.\n"); |
|
1465 return 0; |
|
1466 } |
|
1467 |
|
1468 // create the EoE workqueue, if necessary |
|
1469 if (!master->eoe_wq) { |
|
1470 if (!(master->eoe_wq = create_singlethread_workqueue("eoework"))) { |
|
1471 EC_ERR("Failed to create EoE workqueue!\n"); |
|
1472 return -1; |
|
1473 } |
|
1474 } |
|
1475 |
|
1476 // start EoE processing |
|
1477 queue_work(master->eoe_wq, &master->eoe_work); |
|
1478 return 0; |
|
1479 } |
|
1480 |
|
1481 /*****************************************************************************/ |
|
1482 |
|
1483 /** |
1435 Sets the debug level of the master. |
1484 Sets the debug level of the master. |
1436 The following levels are valid: |
1485 The following levels are valid: |
1437 - 1: only output positions marks and basic data |
1486 - 1: only output positions marks and basic data |
1438 - 2: additional frame data output |
1487 - 2: additional frame data output |
1439 \ingroup RealtimeInterface |
1488 \ingroup RealtimeInterface |
1493 EXPORT_SYMBOL(ecrt_master_prepare_async_io); |
1542 EXPORT_SYMBOL(ecrt_master_prepare_async_io); |
1494 EXPORT_SYMBOL(ecrt_master_sync_io); |
1543 EXPORT_SYMBOL(ecrt_master_sync_io); |
1495 EXPORT_SYMBOL(ecrt_master_async_send); |
1544 EXPORT_SYMBOL(ecrt_master_async_send); |
1496 EXPORT_SYMBOL(ecrt_master_async_receive); |
1545 EXPORT_SYMBOL(ecrt_master_async_receive); |
1497 EXPORT_SYMBOL(ecrt_master_run); |
1546 EXPORT_SYMBOL(ecrt_master_run); |
|
1547 EXPORT_SYMBOL(ecrt_master_callbacks); |
|
1548 EXPORT_SYMBOL(ecrt_master_start_eoe); |
1498 EXPORT_SYMBOL(ecrt_master_debug); |
1549 EXPORT_SYMBOL(ecrt_master_debug); |
1499 EXPORT_SYMBOL(ecrt_master_print); |
1550 EXPORT_SYMBOL(ecrt_master_print); |
1500 EXPORT_SYMBOL(ecrt_master_get_slave); |
1551 EXPORT_SYMBOL(ecrt_master_get_slave); |
1501 |
1552 |
1502 /** \endcond */ |
1553 /** \endcond */ |