50 static struct ipipe_domain this_domain; |
50 static struct ipipe_domain this_domain; |
51 static struct ipipe_sysinfo sys_info; |
51 static struct ipipe_sysinfo sys_info; |
52 |
52 |
53 // EtherCAT |
53 // EtherCAT |
54 ec_master_t *master = NULL; |
54 ec_master_t *master = NULL; |
55 ec_slave_t *s_in1, *s_out1, *s_out2, *s_out3; |
55 ec_slave_t *s_in1, *s_out1, *s_ssi, *s_inc; |
56 |
56 |
57 double value; |
57 uint16_t angle0; |
58 int dig1; |
|
59 |
58 |
60 ec_slave_init_t slaves[] = { |
59 ec_slave_init_t slaves[] = { |
61 {&s_in1, 1, "Beckhoff", "EL3102", 0}, |
60 {&s_in1, "1", "Beckhoff", "EL3102", 0}, |
62 {&s_out1, 8, "Beckhoff", "EL2004", 0}, |
61 {&s_out1, "2", "Beckhoff", "EL2004", 0}, |
63 {&s_out2, 9, "Beckhoff", "EL2004", 0}, |
62 {&s_ssi, "3", "Beckhoff", "EL5001", 0}, |
64 {&s_out3, 10, "Beckhoff", "EL2004", 0} |
63 {&s_inc, "0:4", "Beckhoff", "EL5101", 0} |
65 }; |
64 }; |
66 |
65 |
67 #define SLAVE_COUNT (sizeof(slaves) / sizeof(ec_slave_init_t)) |
66 #define SLAVE_COUNT (sizeof(slaves) / sizeof(ec_slave_init_t)) |
68 |
67 |
69 /****************************************************************************** |
68 /****************************************************************************** |
75 static void msr_controller_run(void) |
74 static void msr_controller_run(void) |
76 { |
75 { |
77 static unsigned int counter = 0; |
76 static unsigned int counter = 0; |
78 |
77 |
79 msr_jitter_run(MSR_ABTASTFREQUENZ); |
78 msr_jitter_run(MSR_ABTASTFREQUENZ); |
|
79 |
|
80 EC_WRITE_EL20XX(s_out1, 3, EC_READ_EL31XX(s_in1, 0) < 0); |
|
81 |
|
82 if (!counter) { |
|
83 EtherCAT_rt_debug_level(master, 2); |
|
84 } |
|
85 |
|
86 // Prozessdaten lesen und schreiben |
|
87 EtherCAT_rt_domain_xio(master, 0, 40); |
80 |
88 |
81 if (counter) { |
89 if (counter) { |
82 counter--; |
90 counter--; |
83 } |
91 } |
84 else { |
92 else { |
85 // "Star Trek"-Effekte |
93 EtherCAT_rt_debug_level(master, 0); |
86 EC_WRITE_EL20XX(s_out1, 0, jiffies & 1); |
94 printk("SSI status=0x%X value=%u\n", |
87 EC_WRITE_EL20XX(s_out1, 1, (jiffies >> 1) & 1); |
95 EC_READ_EL5001_STATE(s_ssi), EC_READ_EL5001_VALUE(s_ssi)); |
88 EC_WRITE_EL20XX(s_out1, 2, (jiffies >> 2) & 1); |
96 printk("INC status=0x%X value=%u\n", |
89 EC_WRITE_EL20XX(s_out1, 3, (jiffies >> 3) & 1); |
97 EC_READ_EL5101_STATE(s_inc), EC_READ_EL5101_VALUE(s_inc)); |
90 EC_WRITE_EL20XX(s_out2, 0, (jiffies >> 4) & 1); |
98 |
91 EC_WRITE_EL20XX(s_out2, 1, (jiffies >> 3) & 1); |
99 counter = MSR_ABTASTFREQUENZ * 5; |
92 EC_WRITE_EL20XX(s_out2, 2, (jiffies >> 2) & 1); |
100 } |
93 EC_WRITE_EL20XX(s_out2, 3, (jiffies >> 6) & 1); |
101 |
94 EC_WRITE_EL20XX(s_out3, 0, (jiffies >> 7) & 1); |
102 angle0 = EC_READ_EL5101_VALUE(s_inc); |
95 EC_WRITE_EL20XX(s_out3, 1, (jiffies >> 2) & 1); |
|
96 EC_WRITE_EL20XX(s_out3, 2, (jiffies >> 8) & 1); |
|
97 |
|
98 counter = MSR_ABTASTFREQUENZ / 4; |
|
99 } |
|
100 |
|
101 EC_WRITE_EL20XX(s_out3, 3, EC_READ_EL31XX(s_in1, 0) < 0); |
|
102 |
|
103 // Prozessdaten lesen und schreiben |
|
104 EtherCAT_rt_domain_xio(master, 0, 40); |
|
105 } |
103 } |
106 |
104 |
107 /****************************************************************************** |
105 /****************************************************************************** |
108 * |
106 * |
109 * Function: msr_run(_interrupt) |
107 * Function: msr_run(_interrupt) |
141 |
139 |
142 ipipe_get_sysinfo(&sys_info); |
140 ipipe_get_sysinfo(&sys_info); |
143 ipipe_virtualize_irq(ipipe_current_domain,sys_info.archdep.tmirq, |
141 ipipe_virtualize_irq(ipipe_current_domain,sys_info.archdep.tmirq, |
144 &msr_run, NULL, IPIPE_HANDLE_MASK); |
142 &msr_run, NULL, IPIPE_HANDLE_MASK); |
145 |
143 |
146 ipipe_tune_timer(1000000000UL/MSR_ABTASTFREQUENZ,0); |
144 ipipe_tune_timer(1000000000UL / MSR_ABTASTFREQUENZ, 0); |
147 } |
145 } |
148 |
146 |
149 /****************************************************************************** |
147 /****************************************************************************** |
150 * |
148 * |
151 * Function: msr_register_channels |
149 * Function: msr_register_channels |
160 * |
158 * |
161 *****************************************************************************/ |
159 *****************************************************************************/ |
162 |
160 |
163 int msr_globals_register(void) |
161 int msr_globals_register(void) |
164 { |
162 { |
165 msr_reg_kanal("/value", "V", &value, TDBL); |
163 //msr_reg_kanal("/value", "V", &value, TDBL); |
166 msr_reg_kanal("/dig1", "", &dig1, TINT); |
164 //msr_reg_kanal("/dig1", "", &dig1, TINT); |
|
165 msr_reg_kanal("/angle0", "", &angle0, TINT); |
167 |
166 |
168 return 0; |
167 return 0; |
169 } |
168 } |
170 |
169 |
171 /****************************************************************************** |
170 /****************************************************************************** |
196 goto out_release_master; |
195 goto out_release_master; |
197 } |
196 } |
198 |
197 |
199 if (EtherCAT_rt_activate_slaves(master) < 0) { |
198 if (EtherCAT_rt_activate_slaves(master) < 0) { |
200 printk(KERN_ERR "EtherCAT: Could not activate slaves!\n"); |
199 printk(KERN_ERR "EtherCAT: Could not activate slaves!\n"); |
|
200 goto out_release_master; |
|
201 } |
|
202 |
|
203 if (EtherCAT_rt_canopen_sdo_write(master, s_ssi, 0x4067, 0, 1, 2)) { |
|
204 printk(KERN_ERR "EtherCAT: Could not set SSI baud rate!\n"); |
|
205 goto out_release_master; |
|
206 } |
|
207 |
|
208 if (EtherCAT_rt_canopen_sdo_write(master, s_ssi, 0x4061, 4, 1, 1)) { |
|
209 printk(KERN_ERR "EtherCAT: Could not set SSI feature bit!\n"); |
201 goto out_release_master; |
210 goto out_release_master; |
202 } |
211 } |
203 |
212 |
204 do_gettimeofday(&process_time); |
213 do_gettimeofday(&process_time); |
205 msr_time_increment.tv_sec = 0; |
214 msr_time_increment.tv_sec = 0; |