Added ec_master_find_slave_const().
authorFlorian Pose <fp@igh-essen.com>
Wed, 02 Jul 2008 08:14:47 +0000
changeset 1077 c95cd717b852
parent 1076 e62b492aab51
child 1078 fce58ba8a912
Added ec_master_find_slave_const().
master/master.c
master/master.h
--- a/master/master.c	Tue Jul 01 15:41:52 2008 +0000
+++ b/master/master.c	Wed Jul 02 08:14:47 2008 +0000
@@ -1023,6 +1023,29 @@
 
 /*****************************************************************************/
 
+/** Common implementation for ec_master_find_slave()
+ * and ec_master_find_slave_const().
+ */
+#define EC_FIND_SLAVE \
+    do { \
+        if (alias) { \
+            for (; slave < master->slaves + master->slave_count; \
+                    slave++) { \
+                if (slave->sii.alias == alias) \
+                break; \
+            } \
+            if (slave == master->slaves + master->slave_count) \
+            return NULL; \
+        } \
+        \
+        slave += position; \
+        if (slave < master->slaves + master->slave_count) { \
+            return slave; \
+        } else { \
+            return NULL; \
+        } \
+    } while (0)
+
 /** Finds a slave in the bus, given the alias and position.
  */
 ec_slave_t *ec_master_find_slave(
@@ -1032,24 +1055,21 @@
         )
 {
     ec_slave_t *slave = master->slaves;
-
-    if (alias) {
-        // find slave with the given alias
-        for (; slave < master->slaves + master->slave_count;
-                slave++) {
-			if (slave->sii.alias == alias)
-                break;
-		}
-        if (slave == master->slaves + master->slave_count)
-            return NULL;
-	}
-
-    slave += position;
-    if (slave < master->slaves + master->slave_count) {
-        return slave;
-    } else {
-        return NULL;
-    }
+    EC_FIND_SLAVE;
+}
+
+/** Finds a slave in the bus, given the alias and position.
+ *
+ * Const version.
+ */
+const ec_slave_t *ec_master_find_slave_const(
+        const ec_master_t *master, /**< EtherCAT master. */
+        uint16_t alias, /**< Slave alias. */
+        uint16_t position /**< Slave position. */
+        )
+{
+    const ec_slave_t *slave = master->slaves;
+    EC_FIND_SLAVE;
 }
 
 /*****************************************************************************/
--- a/master/master.h	Tue Jul 01 15:41:52 2008 +0000
+++ b/master/master.h	Wed Jul 02 08:14:47 2008 +0000
@@ -190,6 +190,8 @@
 // misc.
 void ec_master_attach_slave_configs(ec_master_t *);
 ec_slave_t *ec_master_find_slave(ec_master_t *, uint16_t, uint16_t);
+const ec_slave_t *ec_master_find_slave_const(const ec_master_t *, uint16_t,
+        uint16_t);
 void ec_master_output_stats(ec_master_t *);
 #ifdef EC_EOE
 void ec_master_clear_eoe_handlers(ec_master_t *);