Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
authorFlorian Pose <fp@igh-essen.com>
Tue, 27 Apr 2010 10:37:32 +0200
changeset 1913 cbef34ba142b
parent 1912 d480e0439664
child 1914 da7adbde2625
Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
IDNs ad-hoc using the library.
include/ecrt.h
lib/master.c
--- a/include/ecrt.h	Tue Apr 27 10:30:31 2010 +0200
+++ b/include/ecrt.h	Tue Apr 27 10:37:32 2010 +0200
@@ -75,7 +75,9 @@
  * - Removed 'const' from argument of ecrt_sdo_request_state(), because the
  *   userspace library has to modify object internals.
  * - Added 64-bit data access macros.
- * - Added ecrt_slave_config_idn() method for storing SoE IDN configurations.
+ * - 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.
  *
  * @{
  */
@@ -661,6 +663,44 @@
         uint32_t *abort_code /**< Abort code of the SDO upload. */
         );
 
+/** Executes an SoE write request.
+ *
+ * Starts writing an IDN and blocks until the request was processed, or an
+ * error occurred.
+ *
+ * \retval  0 Success.
+ * \retval -1 An error occured.
+ */
+int ecrt_master_write_idn(
+        ec_master_t *master, /**< EtherCAT master. */
+        uint16_t slave_position, /**< Slave position. */
+        uint16_t idn, /**< SoE IDN (see ecrt_slave_config_idn()). */
+        uint8_t *data, /**< Pointer to data to write. */
+        size_t data_size, /**< Size of data to write. */
+        uint32_t *error_code /**< Pointer to variable, where an SoE error code
+                               can be stored. */
+        );
+
+/** Executes an SoE read request.
+ *
+ * Starts reading an IDN and blocks until the request was processed, or an
+ * error occurred.
+ *
+ * \retval  0 Success.
+ * \retval -1 An error occured.
+ */
+int ecrt_master_read_idn(
+        ec_master_t *master, /**< EtherCAT master. */
+        uint16_t slave_position, /**< Slave position. */
+        uint16_t idn, /**< SoE IDN (see ecrt_slave_config_idn()). */
+        uint8_t *target, /**< Pointer to memory where the read data can be
+                           stored. */
+        size_t target_size, /**< Size of the memory \a target points to. */
+        size_t *result_size, /**< Actual size of the received data. */
+        uint32_t *error_code /**< Pointer to variable, where an SoE error code
+                               can be stored. */
+        );
+
 #endif /* #ifndef __KERNEL__ */
 
 /** Finishes the configuration phase and prepares for cyclic operation.
--- a/lib/master.c	Tue Apr 27 10:30:31 2010 +0200
+++ b/lib/master.c	Tue Apr 27 10:37:32 2010 +0200
@@ -304,6 +304,54 @@
 
 /*****************************************************************************/
 
+int ecrt_master_write_idn(ec_master_t *master, uint16_t slave_position,
+        uint16_t idn, uint8_t *data, size_t data_size, uint32_t *error_code)
+{
+    ec_ioctl_slave_soe_write_t io;
+
+    io.slave_position = slave_position;
+    io.idn = idn;
+    io.data_size = data_size;
+    io.data = data;
+
+    if (ioctl(master->fd, EC_IOCTL_SLAVE_SOE_WRITE, &io) == -1) {
+        if (errno == EIO && error_code) {
+            *error_code = io.error_code;
+        }
+        fprintf(stderr, "Failed to write IDN: %s\n", strerror(errno));
+        return -1;
+    }
+
+    return 0;
+}
+
+/*****************************************************************************/
+
+int ecrt_master_read_idn(ec_master_t *master, uint16_t slave_position,
+        uint16_t idn, uint8_t *target, size_t target_size,
+        size_t *result_size, uint32_t *error_code)
+{
+    ec_ioctl_slave_soe_read_t io;
+
+    io.slave_position = slave_position;
+    io.idn = idn;
+    io.mem_size = target_size;
+    io.data = target;
+
+    if (ioctl(master->fd, EC_IOCTL_SLAVE_SOE_READ, &io) == -1) {
+        if (errno == EIO && error_code) {
+            *error_code = io.error_code;
+        }
+        fprintf(stderr, "Failed to read IDN: %s\n", strerror(errno));
+        return -1;
+    }
+
+    *result_size = io.data_size;
+    return 0;
+}
+
+/*****************************************************************************/
+
 int ecrt_master_activate(ec_master_t *master)
 {
     if (ioctl(master->fd, EC_IOCTL_ACTIVATE,