Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
authorFlorian Pose <fp@igh-essen.com>
Tue, 05 May 2009 08:15:02 +0000
changeset 1441 27a8d6f97a95
parent 1440 1b32fe09c689
child 1442 52e1fd1603a7
Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
S. Weiser.
NEWS
include/ecrt.h
lib/master.c
--- a/NEWS	Mon May 04 13:53:41 2009 +0000
+++ b/NEWS	Tue May 05 08:15:02 2009 +0000
@@ -36,6 +36,9 @@
 * Output device link state in 'ethercat master'.
 * Added 'ethercat graph' command which outputs the bus topology in
   DOT language.
+* Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download() methods to let
+  an application transfer SDOs before activating the master. Thanks to Stefan
+  Weiser.
 
 Changes in 1.4.0:
 
--- a/include/ecrt.h	Mon May 04 13:53:41 2009 +0000
+++ b/include/ecrt.h	Tue May 05 08:15:02 2009 +0000
@@ -55,6 +55,8 @@
  * - Renamed ec_sdo_request_state_t to ec_request_state_t, because it is also
  *   used by VoE handlers.
  * - Added ecrt_master_slave() to get information about a certain slave.
+ * - Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download() methods to
+ *   let an application transfer SDOs before activating the master.
  * - Removed 'const' from argument of ecrt_sdo_request_state(), because the
  *   userspace library has to modify object internals.
  * - Added 64-bit data access macros.
@@ -448,6 +450,8 @@
         uint32_t product_code /**< Expected product code. */
         );
 
+#ifndef __KERNEL__
+
 /** Obtains slave information.
  *
  * Tries to find the slave with the given ring position. The obtained
@@ -465,6 +469,8 @@
                                       information */
         );
 
+#endif /* ifndef __KERNEL__ */
+
 /** Finishes the configuration phase and prepares for cyclic operation.
  *
  * This function tells the master that the configuration phase is finished and
@@ -551,6 +557,50 @@
         ec_master_t *master /**< EtherCAT master. */
         );
 
+#ifndef __KERNEL__
+
+/** Executes an SDO write request to download data.
+ *
+ * This function operates aside of the normal way to request SDOs. Before the
+ * activation of the master, these requests are processed by the master state
+ * machine itself. After activation the user has to ensure cyclic processing.
+ *
+ * \retval  0 Success.
+ * \retval -1 An error occured.
+ */
+int ecrt_slave_sdo_download(
+        ec_master_t* master, /**< EtherCAT master. */
+        uint16_t slave_position, /**< Slave position. */
+        uint16_t index, /**< Index of the SDO. */
+        uint8_t subindex, /**< Subindex of the SDO. */
+        uint8_t *data, /**< Data buffer to download. */
+        size_t data_size, /**< Size of the data buffer. */
+        uint32_t *abort_code /**< Abort code of the SDO download. */
+        );
+
+/** Executes a SDO read request to upload data.
+ *
+ * This function operates aside of the normal way to request SDOs. Before the
+ * activation of the master, these requests are processed by the master state
+ * machine itself. After activation the user have to ensure cyclic
+ * processing.
+ *
+ * \retval  0 Success.
+ * \retval -1 Error occured.
+ */
+int ecrt_slave_sdo_upload(
+        ec_master_t* master, /**< EtherCAT master. */
+        uint16_t slave_position, /**< Slave position. */
+        uint16_t index, /**< Index of the SDO. */
+        uint8_t subindex, /**< Subindex of the SDO. */
+        uint8_t *target, /**< Target buffer for the upload. */
+        size_t target_size, /**< Size of the target buffer. */
+        size_t *result_size, /**< Uploaded data size. */
+        uint32_t *abort_code /**< Abort code of the SDO upload. */
+        );
+
+#endif /* ifndef __KERNEL__ */
+
 /******************************************************************************
  * Slave configuration methods
  *****************************************************************************/
--- a/lib/master.c	Mon May 04 13:53:41 2009 +0000
+++ b/lib/master.c	Tue May 05 08:15:02 2009 +0000
@@ -222,3 +222,60 @@
 }
 
 /*****************************************************************************/
+
+int ecrt_slave_sdo_download(ec_master_t* master, uint16_t slave_position,
+        uint16_t index, uint8_t subindex, uint8_t *data,
+        size_t data_size, uint32_t *abort_code)
+{
+    ec_ioctl_slave_sdo_download_t download;
+
+    download.slave_position = slave_position;
+    download.sdo_index = index;
+    download.sdo_entry_subindex = subindex;
+    download.data_size = data_size;
+    download.data = data;
+
+    if (ioctl(master->fd, EC_IOCTL_SLAVE_SDO_DOWNLOAD, &download) == -1) {
+        if (errno == -EIO) {
+            if (abort_code) {
+                *abort_code = download.abort_code;
+            }
+        }
+        fprintf(stderr, "Failed to execute SDO download: %s\n",
+            strerror(errno));
+        return -1;
+    }
+
+    return 0;
+}
+
+/*****************************************************************************/
+
+int ecrt_slave_sdo_upload(ec_master_t* master, uint16_t slave_position,
+        uint16_t index, uint8_t subindex, uint8_t *target,
+        size_t target_size, size_t *result_size, uint32_t *abort_code)
+{
+    ec_ioctl_slave_sdo_upload_t upload;
+
+    upload.slave_position = slave_position;
+    upload.sdo_index = index;
+    upload.sdo_entry_subindex = subindex;
+    upload.target_size = target_size;
+    upload.target = target;
+
+    if (ioctl(master->fd, EC_IOCTL_SLAVE_SDO_UPLOAD, &upload) == -1) {
+        if (errno == -EIO) {
+            if (abort_code) {
+                *abort_code = upload.abort_code;
+            }
+        }
+        fprintf(stderr, "Failed to execute SDO upload: %s\n",
+                strerror(errno));
+        return -1;
+    }
+
+    *result_size = upload.data_size;
+    return 0;
+}
+
+/*****************************************************************************/