Implemented ecrt_master_deactivate() in userspace.
authorFlorian Pose <fp@igh-essen.com>
Thu, 20 Aug 2009 14:43:55 +0200
changeset 1531 6c5478400e28
parent 1530 96629de2202b
child 1532 b1d1317f1c7a
Implemented ecrt_master_deactivate() in userspace.
TODO
lib/master.c
master/cdev.c
master/ioctl.h
--- a/TODO	Thu Aug 20 14:27:35 2009 +0200
+++ b/TODO	Thu Aug 20 14:43:55 2009 +0200
@@ -52,7 +52,6 @@
 * Implement CompleteAccess for SDO uploads.
 * Implement identifier parameter for cstruct command.
 * Implement sync delimiter for cstruct command.
-* Implement ecrt_master_deactivate() in userspace.
 
 Future issues:
 
--- a/lib/master.c	Thu Aug 20 14:27:35 2009 +0200
+++ b/lib/master.c	Thu Aug 20 14:43:55 2009 +0200
@@ -335,6 +335,16 @@
 
 /*****************************************************************************/
 
+void ecrt_master_deactivate(ec_master_t *master)
+{
+    if (ioctl(master->fd, EC_IOCTL_DEACTIVATE, NULL) == -1) {
+        fprintf(stderr, "Failed to deactivate master: %s\n", strerror(errno));
+        return;
+    }
+}
+
+/*****************************************************************************/
+
 void ecrt_master_send(ec_master_t *master)
 {
     if (ioctl(master->fd, EC_IOCTL_SEND, NULL) == -1) {
--- a/master/cdev.c	Thu Aug 20 14:27:35 2009 +0200
+++ b/master/cdev.c	Thu Aug 20 14:43:55 2009 +0200
@@ -1648,6 +1648,23 @@
 
 /*****************************************************************************/
 
+/** Deactivates the master.
+ */
+int ec_cdev_ioctl_deactivate(
+        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;
+
+    ecrt_master_deactivate(master);
+    return 0;
+}
+
+/*****************************************************************************/
+
 /** Send frames.
  */
 int ec_cdev_ioctl_send(
@@ -3263,6 +3280,10 @@
             if (!(filp->f_mode & FMODE_WRITE))
                 return -EPERM;
             return ec_cdev_ioctl_activate(master, arg, priv);
+        case EC_IOCTL_DEACTIVATE:
+            if (!(filp->f_mode & FMODE_WRITE))
+                return -EPERM;
+            return ec_cdev_ioctl_deactivate(master, arg, priv);
         case EC_IOCTL_SEND:
             if (!(filp->f_mode & FMODE_WRITE))
                 return -EPERM;
--- a/master/ioctl.h	Thu Aug 20 14:27:35 2009 +0200
+++ b/master/ioctl.h	Thu Aug 20 14:43:55 2009 +0200
@@ -86,40 +86,41 @@
 #define EC_IOCTL_CREATE_DOMAIN          EC_IO(0x1a)
 #define EC_IOCTL_CREATE_SLAVE_CONFIG  EC_IOWR(0x1b, ec_ioctl_config_t)
 #define EC_IOCTL_ACTIVATE              EC_IOR(0x1c, size_t)
-#define EC_IOCTL_SEND                   EC_IO(0x1d)
-#define EC_IOCTL_RECEIVE                EC_IO(0x1e)
-#define EC_IOCTL_MASTER_STATE          EC_IOR(0x1f, ec_master_state_t)
-#define EC_IOCTL_APP_TIME              EC_IOW(0x20, ec_ioctl_app_time_t)
-#define EC_IOCTL_SYNC_REF               EC_IO(0x21)
-#define EC_IOCTL_SYNC_SLAVES            EC_IO(0x22)
-#define EC_IOCTL_SC_SYNC               EC_IOW(0x23, ec_ioctl_config_t)
-#define EC_IOCTL_SC_WATCHDOG           EC_IOW(0x24, ec_ioctl_config_t)
-#define EC_IOCTL_SC_ADD_PDO            EC_IOW(0x25, ec_ioctl_config_pdo_t)
-#define EC_IOCTL_SC_CLEAR_PDOS         EC_IOW(0x26, ec_ioctl_config_pdo_t)
-#define EC_IOCTL_SC_ADD_ENTRY          EC_IOW(0x27, ec_ioctl_add_pdo_entry_t)
-#define EC_IOCTL_SC_CLEAR_ENTRIES      EC_IOW(0x28, ec_ioctl_config_pdo_t)
-#define EC_IOCTL_SC_REG_PDO_ENTRY     EC_IOWR(0x29, ec_ioctl_reg_pdo_entry_t)
-#define EC_IOCTL_SC_DC                 EC_IOW(0x2a, ec_ioctl_config_t)
-#define EC_IOCTL_SC_SDO                EC_IOW(0x2b, ec_ioctl_sc_sdo_t)
-#define EC_IOCTL_SC_SDO_REQUEST       EC_IOWR(0x2c, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_SC_VOE               EC_IOWR(0x2d, ec_ioctl_voe_t)
-#define EC_IOCTL_SC_STATE             EC_IOWR(0x2e, ec_ioctl_sc_state_t)
-#define EC_IOCTL_DOMAIN_OFFSET          EC_IO(0x2f)
-#define EC_IOCTL_DOMAIN_PROCESS         EC_IO(0x20)
-#define EC_IOCTL_DOMAIN_QUEUE           EC_IO(0x31)
-#define EC_IOCTL_DOMAIN_STATE         EC_IOWR(0x32, ec_ioctl_domain_state_t)
-#define EC_IOCTL_SDO_REQUEST_TIMEOUT  EC_IOWR(0x33, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_SDO_REQUEST_STATE    EC_IOWR(0x34, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_SDO_REQUEST_READ     EC_IOWR(0x35, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_SDO_REQUEST_WRITE    EC_IOWR(0x36, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_SDO_REQUEST_DATA     EC_IOWR(0x37, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_VOE_SEND_HEADER       EC_IOW(0x38, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_REC_HEADER       EC_IOWR(0x39, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_READ              EC_IOW(0x3a, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_READ_NOSYNC       EC_IOW(0x3b, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_WRITE            EC_IOWR(0x3c, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_EXEC             EC_IOWR(0x3d, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_DATA             EC_IOWR(0x3e, ec_ioctl_voe_t)
+#define EC_IOCTL_DEACTIVATE             EC_IO(0x1d)
+#define EC_IOCTL_SEND                   EC_IO(0x1e)
+#define EC_IOCTL_RECEIVE                EC_IO(0x1f)
+#define EC_IOCTL_MASTER_STATE          EC_IOR(0x20, ec_master_state_t)
+#define EC_IOCTL_APP_TIME              EC_IOW(0x21, ec_ioctl_app_time_t)
+#define EC_IOCTL_SYNC_REF               EC_IO(0x22)
+#define EC_IOCTL_SYNC_SLAVES            EC_IO(0x23)
+#define EC_IOCTL_SC_SYNC               EC_IOW(0x24, ec_ioctl_config_t)
+#define EC_IOCTL_SC_WATCHDOG           EC_IOW(0x25, ec_ioctl_config_t)
+#define EC_IOCTL_SC_ADD_PDO            EC_IOW(0x26, ec_ioctl_config_pdo_t)
+#define EC_IOCTL_SC_CLEAR_PDOS         EC_IOW(0x27, ec_ioctl_config_pdo_t)
+#define EC_IOCTL_SC_ADD_ENTRY          EC_IOW(0x28, ec_ioctl_add_pdo_entry_t)
+#define EC_IOCTL_SC_CLEAR_ENTRIES      EC_IOW(0x29, ec_ioctl_config_pdo_t)
+#define EC_IOCTL_SC_REG_PDO_ENTRY     EC_IOWR(0x2a, ec_ioctl_reg_pdo_entry_t)
+#define EC_IOCTL_SC_DC                 EC_IOW(0x2b, ec_ioctl_config_t)
+#define EC_IOCTL_SC_SDO                EC_IOW(0x2c, ec_ioctl_sc_sdo_t)
+#define EC_IOCTL_SC_SDO_REQUEST       EC_IOWR(0x2d, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_SC_VOE               EC_IOWR(0x2e, ec_ioctl_voe_t)
+#define EC_IOCTL_SC_STATE             EC_IOWR(0x2f, ec_ioctl_sc_state_t)
+#define EC_IOCTL_DOMAIN_OFFSET          EC_IO(0x20)
+#define EC_IOCTL_DOMAIN_PROCESS         EC_IO(0x31)
+#define EC_IOCTL_DOMAIN_QUEUE           EC_IO(0x32)
+#define EC_IOCTL_DOMAIN_STATE         EC_IOWR(0x33, ec_ioctl_domain_state_t)
+#define EC_IOCTL_SDO_REQUEST_TIMEOUT  EC_IOWR(0x34, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_SDO_REQUEST_STATE    EC_IOWR(0x35, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_SDO_REQUEST_READ     EC_IOWR(0x36, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_SDO_REQUEST_WRITE    EC_IOWR(0x37, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_SDO_REQUEST_DATA     EC_IOWR(0x38, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_VOE_SEND_HEADER       EC_IOW(0x39, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_REC_HEADER       EC_IOWR(0x3a, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_READ              EC_IOW(0x3b, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_READ_NOSYNC       EC_IOW(0x3c, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_WRITE            EC_IOWR(0x3d, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_EXEC             EC_IOWR(0x3e, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_DATA             EC_IOWR(0x3f, ec_ioctl_voe_t)
 
 /*****************************************************************************/