188 // init state machine datagram |
188 // init state machine datagram |
189 ec_datagram_init(&master->fsm_datagram); |
189 ec_datagram_init(&master->fsm_datagram); |
190 snprintf(master->fsm_datagram.name, EC_DATAGRAM_NAME_SIZE, "master-fsm"); |
190 snprintf(master->fsm_datagram.name, EC_DATAGRAM_NAME_SIZE, "master-fsm"); |
191 ret = ec_datagram_prealloc(&master->fsm_datagram, EC_MAX_DATA_SIZE); |
191 ret = ec_datagram_prealloc(&master->fsm_datagram, EC_MAX_DATA_SIZE); |
192 if (ret < 0) { |
192 if (ret < 0) { |
|
193 ec_datagram_clear(&master->fsm_datagram); |
193 EC_ERR("Failed to allocate FSM datagram.\n"); |
194 EC_ERR("Failed to allocate FSM datagram.\n"); |
194 goto out_clear_backup; |
195 goto out_clear_backup; |
195 } |
196 } |
196 |
197 |
197 // create state machine object |
198 // create state machine object |
198 ec_fsm_master_init(&master->fsm, master, &master->fsm_datagram); |
199 ec_fsm_master_init(&master->fsm, master, &master->fsm_datagram); |
|
200 |
|
201 // init sync datagram |
|
202 ec_datagram_init(&master->sync_datagram); |
|
203 snprintf(master->sync_datagram.name, EC_DATAGRAM_NAME_SIZE, "sync"); |
|
204 ret = ec_datagram_armw(&master->sync_datagram, 0 /* FIXME */, 0x0910, 4); |
|
205 if (ret < 0) { |
|
206 ec_datagram_clear(&master->sync_datagram); |
|
207 EC_ERR("Failed to allocate synchronisation datagram.\n"); |
|
208 goto out_clear_fsm; |
|
209 } |
199 |
210 |
200 // init character device |
211 // init character device |
201 ret = ec_cdev_init(&master->cdev, master, device_number); |
212 ret = ec_cdev_init(&master->cdev, master, device_number); |
202 if (ret) |
213 if (ret) |
203 goto out_clear_fsm; |
214 goto out_clear_sync; |
204 |
215 |
205 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27) |
216 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27) |
206 master->class_device = device_create(class, NULL, |
217 master->class_device = device_create(class, NULL, |
207 MKDEV(MAJOR(device_number), master->index), NULL, |
218 MKDEV(MAJOR(device_number), master->index), NULL, |
208 "EtherCAT%u", master->index); |
219 "EtherCAT%u", master->index); |
251 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26) |
264 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26) |
252 device_unregister(master->class_device); |
265 device_unregister(master->class_device); |
253 #else |
266 #else |
254 class_device_unregister(master->class_device); |
267 class_device_unregister(master->class_device); |
255 #endif |
268 #endif |
|
269 |
256 ec_cdev_clear(&master->cdev); |
270 ec_cdev_clear(&master->cdev); |
|
271 |
257 #ifdef EC_EOE |
272 #ifdef EC_EOE |
258 ec_master_clear_eoe_handlers(master); |
273 ec_master_clear_eoe_handlers(master); |
259 #endif |
274 #endif |
260 ec_master_clear_domains(master); |
275 ec_master_clear_domains(master); |
261 ec_master_clear_slave_configs(master); |
276 ec_master_clear_slave_configs(master); |
262 ec_master_clear_slaves(master); |
277 ec_master_clear_slaves(master); |
|
278 |
|
279 ec_datagram_clear(&master->sync_datagram); |
263 ec_fsm_master_clear(&master->fsm); |
280 ec_fsm_master_clear(&master->fsm); |
264 ec_datagram_clear(&master->fsm_datagram); |
281 ec_datagram_clear(&master->fsm_datagram); |
265 ec_device_clear(&master->backup_device); |
282 ec_device_clear(&master->backup_device); |
266 ec_device_clear(&master->main_device); |
283 ec_device_clear(&master->main_device); |
267 } |
284 } |
1312 |
1329 |
1313 return 0; |
1330 return 0; |
1314 } |
1331 } |
1315 |
1332 |
1316 /****************************************************************************** |
1333 /****************************************************************************** |
1317 * Realtime interface |
1334 * Application interface |
1318 *****************************************************************************/ |
1335 *****************************************************************************/ |
1319 |
1336 |
1320 /** Same as ecrt_master_create_domain(), but with ERR_PTR() return value. |
1337 /** Same as ecrt_master_create_domain(), but with ERR_PTR() return value. |
1321 */ |
1338 */ |
1322 ec_domain_t *ecrt_master_create_domain_err( |
1339 ec_domain_t *ecrt_master_create_domain_err( |
1588 state->link_up = master->main_device.link_state; |
1605 state->link_up = master->main_device.link_state; |
1589 } |
1606 } |
1590 |
1607 |
1591 /*****************************************************************************/ |
1608 /*****************************************************************************/ |
1592 |
1609 |
|
1610 void ecrt_master_sync(ec_master_t *master) |
|
1611 { |
|
1612 ec_datagram_zero(&master->sync_datagram); |
|
1613 ec_master_queue_datagram(master, &master->sync_datagram); |
|
1614 } |
|
1615 |
|
1616 /*****************************************************************************/ |
|
1617 |
1593 /** \cond */ |
1618 /** \cond */ |
1594 |
1619 |
1595 EXPORT_SYMBOL(ecrt_master_create_domain); |
1620 EXPORT_SYMBOL(ecrt_master_create_domain); |
1596 EXPORT_SYMBOL(ecrt_master_activate); |
1621 EXPORT_SYMBOL(ecrt_master_activate); |
1597 EXPORT_SYMBOL(ecrt_master_send); |
1622 EXPORT_SYMBOL(ecrt_master_send); |
1598 EXPORT_SYMBOL(ecrt_master_receive); |
1623 EXPORT_SYMBOL(ecrt_master_receive); |
1599 EXPORT_SYMBOL(ecrt_master_callbacks); |
1624 EXPORT_SYMBOL(ecrt_master_callbacks); |
1600 EXPORT_SYMBOL(ecrt_master_slave_config); |
1625 EXPORT_SYMBOL(ecrt_master_slave_config); |
1601 EXPORT_SYMBOL(ecrt_master_state); |
1626 EXPORT_SYMBOL(ecrt_master_state); |
|
1627 EXPORT_SYMBOL(ecrt_master_sync); |
1602 |
1628 |
1603 /** \endcond */ |
1629 /** \endcond */ |
1604 |
1630 |
1605 /*****************************************************************************/ |
1631 /*****************************************************************************/ |