23 #include "command.h" |
23 #include "command.h" |
24 #include "ethernet.h" |
24 #include "ethernet.h" |
25 |
25 |
26 /*****************************************************************************/ |
26 /*****************************************************************************/ |
27 |
27 |
|
28 void ec_master_freerun(unsigned long); |
28 ssize_t ec_show_master_attribute(struct kobject *, struct attribute *, char *); |
29 ssize_t ec_show_master_attribute(struct kobject *, struct attribute *, char *); |
29 |
30 |
30 /*****************************************************************************/ |
31 /*****************************************************************************/ |
31 |
32 |
32 EC_SYSFS_READ_ATTR(slave_count); |
33 EC_SYSFS_READ_ATTR(slave_count); |
|
34 EC_SYSFS_READ_ATTR(mode); |
33 |
35 |
34 static struct attribute *ec_def_attrs[] = { |
36 static struct attribute *ec_def_attrs[] = { |
35 &attr_slave_count, |
37 &attr_slave_count, |
|
38 &attr_mode, |
36 NULL, |
39 NULL, |
37 }; |
40 }; |
38 |
41 |
39 static struct sysfs_ops ec_sysfs_ops = { |
42 static struct sysfs_ops ec_sysfs_ops = { |
40 .show = &ec_show_master_attribute, |
43 .show = &ec_show_master_attribute, |
76 EC_ERR("Failed to set kobj name.\n"); |
79 EC_ERR("Failed to set kobj name.\n"); |
77 kobject_put(&master->kobj); |
80 kobject_put(&master->kobj); |
78 return -1; |
81 return -1; |
79 } |
82 } |
80 |
83 |
|
84 // Init freerun timer |
|
85 init_timer(&master->freerun_timer); |
|
86 master->freerun_timer.function = ec_master_freerun; |
|
87 master->freerun_timer.data = (unsigned long) master; |
|
88 |
81 ec_command_init(&master->simple_command); |
89 ec_command_init(&master->simple_command); |
82 ec_command_init(&master->watch_command); |
90 ec_command_init(&master->watch_command); |
83 |
91 |
84 ec_master_reset(master); |
92 ec_master_reset(master); |
85 return 0; |
93 return 0; |
97 void ec_master_clear(struct kobject *kobj /**< KObject des Masters */) |
105 void ec_master_clear(struct kobject *kobj /**< KObject des Masters */) |
98 { |
106 { |
99 ec_master_t *master = container_of(kobj, ec_master_t, kobj); |
107 ec_master_t *master = container_of(kobj, ec_master_t, kobj); |
100 |
108 |
101 EC_INFO("Clearing master %i...\n", master->index); |
109 EC_INFO("Clearing master %i...\n", master->index); |
|
110 |
|
111 del_timer_sync(&master->freerun_timer); |
102 |
112 |
103 ec_master_reset(master); |
113 ec_master_reset(master); |
104 |
114 |
105 if (master->device) { |
115 if (master->device) { |
106 ec_device_clear(master->device); |
116 ec_device_clear(master->device); |
128 { |
138 { |
129 ec_slave_t *slave, *next_s; |
139 ec_slave_t *slave, *next_s; |
130 ec_command_t *command, *next_c; |
140 ec_command_t *command, *next_c; |
131 ec_domain_t *domain, *next_d; |
141 ec_domain_t *domain, *next_d; |
132 ec_eoe_t *eoe, *next_eoe; |
142 ec_eoe_t *eoe, *next_eoe; |
|
143 |
|
144 ec_master_freerun_stop(master); |
133 |
145 |
134 // Alle Slaves entfernen |
146 // Alle Slaves entfernen |
135 list_for_each_entry_safe(slave, next_s, &master->slaves, list) { |
147 list_for_each_entry_safe(slave, next_s, &master->slaves, list) { |
136 list_del(&slave->list); |
148 list_del(&slave->list); |
137 kobject_del(&slave->kobj); |
149 kobject_del(&slave->kobj); |
170 master->stats.delayed = 0; |
182 master->stats.delayed = 0; |
171 master->stats.corrupted = 0; |
183 master->stats.corrupted = 0; |
172 master->stats.unmatched = 0; |
184 master->stats.unmatched = 0; |
173 master->stats.eoe_errors = 0; |
185 master->stats.eoe_errors = 0; |
174 master->stats.t_last = 0; |
186 master->stats.t_last = 0; |
|
187 |
|
188 master->mode = EC_MASTER_MODE_IDLE; |
175 } |
189 } |
176 |
190 |
177 /*****************************************************************************/ |
191 /*****************************************************************************/ |
178 |
192 |
179 /** |
193 /** |
599 EC_WARN("%i EOE ERROR(S)!\n", master->stats.eoe_errors); |
613 EC_WARN("%i EOE ERROR(S)!\n", master->stats.eoe_errors); |
600 master->stats.eoe_errors = 0; |
614 master->stats.eoe_errors = 0; |
601 } |
615 } |
602 master->stats.t_last = t_now; |
616 master->stats.t_last = t_now; |
603 } |
617 } |
|
618 } |
|
619 |
|
620 /*****************************************************************************/ |
|
621 |
|
622 /** |
|
623 Starts Free-Run mode. |
|
624 */ |
|
625 |
|
626 void ec_master_freerun_start(ec_master_t *master /**< EtherCAT master */) |
|
627 { |
|
628 if (master->mode == EC_MASTER_MODE_FREERUN) return; |
|
629 |
|
630 if (master->mode == EC_MASTER_MODE_RUNNING) { |
|
631 EC_ERR("ec_master_freerun_start: Master already running!\n"); |
|
632 return; |
|
633 } |
|
634 |
|
635 EC_INFO("Starting Free-Run mode.\n"); |
|
636 |
|
637 master->mode = EC_MASTER_MODE_FREERUN; |
|
638 |
|
639 master->freerun_timer.expires = jiffies + 10; |
|
640 add_timer(&master->freerun_timer); |
|
641 } |
|
642 |
|
643 /*****************************************************************************/ |
|
644 |
|
645 /** |
|
646 Stops Free-Run mode. |
|
647 */ |
|
648 |
|
649 void ec_master_freerun_stop(ec_master_t *master /**< EtherCAT master */) |
|
650 { |
|
651 if (master->mode != EC_MASTER_MODE_FREERUN) return; |
|
652 |
|
653 EC_INFO("Stopping Free-Run mode.\n"); |
|
654 |
|
655 del_timer_sync(&master->freerun_timer); |
|
656 master->mode = EC_MASTER_MODE_IDLE; |
|
657 } |
|
658 |
|
659 /*****************************************************************************/ |
|
660 |
|
661 /** |
|
662 Free-Run mode function. |
|
663 */ |
|
664 |
|
665 void ec_master_freerun(unsigned long data) |
|
666 { |
|
667 ec_master_t *master = (ec_master_t *) data; |
|
668 |
|
669 // nop |
|
670 |
|
671 master->freerun_timer.expires += HZ; |
|
672 add_timer(&master->freerun_timer); |
604 } |
673 } |
605 |
674 |
606 /*****************************************************************************/ |
675 /*****************************************************************************/ |
607 |
676 |
608 /** |
677 /** |
793 ec_master_t *master = container_of(kobj, ec_master_t, kobj); |
862 ec_master_t *master = container_of(kobj, ec_master_t, kobj); |
794 |
863 |
795 if (attr == &attr_slave_count) { |
864 if (attr == &attr_slave_count) { |
796 return sprintf(buffer, "%i\n", master->slave_count); |
865 return sprintf(buffer, "%i\n", master->slave_count); |
797 } |
866 } |
|
867 else if (attr == &attr_mode) { |
|
868 switch (master->mode) { |
|
869 case EC_MASTER_MODE_IDLE: |
|
870 return sprintf(buffer, "IDLE\n"); |
|
871 case EC_MASTER_MODE_FREERUN: |
|
872 return sprintf(buffer, "FREERUN\n"); |
|
873 case EC_MASTER_MODE_RUNNING: |
|
874 return sprintf(buffer, "RUNNING\n"); |
|
875 } |
|
876 } |
798 |
877 |
799 return 0; |
878 return 0; |
800 } |
879 } |
801 |
880 |
802 /*****************************************************************************/ |
881 /*****************************************************************************/ |