Added ecrt_master_reset() method.
authorFlorian Pose <fp@igh-essen.com>
Tue, 30 Nov 2010 15:24:21 +0100
changeset 2009 b5391b329b5d
parent 1977 e9f722488fcd
child 2011 04fdb4abf120
Added ecrt_master_reset() method.
include/ecrt.h
lib/master.c
master/cdev.c
master/ioctl.h
master/master.c
--- a/include/ecrt.h	Mon Oct 25 17:06:45 2010 +0200
+++ b/include/ecrt.h	Tue Nov 30 15:24:21 2010 +0100
@@ -78,6 +78,7 @@
  * - Added ecrt_slave_config_idn() method for storing SoE IDN configurations,
  *   and ecrt_master_read_idn() and ecrt_master_write_idn() to read/write IDNs
  *   ad-hoc via the user-space library.
+ * - Added ecrt_master_reset() to initiate retrying to configure slaves.
  *
  * @{
  */
@@ -859,6 +860,17 @@
         ec_master_t *master /**< EtherCAT master. */
         );
 
+/** Retry configuring slaves.
+ *
+ * Via this method, the application can tell the master to bring all slaves to
+ * OP state. In general, this is not necessary, because it is automatically
+ * done by the master. But with special slaves, that can be reconfigured by
+ * the vendor during runtime, it can be useful.
+ */
+void ecrt_master_reset(
+        ec_master_t *master /**< EtherCAT master. */
+        );
+
 /******************************************************************************
  * Slave configuration methods
  *****************************************************************************/
--- a/lib/master.c	Mon Oct 25 17:06:45 2010 +0200
+++ b/lib/master.c	Tue Nov 30 15:24:21 2010 +0100
@@ -572,3 +572,12 @@
 }
 
 /*****************************************************************************/
+
+void ecrt_master_reset(ec_master_t *master)
+{
+    if (ioctl(master->fd, EC_IOCTL_RESET, NULL) == -1) {
+        fprintf(stderr, "Failed to reset master: %s\n", strerror(errno));
+    }
+}
+
+/*****************************************************************************/
--- a/master/cdev.c	Mon Oct 25 17:06:45 2010 +0200
+++ b/master/cdev.c	Tue Nov 30 15:24:21 2010 +0100
@@ -1992,6 +1992,25 @@
 
 /*****************************************************************************/
 
+/** Reset configuration.
+ */
+int ec_cdev_ioctl_reset(
+        ec_master_t *master, /**< EtherCAT master. */
+        unsigned long arg, /**< ioctl() argument. */
+        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
+        )
+{
+    if (unlikely(!priv->requested))
+        return -EPERM;
+
+    down(&master->master_sem);
+    ecrt_master_reset(master);
+    up(&master->master_sem);
+    return 0;
+}
+
+/*****************************************************************************/
+
 /** Configure a sync manager.
  */
 int ec_cdev_ioctl_sc_sync(
@@ -3671,6 +3690,10 @@
             if (!(filp->f_mode & FMODE_WRITE))
                 return -EPERM;
             return ec_cdev_ioctl_sync_mon_process(master, arg, priv);
+        case EC_IOCTL_RESET:
+            if (!(filp->f_mode & FMODE_WRITE))
+                return -EPERM;
+            return ec_cdev_ioctl_reset(master, arg, priv);
         case EC_IOCTL_SC_SYNC:
             if (!(filp->f_mode & FMODE_WRITE))
                 return -EPERM;
--- a/master/ioctl.h	Mon Oct 25 17:06:45 2010 +0200
+++ b/master/ioctl.h	Tue Nov 30 15:24:21 2010 +0100
@@ -56,7 +56,7 @@
  *
  * Increment this when changing the ioctl interface!
  */
-#define EC_IOCTL_VERSION_MAGIC 10
+#define EC_IOCTL_VERSION_MAGIC 11
 
 // Command-line tool
 #define EC_IOCTL_MODULE                EC_IOR(0x00, ec_ioctl_module_t)
@@ -95,7 +95,7 @@
 // Application interface
 #define EC_IOCTL_REQUEST                EC_IO(0x1e)
 #define EC_IOCTL_CREATE_DOMAIN          EC_IO(0x1f)
-#define EC_IOCTL_CREATE_SLAVE_CONFIG  EC_IOWR(0x10, ec_ioctl_config_t)
+#define EC_IOCTL_CREATE_SLAVE_CONFIG  EC_IOWR(0x20, ec_ioctl_config_t)
 #define EC_IOCTL_ACTIVATE              EC_IOR(0x21, size_t)
 #define EC_IOCTL_DEACTIVATE             EC_IO(0x22)
 #define EC_IOCTL_SEND                   EC_IO(0x23)
@@ -106,36 +106,37 @@
 #define EC_IOCTL_SYNC_SLAVES            EC_IO(0x28)
 #define EC_IOCTL_SYNC_MON_QUEUE         EC_IO(0x29)
 #define EC_IOCTL_SYNC_MON_PROCESS      EC_IOR(0x2a, uint32_t)
-#define EC_IOCTL_SC_SYNC               EC_IOW(0x2b, ec_ioctl_config_t)
-#define EC_IOCTL_SC_WATCHDOG           EC_IOW(0x2c, ec_ioctl_config_t)
-#define EC_IOCTL_SC_ADD_PDO            EC_IOW(0x2d, ec_ioctl_config_pdo_t)
-#define EC_IOCTL_SC_CLEAR_PDOS         EC_IOW(0x2e, ec_ioctl_config_pdo_t)
-#define EC_IOCTL_SC_ADD_ENTRY          EC_IOW(0x2f, ec_ioctl_add_pdo_entry_t)
-#define EC_IOCTL_SC_CLEAR_ENTRIES      EC_IOW(0x20, ec_ioctl_config_pdo_t)
-#define EC_IOCTL_SC_REG_PDO_ENTRY     EC_IOWR(0x21, ec_ioctl_reg_pdo_entry_t)
-#define EC_IOCTL_SC_DC                 EC_IOW(0x32, ec_ioctl_config_t)
-#define EC_IOCTL_SC_SDO                EC_IOW(0x33, ec_ioctl_sc_sdo_t)
-#define EC_IOCTL_SC_SDO_REQUEST       EC_IOWR(0x34, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_SC_VOE               EC_IOWR(0x35, ec_ioctl_voe_t)
-#define EC_IOCTL_SC_STATE             EC_IOWR(0x36, ec_ioctl_sc_state_t)
-#define EC_IOCTL_SC_IDN                EC_IOW(0x37, ec_ioctl_sc_idn_t)
-#define EC_IOCTL_DOMAIN_OFFSET          EC_IO(0x38)
-#define EC_IOCTL_DOMAIN_PROCESS         EC_IO(0x39)
-#define EC_IOCTL_DOMAIN_QUEUE           EC_IO(0x3a)
-#define EC_IOCTL_DOMAIN_STATE         EC_IOWR(0x3b, ec_ioctl_domain_state_t)
-#define EC_IOCTL_SDO_REQUEST_TIMEOUT  EC_IOWR(0x3c, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_SDO_REQUEST_STATE    EC_IOWR(0x3d, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_SDO_REQUEST_READ     EC_IOWR(0x3e, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_SDO_REQUEST_WRITE    EC_IOWR(0x3f, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_SDO_REQUEST_DATA     EC_IOWR(0x30, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_VOE_SEND_HEADER       EC_IOW(0x41, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_REC_HEADER       EC_IOWR(0x42, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_READ              EC_IOW(0x43, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_READ_NOSYNC       EC_IOW(0x44, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_WRITE            EC_IOWR(0x45, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_EXEC             EC_IOWR(0x46, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_DATA             EC_IOWR(0x47, ec_ioctl_voe_t)
-#define EC_IOCTL_SET_SEND_INTERVAL     EC_IOW(0x48, size_t)
+#define EC_IOCTL_RESET                  EC_IO(0x2b)
+#define EC_IOCTL_SC_SYNC               EC_IOW(0x2c, ec_ioctl_config_t)
+#define EC_IOCTL_SC_WATCHDOG           EC_IOW(0x2d, ec_ioctl_config_t)
+#define EC_IOCTL_SC_ADD_PDO            EC_IOW(0x2e, ec_ioctl_config_pdo_t)
+#define EC_IOCTL_SC_CLEAR_PDOS         EC_IOW(0x2f, ec_ioctl_config_pdo_t)
+#define EC_IOCTL_SC_ADD_ENTRY          EC_IOW(0x30, ec_ioctl_add_pdo_entry_t)
+#define EC_IOCTL_SC_CLEAR_ENTRIES      EC_IOW(0x31, ec_ioctl_config_pdo_t)
+#define EC_IOCTL_SC_REG_PDO_ENTRY     EC_IOWR(0x32, ec_ioctl_reg_pdo_entry_t)
+#define EC_IOCTL_SC_DC                 EC_IOW(0x33, ec_ioctl_config_t)
+#define EC_IOCTL_SC_SDO                EC_IOW(0x34, ec_ioctl_sc_sdo_t)
+#define EC_IOCTL_SC_SDO_REQUEST       EC_IOWR(0x35, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_SC_VOE               EC_IOWR(0x36, ec_ioctl_voe_t)
+#define EC_IOCTL_SC_STATE             EC_IOWR(0x37, ec_ioctl_sc_state_t)
+#define EC_IOCTL_SC_IDN                EC_IOW(0x38, ec_ioctl_sc_idn_t)
+#define EC_IOCTL_DOMAIN_OFFSET          EC_IO(0x39)
+#define EC_IOCTL_DOMAIN_PROCESS         EC_IO(0x3a)
+#define EC_IOCTL_DOMAIN_QUEUE           EC_IO(0x3b)
+#define EC_IOCTL_DOMAIN_STATE         EC_IOWR(0x3c, ec_ioctl_domain_state_t)
+#define EC_IOCTL_SDO_REQUEST_TIMEOUT  EC_IOWR(0x3d, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_SDO_REQUEST_STATE    EC_IOWR(0x3e, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_SDO_REQUEST_READ     EC_IOWR(0x3f, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_SDO_REQUEST_WRITE    EC_IOWR(0x40, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_SDO_REQUEST_DATA     EC_IOWR(0x41, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_VOE_SEND_HEADER       EC_IOW(0x42, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_REC_HEADER       EC_IOWR(0x43, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_READ              EC_IOW(0x44, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_READ_NOSYNC       EC_IOW(0x45, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_WRITE            EC_IOWR(0x46, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_EXEC             EC_IOWR(0x47, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_DATA             EC_IOWR(0x48, ec_ioctl_voe_t)
+#define EC_IOCTL_SET_SEND_INTERVAL     EC_IOW(0x49, size_t)
 
 /*****************************************************************************/
 
--- a/master/master.c	Mon Oct 25 17:06:45 2010 +0200
+++ b/master/master.c	Tue Nov 30 15:24:21 2010 +0100
@@ -2501,6 +2501,19 @@
 
 /*****************************************************************************/
 
+void ecrt_master_reset(ec_master_t *master)
+{
+    ec_slave_config_t *sc;
+
+    list_for_each_entry(sc, &master->configs, list) {
+        if (sc->slave) {
+            ec_slave_request_state(sc->slave, EC_SLAVE_STATE_OP);
+        }
+    }
+}
+
+/*****************************************************************************/
+
 /** \cond */
 
 EXPORT_SYMBOL(ecrt_master_create_domain);
@@ -2521,6 +2534,7 @@
 EXPORT_SYMBOL(ecrt_master_sync_monitor_process);
 EXPORT_SYMBOL(ecrt_master_write_idn);
 EXPORT_SYMBOL(ecrt_master_read_idn);
+EXPORT_SYMBOL(ecrt_master_reset);
 
 /** \endcond */