Merge.
--- a/TODO Thu Aug 05 09:54:06 2010 +0200
+++ b/TODO Thu Sep 16 10:16:12 2010 +0200
@@ -13,9 +13,6 @@
* Ethernet drivers:
- Fix link detection in generic driver.
- Add native drivers from 2.6.24 up to 2.6.31.
-* Finish library implementation.
- - Remove stdio uses?
-* Rescan command.
* ethercat tool:
- Output error after usage.
- Implement ranges for slaves and domains.
@@ -80,6 +77,7 @@
* Simplify master fsm by introducing a common request state to handle external
requests (replace write_sii, sdo_request, etc).
* Write PDO mapping/assignment by default?
+* Remove stdio uses in userspace library?
Smaller issues:
--- a/lib/common.c Thu Aug 05 09:54:06 2010 +0200
+++ b/lib/common.c Thu Sep 16 10:16:12 2010 +0200
@@ -55,9 +55,9 @@
ec_master_t *master = ecrt_open_master(master_index);
if (master) {
if (ecrt_master_reserve(master) < 0) {
- close(master->fd);
+ ec_master_clear(master);
free(master);
- master = 0;
+ master = NULL;
}
}
@@ -82,19 +82,21 @@
master->process_data = NULL;
master->process_data_size = 0;
+ master->first_domain = NULL;
+ master->first_config = NULL;
snprintf(path, MAX_PATH_LEN - 1, "/dev/EtherCAT%u", master_index);
master->fd = open(path, O_RDWR);
if (master->fd == -1) {
fprintf(stderr, "Failed to open %s: %s\n", path, strerror(errno));
- goto out_free;
+ goto out_clear;
}
if (ioctl(master->fd, EC_IOCTL_MODULE, &module_data) < 0) {
fprintf(stderr, "Failed to get module information from %s: %s\n",
path, strerror(errno));
- goto out_close;
+ goto out_clear;
}
if (module_data.ioctl_version_magic != EC_IOCTL_VERSION_MAGIC) {
@@ -102,14 +104,13 @@
" %s: %u, libethercat: %u.\n",
path, module_data.ioctl_version_magic,
EC_IOCTL_VERSION_MAGIC);
- goto out_close;
+ goto out_clear;
}
return master;
-out_close:
- close(master->fd);
-out_free:
+out_clear:
+ ec_master_clear(master);
free(master);
return 0;
}
@@ -118,11 +119,7 @@
void ecrt_release_master(ec_master_t *master)
{
- if (master->process_data) {
- munmap(master->process_data, master->process_data_size);
- }
-
- close(master->fd);
+ ec_master_clear(master);
free(master);
}
--- a/lib/domain.c Thu Aug 05 09:54:06 2010 +0200
+++ b/lib/domain.c Thu Sep 16 10:16:12 2010 +0200
@@ -47,6 +47,13 @@
/*****************************************************************************/
+void ec_domain_clear(ec_domain_t *domain)
+{
+ // nothing to do
+}
+
+/*****************************************************************************/
+
int ecrt_domain_reg_pdo_entry_list(ec_domain_t *domain,
const ec_pdo_entry_reg_t *regs)
{
--- a/lib/domain.h Thu Aug 05 09:54:06 2010 +0200
+++ b/lib/domain.h Thu Sep 16 10:16:12 2010 +0200
@@ -33,9 +33,14 @@
/*****************************************************************************/
struct ec_domain {
+ ec_domain_t *next;
unsigned int index;
ec_master_t *master;
uint8_t *process_data;
};
/*****************************************************************************/
+
+void ec_domain_clear(ec_domain_t *);
+
+/*****************************************************************************/
--- a/lib/master.c Thu Aug 05 09:54:06 2010 +0200
+++ b/lib/master.c Thu Sep 16 10:16:12 2010 +0200
@@ -53,6 +53,60 @@
/*****************************************************************************/
+void ec_master_clear_config(ec_master_t *master)
+{
+ ec_domain_t *d, *next_d;
+ ec_slave_config_t *c, *next_c;
+
+ d = master->first_domain;
+ while (d) {
+ next_d = d->next;
+ ec_domain_clear(d);
+ d = next_d;
+ }
+ master->first_domain = NULL;
+
+ c = master->first_config;
+ while (c) {
+ next_c = c->next;
+ ec_slave_config_clear(c);
+ c = next_c;
+ }
+ master->first_config = NULL;
+}
+
+/*****************************************************************************/
+
+void ec_master_clear(ec_master_t *master)
+{
+ if (master->process_data) {
+ munmap(master->process_data, master->process_data_size);
+ }
+
+ ec_master_clear_config(master);
+
+ if (master->fd != -1) {
+ close(master->fd);
+ }
+}
+
+/*****************************************************************************/
+
+void ec_master_add_domain(ec_master_t *master, ec_domain_t *domain)
+{
+ if (master->first_domain) {
+ ec_domain_t *d = master->first_domain;
+ while (d->next) {
+ d = d->next;
+ }
+ d->next = domain;
+ } else {
+ master->first_domain = domain;
+ }
+}
+
+/*****************************************************************************/
+
ec_domain_t *ecrt_master_create_domain(ec_master_t *master)
{
ec_domain_t *domain;
@@ -71,14 +125,33 @@
return 0;
}
+ domain->next = NULL;
domain->index = (unsigned int) index;
domain->master = master;
domain->process_data = NULL;
+
+ ec_master_add_domain(master, domain);
+
return domain;
}
/*****************************************************************************/
+void ec_master_add_slave_config(ec_master_t *master, ec_slave_config_t *sc)
+{
+ if (master->first_config) {
+ ec_slave_config_t *c = master->first_config;
+ while (c->next) {
+ c = c->next;
+ }
+ c->next = sc;
+ } else {
+ master->first_config = sc;
+ }
+}
+
+/*****************************************************************************/
+
ec_slave_config_t *ecrt_master_slave_config(ec_master_t *master,
uint16_t alias, uint16_t position, uint32_t vendor_id,
uint32_t product_code)
@@ -105,10 +178,16 @@
return 0;
}
+ sc->next = NULL;
sc->master = master;
sc->index = data.config_index;
sc->alias = alias;
sc->position = position;
+ sc->first_sdo_request = NULL;
+ sc->first_voe_handler = NULL;
+
+ ec_master_add_slave_config(master, sc);
+
return sc;
}
@@ -389,8 +468,9 @@
fprintf(stderr, "Failed to deactivate master: %s\n", strerror(errno));
return;
}
-}
-
+
+ ec_master_clear_config(master);
+}
/*****************************************************************************/
@@ -405,7 +485,6 @@
return 0;
}
-
/*****************************************************************************/
void ecrt_master_send(ec_master_t *master)
--- a/lib/master.h Thu Aug 05 09:54:06 2010 +0200
+++ b/lib/master.h Thu Sep 16 10:16:12 2010 +0200
@@ -36,6 +36,13 @@
int fd;
uint8_t *process_data;
size_t process_data_size;
+
+ ec_domain_t *first_domain;
+ ec_slave_config_t *first_config;
};
/*****************************************************************************/
+
+void ec_master_clear(ec_master_t *);
+
+/*****************************************************************************/
--- a/lib/sdo_request.c Thu Aug 05 09:54:06 2010 +0200
+++ b/lib/sdo_request.c Thu Sep 16 10:16:12 2010 +0200
@@ -43,8 +43,17 @@
#include "slave_config.h"
#include "master.h"
+/*****************************************************************************/
+
+void ec_sdo_request_clear(ec_sdo_request_t *req)
+{
+ if (req->data) {
+ free(req->data);
+ }
+}
+
/*****************************************************************************
- * Realtime interface.
+ * Application interface.
****************************************************************************/
void ecrt_sdo_request_timeout(ec_sdo_request_t *req, uint32_t timeout)
--- a/lib/sdo_request.h Thu Aug 05 09:54:06 2010 +0200
+++ b/lib/sdo_request.h Thu Sep 16 10:16:12 2010 +0200
@@ -33,6 +33,7 @@
/*****************************************************************************/
struct ec_sdo_request {
+ ec_sdo_request_t *next; /**< List header. */
ec_slave_config_t *config; /**< Parent slave configuration. */
unsigned int index; /**< Request index (identifier). */
uint16_t sdo_index; /**< SDO index. */
@@ -43,3 +44,7 @@
};
/*****************************************************************************/
+
+void ec_sdo_request_clear(ec_sdo_request_t *);
+
+/*****************************************************************************/
--- a/lib/slave_config.c Thu Aug 05 09:54:06 2010 +0200
+++ b/lib/slave_config.c Thu Sep 16 10:16:12 2010 +0200
@@ -43,6 +43,29 @@
/*****************************************************************************/
+void ec_slave_config_clear(ec_slave_config_t *sc)
+{
+ ec_sdo_request_t *r, *next_r;
+ ec_voe_handler_t *v, *next_v;
+
+ r = sc->first_sdo_request;
+ while (r) {
+ next_r = r->next;
+ ec_sdo_request_clear(r);
+ r = next_r;
+ }
+
+
+ v = sc->first_voe_handler;
+ while (v) {
+ next_v = v->next;
+ ec_voe_handler_clear(v);
+ v = next_v;
+ }
+}
+
+/*****************************************************************************/
+
int ecrt_slave_config_sync_manager(ec_slave_config_t *sc, uint8_t sync_index,
ec_direction_t dir, ec_watchdog_mode_t watchdog_mode)
{
@@ -361,6 +384,22 @@
/*****************************************************************************/
+void ec_slave_config_add_sdo_request(ec_slave_config_t *sc,
+ ec_sdo_request_t *req)
+{
+ if (sc->first_sdo_request) {
+ ec_sdo_request_t *r = sc->first_sdo_request;
+ while (r->next) {
+ r = r->next;
+ }
+ r->next = req;
+ } else {
+ sc->first_sdo_request = req;
+ }
+}
+
+/*****************************************************************************/
+
ec_sdo_request_t *ecrt_slave_config_create_sdo_request(ec_slave_config_t *sc,
uint16_t index, uint8_t subindex, size_t size)
{
@@ -393,23 +432,42 @@
if (ioctl(sc->master->fd, EC_IOCTL_SC_SDO_REQUEST, &data) == -1) {
fprintf(stderr, "Failed to create SDO request: %s\n",
strerror(errno));
- if (req->data)
- free(req->data);
+ ec_sdo_request_clear(req);
free(req);
return NULL;
}
+ req->next = NULL;
req->config = sc;
req->index = data.request_index;
req->sdo_index = data.sdo_index;
req->sdo_subindex = data.sdo_subindex;
req->data_size = size;
req->mem_size = size;
+
+ ec_slave_config_add_sdo_request(sc, req);
+
return req;
}
/*****************************************************************************/
+void ec_slave_config_add_voe_handler(ec_slave_config_t *sc,
+ ec_voe_handler_t *voe)
+{
+ if (sc->first_voe_handler) {
+ ec_voe_handler_t *v = sc->first_voe_handler;
+ while (v->next) {
+ v = v->next;
+ }
+ v->next = voe;
+ } else {
+ sc->first_voe_handler = voe;
+ }
+}
+
+/*****************************************************************************/
+
ec_voe_handler_t *ecrt_slave_config_create_voe_handler(ec_slave_config_t *sc,
size_t size)
{
@@ -441,16 +499,19 @@
if (ioctl(sc->master->fd, EC_IOCTL_SC_VOE, &data) == -1) {
fprintf(stderr, "Failed to create VoE handler: %s\n",
strerror(errno));
- if (voe->data)
- free(voe->data);
+ ec_voe_handler_clear(voe);
free(voe);
return NULL;
}
+ voe->next = NULL;
voe->config = sc;
voe->index = data.voe_index;
voe->data_size = size;
voe->mem_size = size;
+
+ ec_slave_config_add_voe_handler(sc, voe);
+
return voe;
}
--- a/lib/slave_config.h Thu Aug 05 09:54:06 2010 +0200
+++ b/lib/slave_config.h Thu Sep 16 10:16:12 2010 +0200
@@ -33,10 +33,17 @@
/*****************************************************************************/
struct ec_slave_config {
+ ec_slave_config_t *next;
ec_master_t *master;
unsigned int index;
uint16_t alias;
uint16_t position;
+ ec_sdo_request_t *first_sdo_request;
+ ec_voe_handler_t *first_voe_handler;
};
/*****************************************************************************/
+
+void ec_slave_config_clear(ec_slave_config_t *);
+
+/*****************************************************************************/
--- a/lib/voe_handler.c Thu Aug 05 09:54:06 2010 +0200
+++ b/lib/voe_handler.c Thu Sep 16 10:16:12 2010 +0200
@@ -47,6 +47,14 @@
/*****************************************************************************/
+void ec_voe_handler_clear(ec_voe_handler_t *voe)
+{
+ if (voe->data)
+ free(voe->data);
+}
+
+/*****************************************************************************/
+
void ecrt_voe_handler_send_header(ec_voe_handler_t *voe, uint32_t vendor_id,
uint16_t vendor_type)
{
--- a/lib/voe_handler.h Thu Aug 05 09:54:06 2010 +0200
+++ b/lib/voe_handler.h Thu Sep 16 10:16:12 2010 +0200
@@ -33,6 +33,7 @@
/*****************************************************************************/
struct ec_voe_handler {
+ ec_voe_handler_t *next;
ec_slave_config_t *config;
unsigned int index;
size_t data_size;
@@ -41,3 +42,7 @@
};
/*****************************************************************************/
+
+void ec_voe_handler_clear(ec_voe_handler_t *);
+
+/*****************************************************************************/
--- a/master/cdev.c Thu Aug 05 09:54:06 2010 +0200
+++ b/master/cdev.c Thu Sep 16 10:16:12 2010 +0200
@@ -659,6 +659,19 @@
/*****************************************************************************/
+/** Issue a bus scan.
+ */
+int ec_cdev_ioctl_master_rescan(
+ ec_master_t *master, /**< EtherCAT master. */
+ unsigned long arg /**< ioctl() argument. */
+ )
+{
+ master->fsm.rescan_required = 1;
+ return 0;
+}
+
+/*****************************************************************************/
+
/** Set slave state.
*/
int ec_cdev_ioctl_slave_state(
@@ -3501,6 +3514,10 @@
if (!(filp->f_mode & FMODE_WRITE))
return -EPERM;
return ec_cdev_ioctl_master_debug(master, arg);
+ case EC_IOCTL_MASTER_RESCAN:
+ if (!(filp->f_mode & FMODE_WRITE))
+ return -EPERM;
+ return ec_cdev_ioctl_master_rescan(master, arg);
case EC_IOCTL_SLAVE_STATE:
if (!(filp->f_mode & FMODE_WRITE))
return -EPERM;
--- a/master/fsm_master.c Thu Aug 05 09:54:06 2010 +0200
+++ b/master/fsm_master.c Thu Sep 16 10:16:12 2010 +0200
@@ -85,7 +85,7 @@
fsm->idle = 0;
fsm->link_state = 0;
fsm->slaves_responding = 0;
- fsm->topology_change_pending = 0;
+ fsm->rescan_required = 0;
fsm->slave_states = EC_SLAVE_STATE_UNKNOWN;
// init sub-state-machines
@@ -201,7 +201,7 @@
// bus topology change?
if (datagram->working_counter != fsm->slaves_responding) {
- fsm->topology_change_pending = 1;
+ fsm->rescan_required = 1;
fsm->slaves_responding = datagram->working_counter;
EC_MASTER_INFO(master, "%u slave(s) responding.\n",
fsm->slaves_responding);
@@ -237,7 +237,7 @@
fsm->slave_states = 0x00;
}
- if (fsm->topology_change_pending) {
+ if (fsm->rescan_required) {
down(&master->scan_sem);
if (!master->allow_scan) {
up(&master->scan_sem);
@@ -245,9 +245,8 @@
master->scan_busy = 1;
up(&master->scan_sem);
- // topology change when scan is allowed:
// clear all slaves and scan the bus
- fsm->topology_change_pending = 0;
+ fsm->rescan_required = 0;
fsm->idle = 0;
fsm->scan_jiffies = jiffies;
@@ -630,7 +629,7 @@
slave->error_flag = 1;
EC_SLAVE_DBG(slave, 1, "Slave did not respond to state query.\n");
}
- fsm->topology_change_pending = 1;
+ fsm->rescan_required = 1;
ec_fsm_master_restart(fsm);
return;
}
--- a/master/fsm_master.h Thu Aug 05 09:54:06 2010 +0200
+++ b/master/fsm_master.h Thu Sep 16 10:16:12 2010 +0200
@@ -119,7 +119,7 @@
unsigned long scan_jiffies; /**< beginning of slave scanning */
uint8_t link_state; /**< Last main device link state. */
unsigned int slaves_responding; /**< number of responding slaves */
- unsigned int topology_change_pending; /**< bus topology changed */
+ unsigned int rescan_required; /**< A bus rescan is required. */
ec_slave_state_t slave_states; /**< states of responding slaves */
ec_slave_t *slave; /**< current slave */
ec_sii_write_request_t *sii_request; /**< SII write request */
--- a/master/ioctl.h Thu Aug 05 09:54:06 2010 +0200
+++ b/master/ioctl.h Thu Sep 16 10:16:12 2010 +0200
@@ -56,7 +56,7 @@
*
* Increment this when changing the ioctl interface!
*/
-#define EC_IOCTL_VERSION_MAGIC 7
+#define EC_IOCTL_VERSION_MAGIC 8
// Command-line tool
#define EC_IOCTL_MODULE EC_IOR(0x00, ec_ioctl_module_t)
@@ -69,71 +69,72 @@
#define EC_IOCTL_DOMAIN_FMMU EC_IOWR(0x07, ec_ioctl_domain_fmmu_t)
#define EC_IOCTL_DOMAIN_DATA EC_IOWR(0x08, ec_ioctl_domain_data_t)
#define EC_IOCTL_MASTER_DEBUG EC_IO(0x09)
-#define EC_IOCTL_SLAVE_STATE EC_IOW(0x0a, ec_ioctl_slave_state_t)
-#define EC_IOCTL_SLAVE_SDO EC_IOWR(0x0b, ec_ioctl_slave_sdo_t)
-#define EC_IOCTL_SLAVE_SDO_ENTRY EC_IOWR(0x0c, ec_ioctl_slave_sdo_entry_t)
-#define EC_IOCTL_SLAVE_SDO_UPLOAD EC_IOWR(0x0d, ec_ioctl_slave_sdo_upload_t)
-#define EC_IOCTL_SLAVE_SDO_DOWNLOAD EC_IOWR(0x0e, ec_ioctl_slave_sdo_download_t)
-#define EC_IOCTL_SLAVE_SII_READ EC_IOWR(0x0f, ec_ioctl_slave_sii_t)
-#define EC_IOCTL_SLAVE_SII_WRITE EC_IOW(0x10, ec_ioctl_slave_sii_t)
-#define EC_IOCTL_SLAVE_REG_READ EC_IOWR(0x11, ec_ioctl_slave_reg_t)
-#define EC_IOCTL_SLAVE_REG_WRITE EC_IOW(0x12, ec_ioctl_slave_reg_t)
-#define EC_IOCTL_SLAVE_FOE_READ EC_IOWR(0x13, ec_ioctl_slave_foe_t)
-#define EC_IOCTL_SLAVE_FOE_WRITE EC_IOW(0x14, ec_ioctl_slave_foe_t)
-#define EC_IOCTL_SLAVE_SOE_READ EC_IOWR(0x15, ec_ioctl_slave_soe_read_t)
-#define EC_IOCTL_SLAVE_SOE_WRITE EC_IOWR(0x16, ec_ioctl_slave_soe_write_t)
-#define EC_IOCTL_CONFIG EC_IOWR(0x17, ec_ioctl_config_t)
-#define EC_IOCTL_CONFIG_PDO EC_IOWR(0x18, ec_ioctl_config_pdo_t)
-#define EC_IOCTL_CONFIG_PDO_ENTRY EC_IOWR(0x19, ec_ioctl_config_pdo_entry_t)
-#define EC_IOCTL_CONFIG_SDO EC_IOWR(0x1a, ec_ioctl_config_sdo_t)
+#define EC_IOCTL_MASTER_RESCAN EC_IO(0x0a)
+#define EC_IOCTL_SLAVE_STATE EC_IOW(0x0b, ec_ioctl_slave_state_t)
+#define EC_IOCTL_SLAVE_SDO EC_IOWR(0x0c, ec_ioctl_slave_sdo_t)
+#define EC_IOCTL_SLAVE_SDO_ENTRY EC_IOWR(0x0d, ec_ioctl_slave_sdo_entry_t)
+#define EC_IOCTL_SLAVE_SDO_UPLOAD EC_IOWR(0x0e, ec_ioctl_slave_sdo_upload_t)
+#define EC_IOCTL_SLAVE_SDO_DOWNLOAD EC_IOWR(0x0f, ec_ioctl_slave_sdo_download_t)
+#define EC_IOCTL_SLAVE_SII_READ EC_IOWR(0x10, ec_ioctl_slave_sii_t)
+#define EC_IOCTL_SLAVE_SII_WRITE EC_IOW(0x11, ec_ioctl_slave_sii_t)
+#define EC_IOCTL_SLAVE_REG_READ EC_IOWR(0x12, ec_ioctl_slave_reg_t)
+#define EC_IOCTL_SLAVE_REG_WRITE EC_IOW(0x13, ec_ioctl_slave_reg_t)
+#define EC_IOCTL_SLAVE_FOE_READ EC_IOWR(0x14, ec_ioctl_slave_foe_t)
+#define EC_IOCTL_SLAVE_FOE_WRITE EC_IOW(0x15, ec_ioctl_slave_foe_t)
+#define EC_IOCTL_SLAVE_SOE_READ EC_IOWR(0x16, ec_ioctl_slave_soe_read_t)
+#define EC_IOCTL_SLAVE_SOE_WRITE EC_IOWR(0x17, ec_ioctl_slave_soe_write_t)
+#define EC_IOCTL_CONFIG EC_IOWR(0x18, ec_ioctl_config_t)
+#define EC_IOCTL_CONFIG_PDO EC_IOWR(0x19, ec_ioctl_config_pdo_t)
+#define EC_IOCTL_CONFIG_PDO_ENTRY EC_IOWR(0x1a, ec_ioctl_config_pdo_entry_t)
+#define EC_IOCTL_CONFIG_SDO EC_IOWR(0x1b, ec_ioctl_config_sdo_t)
#ifdef EC_EOE
-#define EC_IOCTL_EOE_HANDLER EC_IOWR(0x1b, ec_ioctl_eoe_handler_t)
+#define EC_IOCTL_EOE_HANDLER EC_IOWR(0x1c, ec_ioctl_eoe_handler_t)
#endif
// Application interface
-#define EC_IOCTL_REQUEST EC_IO(0x1c)
-#define EC_IOCTL_CREATE_DOMAIN EC_IO(0x1d)
-#define EC_IOCTL_CREATE_SLAVE_CONFIG EC_IOWR(0x1e, ec_ioctl_config_t)
-#define EC_IOCTL_ACTIVATE EC_IOR(0x1f, size_t)
-#define EC_IOCTL_DEACTIVATE EC_IO(0x20)
-#define EC_IOCTL_SEND EC_IO(0x21)
-#define EC_IOCTL_RECEIVE EC_IO(0x22)
-#define EC_IOCTL_MASTER_STATE EC_IOR(0x23, ec_master_state_t)
-#define EC_IOCTL_APP_TIME EC_IOW(0x24, ec_ioctl_app_time_t)
-#define EC_IOCTL_SYNC_REF EC_IO(0x25)
-#define EC_IOCTL_SYNC_SLAVES EC_IO(0x26)
-#define EC_IOCTL_SYNC_MON_QUEUE EC_IO(0x27)
-#define EC_IOCTL_SYNC_MON_PROCESS EC_IOR(0x28, uint32_t)
-#define EC_IOCTL_SC_SYNC EC_IOW(0x29, ec_ioctl_config_t)
-#define EC_IOCTL_SC_WATCHDOG EC_IOW(0x2a, ec_ioctl_config_t)
-#define EC_IOCTL_SC_ADD_PDO EC_IOW(0x2b, ec_ioctl_config_pdo_t)
-#define EC_IOCTL_SC_CLEAR_PDOS EC_IOW(0x2c, ec_ioctl_config_pdo_t)
-#define EC_IOCTL_SC_ADD_ENTRY EC_IOW(0x2d, ec_ioctl_add_pdo_entry_t)
-#define EC_IOCTL_SC_CLEAR_ENTRIES EC_IOW(0x2e, ec_ioctl_config_pdo_t)
-#define EC_IOCTL_SC_REG_PDO_ENTRY EC_IOWR(0x2f, ec_ioctl_reg_pdo_entry_t)
-#define EC_IOCTL_SC_DC EC_IOW(0x20, ec_ioctl_config_t)
-#define EC_IOCTL_SC_SDO EC_IOW(0x31, ec_ioctl_sc_sdo_t)
-#define EC_IOCTL_SC_SDO_REQUEST EC_IOWR(0x32, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_SC_VOE EC_IOWR(0x33, ec_ioctl_voe_t)
-#define EC_IOCTL_SC_STATE EC_IOWR(0x34, ec_ioctl_sc_state_t)
-#define EC_IOCTL_SC_IDN EC_IOW(0x35, ec_ioctl_sc_idn_t)
-#define EC_IOCTL_DOMAIN_OFFSET EC_IO(0x36)
-#define EC_IOCTL_DOMAIN_PROCESS EC_IO(0x37)
-#define EC_IOCTL_DOMAIN_QUEUE EC_IO(0x38)
-#define EC_IOCTL_DOMAIN_STATE EC_IOWR(0x39, ec_ioctl_domain_state_t)
-#define EC_IOCTL_SDO_REQUEST_TIMEOUT EC_IOWR(0x3a, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_SDO_REQUEST_STATE EC_IOWR(0x3b, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_SDO_REQUEST_READ EC_IOWR(0x3c, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_SDO_REQUEST_WRITE EC_IOWR(0x3d, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_SDO_REQUEST_DATA EC_IOWR(0x3e, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_VOE_SEND_HEADER EC_IOW(0x3f, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_REC_HEADER EC_IOWR(0x40, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_READ EC_IOW(0x41, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_READ_NOSYNC EC_IOW(0x42, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_WRITE EC_IOWR(0x43, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_EXEC EC_IOWR(0x44, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_DATA EC_IOWR(0x45, ec_ioctl_voe_t)
-#define EC_IOCTL_SET_SEND_INTERVAL EC_IOW(0x46, size_t)
+#define EC_IOCTL_REQUEST EC_IO(0x1d)
+#define EC_IOCTL_CREATE_DOMAIN EC_IO(0x1e)
+#define EC_IOCTL_CREATE_SLAVE_CONFIG EC_IOWR(0x1f, ec_ioctl_config_t)
+#define EC_IOCTL_ACTIVATE EC_IOR(0x20, size_t)
+#define EC_IOCTL_DEACTIVATE EC_IO(0x21)
+#define EC_IOCTL_SEND EC_IO(0x22)
+#define EC_IOCTL_RECEIVE EC_IO(0x23)
+#define EC_IOCTL_MASTER_STATE EC_IOR(0x24, ec_master_state_t)
+#define EC_IOCTL_APP_TIME EC_IOW(0x25, ec_ioctl_app_time_t)
+#define EC_IOCTL_SYNC_REF EC_IO(0x26)
+#define EC_IOCTL_SYNC_SLAVES EC_IO(0x27)
+#define EC_IOCTL_SYNC_MON_QUEUE EC_IO(0x28)
+#define EC_IOCTL_SYNC_MON_PROCESS EC_IOR(0x29, uint32_t)
+#define EC_IOCTL_SC_SYNC EC_IOW(0x2a, ec_ioctl_config_t)
+#define EC_IOCTL_SC_WATCHDOG EC_IOW(0x2b, ec_ioctl_config_t)
+#define EC_IOCTL_SC_ADD_PDO EC_IOW(0x2c, ec_ioctl_config_pdo_t)
+#define EC_IOCTL_SC_CLEAR_PDOS EC_IOW(0x2d, ec_ioctl_config_pdo_t)
+#define EC_IOCTL_SC_ADD_ENTRY EC_IOW(0x2e, ec_ioctl_add_pdo_entry_t)
+#define EC_IOCTL_SC_CLEAR_ENTRIES EC_IOW(0x2f, ec_ioctl_config_pdo_t)
+#define EC_IOCTL_SC_REG_PDO_ENTRY EC_IOWR(0x20, ec_ioctl_reg_pdo_entry_t)
+#define EC_IOCTL_SC_DC EC_IOW(0x31, ec_ioctl_config_t)
+#define EC_IOCTL_SC_SDO EC_IOW(0x32, ec_ioctl_sc_sdo_t)
+#define EC_IOCTL_SC_SDO_REQUEST EC_IOWR(0x33, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_SC_VOE EC_IOWR(0x34, ec_ioctl_voe_t)
+#define EC_IOCTL_SC_STATE EC_IOWR(0x35, ec_ioctl_sc_state_t)
+#define EC_IOCTL_SC_IDN EC_IOW(0x36, ec_ioctl_sc_idn_t)
+#define EC_IOCTL_DOMAIN_OFFSET EC_IO(0x37)
+#define EC_IOCTL_DOMAIN_PROCESS EC_IO(0x38)
+#define EC_IOCTL_DOMAIN_QUEUE EC_IO(0x39)
+#define EC_IOCTL_DOMAIN_STATE EC_IOWR(0x3a, ec_ioctl_domain_state_t)
+#define EC_IOCTL_SDO_REQUEST_TIMEOUT EC_IOWR(0x3b, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_SDO_REQUEST_STATE EC_IOWR(0x3c, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_SDO_REQUEST_READ EC_IOWR(0x3d, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_SDO_REQUEST_WRITE EC_IOWR(0x3e, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_SDO_REQUEST_DATA EC_IOWR(0x3f, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_VOE_SEND_HEADER EC_IOW(0x40, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_REC_HEADER EC_IOWR(0x41, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_READ EC_IOW(0x42, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_READ_NOSYNC EC_IOW(0x43, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_WRITE EC_IOWR(0x44, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_EXEC EC_IOWR(0x45, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_DATA EC_IOWR(0x46, ec_ioctl_voe_t)
+#define EC_IOCTL_SET_SEND_INTERVAL EC_IOW(0x47, size_t)
/*****************************************************************************/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tool/CommandRescan.cpp Thu Sep 16 10:16:12 2010 +0200
@@ -0,0 +1,85 @@
+/*****************************************************************************
+ *
+ * $Id$
+ *
+ * Copyright (C) 2006-2009 Florian Pose, Ingenieurgemeinschaft IgH
+ *
+ * This file is part of the IgH EtherCAT Master.
+ *
+ * The IgH EtherCAT Master is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 2, as
+ * published by the Free Software Foundation.
+ *
+ * The IgH EtherCAT Master is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with the IgH EtherCAT Master; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * ---
+ *
+ * The license mentioned above concerns the source code only. Using the
+ * EtherCAT technology and brand is only permitted in compliance with the
+ * industrial property and similar rights of Beckhoff Automation GmbH.
+ *
+ * vim: expandtab
+ *
+ ****************************************************************************/
+
+#include <sstream>
+#include <iomanip>
+using namespace std;
+
+#include "CommandRescan.h"
+#include "MasterDevice.h"
+
+/*****************************************************************************/
+
+CommandRescan::CommandRescan():
+ Command("rescan", "Rescan the bus.")
+{
+}
+
+/*****************************************************************************/
+
+string CommandRescan::helpString() const
+{
+ stringstream str;
+
+ str << getName() << endl
+ << endl
+ << getBriefDescription() << endl
+ << endl
+ << "Command a bus rescan. Gathered slave information will be" << endl
+ << "forgotten and slaves will be read in again." << endl
+ << endl;
+
+ return str.str();
+}
+
+/****************************************************************************/
+
+void CommandRescan::execute(const StringVector &args)
+{
+ MasterIndexList masterIndices;
+
+ if (args.size() != 0) {
+ stringstream err;
+ err << "'" << getName() << "' takes no arguments!";
+ throwInvalidUsageException(err);
+ }
+
+ masterIndices = getMasterIndices();
+ MasterIndexList::const_iterator mi;
+ for (mi = masterIndices.begin();
+ mi != masterIndices.end(); mi++) {
+ MasterDevice m(*mi);
+ m.open(MasterDevice::ReadWrite);
+ m.rescan();
+ }
+}
+
+/*****************************************************************************/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tool/CommandRescan.h Thu Sep 16 10:16:12 2010 +0200
@@ -0,0 +1,49 @@
+/*****************************************************************************
+ *
+ * $Id$
+ *
+ * Copyright (C) 2006-2009 Florian Pose, Ingenieurgemeinschaft IgH
+ *
+ * This file is part of the IgH EtherCAT Master.
+ *
+ * The IgH EtherCAT Master is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 2, as
+ * published by the Free Software Foundation.
+ *
+ * The IgH EtherCAT Master is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with the IgH EtherCAT Master; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * ---
+ *
+ * The license mentioned above concerns the source code only. Using the
+ * EtherCAT technology and brand is only permitted in compliance with the
+ * industrial property and similar rights of Beckhoff Automation GmbH.
+ *
+ ****************************************************************************/
+
+#ifndef __COMMANDRESCAN_H__
+#define __COMMANDRESCAN_H__
+
+#include "Command.h"
+
+/****************************************************************************/
+
+class CommandRescan:
+ public Command
+{
+ public:
+ CommandRescan();
+
+ string helpString() const;
+ void execute(const StringVector &);
+};
+
+/****************************************************************************/
+
+#endif
--- a/tool/Makefile.am Thu Aug 05 09:54:06 2010 +0200
+++ b/tool/Makefile.am Thu Sep 16 10:16:12 2010 +0200
@@ -52,6 +52,7 @@
CommandPdos.cpp \
CommandRegRead.cpp \
CommandRegWrite.cpp \
+ CommandRescan.cpp \
CommandSdos.cpp \
CommandSiiRead.cpp \
CommandSiiWrite.cpp \
@@ -93,6 +94,7 @@
CommandPdos.h \
CommandRegRead.h \
CommandRegWrite.h \
+ CommandRescan.h \
CommandSdos.h \
CommandSiiRead.h \
CommandSiiWrite.h \
--- a/tool/MasterDevice.cpp Thu Aug 05 09:54:06 2010 +0200
+++ b/tool/MasterDevice.cpp Thu Sep 16 10:16:12 2010 +0200
@@ -455,6 +455,17 @@
/****************************************************************************/
+void MasterDevice::rescan()
+{
+ if (ioctl(fd, EC_IOCTL_MASTER_RESCAN, 0) < 0) {
+ stringstream err;
+ err << "Failed to command rescan: " << strerror(errno);
+ throw MasterDeviceException(err);
+ }
+}
+
+/****************************************************************************/
+
void MasterDevice::sdoDownload(ec_ioctl_slave_sdo_download_t *data)
{
if (ioctl(fd, EC_IOCTL_SLAVE_SDO_DOWNLOAD, data) < 0) {
--- a/tool/MasterDevice.h Thu Aug 05 09:54:06 2010 +0200
+++ b/tool/MasterDevice.h Thu Sep 16 10:16:12 2010 +0200
@@ -132,6 +132,7 @@
void readReg(ec_ioctl_slave_reg_t *);
void writeReg(ec_ioctl_slave_reg_t *);
void setDebug(unsigned int);
+ void rescan();
void sdoDownload(ec_ioctl_slave_sdo_download_t *);
void sdoUpload(ec_ioctl_slave_sdo_upload_t *);
void requestState(uint16_t, uint8_t);
--- a/tool/main.cpp Thu Aug 05 09:54:06 2010 +0200
+++ b/tool/main.cpp Thu Sep 16 10:16:12 2010 +0200
@@ -52,6 +52,7 @@
#include "CommandPdos.h"
#include "CommandRegRead.h"
#include "CommandRegWrite.h"
+#include "CommandRescan.h"
#include "CommandSdos.h"
#include "CommandSiiRead.h"
#include "CommandSiiWrite.h"
@@ -307,6 +308,7 @@
commandList.push_back(new CommandPdos());
commandList.push_back(new CommandRegRead());
commandList.push_back(new CommandRegWrite());
+ commandList.push_back(new CommandRescan());
commandList.push_back(new CommandSdos());
commandList.push_back(new CommandSiiRead());
commandList.push_back(new CommandSiiWrite());