58 spinlock_t master_lock = SPIN_LOCK_UNLOCKED; |
58 spinlock_t master_lock = SPIN_LOCK_UNLOCKED; |
59 |
59 |
60 static ec_domain_t *domain1 = NULL; |
60 static ec_domain_t *domain1 = NULL; |
61 static ec_domain_state_t domain1_state = {}; |
61 static ec_domain_state_t domain1_state = {}; |
62 |
62 |
|
63 static ec_slave_config_t *sc_ana_in = NULL; |
|
64 static ec_slave_config_state_t sc_ana_in_state = {}; |
|
65 |
63 static struct timer_list timer; |
66 static struct timer_list timer; |
64 static unsigned int counter = 0; |
67 static unsigned int counter = 0; |
65 |
68 |
66 /*****************************************************************************/ |
69 /*****************************************************************************/ |
67 |
70 |
126 |
129 |
127 void check_domain1_state(void) |
130 void check_domain1_state(void) |
128 { |
131 { |
129 ec_domain_state_t ds; |
132 ec_domain_state_t ds; |
130 |
133 |
|
134 spin_lock(&master_lock); |
131 ecrt_domain_state(domain1, &ds); |
135 ecrt_domain_state(domain1, &ds); |
|
136 spin_unlock(&master_lock); |
|
137 |
132 if (ds.working_counter != domain1_state.working_counter) |
138 if (ds.working_counter != domain1_state.working_counter) |
133 printk(KERN_INFO PFX "domain1 working_counter changed to %u.\n", |
139 printk(KERN_INFO PFX "Domain1: WC %u.\n", ds.working_counter); |
134 ds.working_counter); |
|
135 |
|
136 if (ds.wc_state != domain1_state.wc_state) |
140 if (ds.wc_state != domain1_state.wc_state) |
137 printk(KERN_INFO PFX "domain1 wc_state changed to %u.\n", |
141 printk(KERN_INFO PFX "Domain1: State %u.\n", ds.wc_state); |
138 ds.wc_state); |
|
139 |
142 |
140 domain1_state = ds; |
143 domain1_state = ds; |
141 } |
144 } |
142 |
145 |
143 /*****************************************************************************/ |
146 /*****************************************************************************/ |
148 |
151 |
149 spin_lock(&master_lock); |
152 spin_lock(&master_lock); |
150 ecrt_master_state(master, &ms); |
153 ecrt_master_state(master, &ms); |
151 spin_unlock(&master_lock); |
154 spin_unlock(&master_lock); |
152 |
155 |
153 if (ms.slaves_responding != master_state.slaves_responding) { |
156 if (ms.slaves_responding != master_state.slaves_responding) |
154 printk(KERN_INFO PFX "slaves_responding changed to %u.\n", |
157 printk(KERN_INFO PFX "%u slave(s).\n", ms.slaves_responding); |
155 ms.slaves_responding); |
158 if (ms.al_states != master_state.al_states) |
156 } |
159 printk(KERN_INFO PFX "AL states: 0x%02X.\n", ms.al_states); |
|
160 if (ms.link_up != master_state.link_up) |
|
161 printk(KERN_INFO PFX "Link is %s.\n", ms.link_up ? "up" : "down"); |
157 |
162 |
158 master_state = ms; |
163 master_state = ms; |
|
164 } |
|
165 |
|
166 /*****************************************************************************/ |
|
167 |
|
168 void check_slave_config_states(void) |
|
169 { |
|
170 ec_slave_config_state_t s; |
|
171 |
|
172 spin_lock(&master_lock); |
|
173 ecrt_slave_config_state(sc_ana_in, &s); |
|
174 spin_unlock(&master_lock); |
|
175 |
|
176 if (s.al_state != sc_ana_in_state.al_state) |
|
177 printk(KERN_INFO PFX "AnaIn: State 0x%02X.\n", s.al_state); |
|
178 if (s.online != sc_ana_in_state.online) |
|
179 printk(KERN_INFO PFX "AnaIn: %s.\n", s.online ? "online" : "offline"); |
|
180 if (s.operational != sc_ana_in_state.operational) |
|
181 printk(KERN_INFO PFX "AnaIn: %soperational.\n", |
|
182 s.operational ? "" : "Not "); |
|
183 |
|
184 sc_ana_in_state = s; |
159 } |
185 } |
160 |
186 |
161 /*****************************************************************************/ |
187 /*****************************************************************************/ |
162 |
188 |
163 #ifdef SDO_ACCESS |
189 #ifdef SDO_ACCESS |
205 // calculate new process data |
231 // calculate new process data |
206 blink = !blink; |
232 blink = !blink; |
207 |
233 |
208 // check for master state (optional) |
234 // check for master state (optional) |
209 check_master_state(); |
235 check_master_state(); |
|
236 |
|
237 // check for islave configuration state(s) (optional) |
|
238 check_slave_config_states(); |
210 |
239 |
211 #ifdef SDO_ACCESS |
240 #ifdef SDO_ACCESS |
212 // read process data Sdo |
241 // read process data Sdo |
213 read_sdo(); |
242 read_sdo(); |
214 #endif |
243 #endif |
267 if (!(domain1 = ecrt_master_create_domain(master))) { |
296 if (!(domain1 = ecrt_master_create_domain(master))) { |
268 printk(KERN_ERR PFX "Domain creation failed!\n"); |
297 printk(KERN_ERR PFX "Domain creation failed!\n"); |
269 goto out_release_master; |
298 goto out_release_master; |
270 } |
299 } |
271 |
300 |
|
301 if (!(sc_ana_in = ecrt_master_slave_config( |
|
302 master, 0, 1, Beckhoff_EL3162))) { |
|
303 printk(KERN_ERR PFX "Failed to get slave configuration.\n"); |
|
304 goto out_release_master; |
|
305 } |
|
306 |
272 #ifdef CONFIGURE_PDOS |
307 #ifdef CONFIGURE_PDOS |
273 printk(KERN_INFO PFX "Configuring Pdos...\n"); |
308 printk(KERN_INFO PFX "Configuring Pdos...\n"); |
274 if (!(sc = ecrt_master_slave_config(master, 0, 1, Beckhoff_EL3162))) { |
309 if (ecrt_slave_config_pdos(sc_ana_in, EC_END, el3162_pdos)) { |
275 printk(KERN_ERR PFX "Failed to get slave configuration.\n"); |
|
276 goto out_release_master; |
|
277 } |
|
278 |
|
279 if (ecrt_slave_config_pdos(sc, EC_END, el3162_pdos)) { |
|
280 printk(KERN_ERR PFX "Failed to configure Pdos.\n"); |
310 printk(KERN_ERR PFX "Failed to configure Pdos.\n"); |
281 goto out_release_master; |
311 goto out_release_master; |
282 } |
312 } |
283 |
313 |
284 if (!(sc = ecrt_master_slave_config(master, 0, 3, Beckhoff_EL2004))) { |
314 if (!(sc = ecrt_master_slave_config(master, 0, 3, Beckhoff_EL2004))) { |