From b6f2f64e0732d316fb09d97986c3689ad4697c7a Mon Sep 17 00:00:00 2001
From: Florian Pose <fp@igh-essen.com>
Date: Thu, 21 Feb 2008 09:50:54 +0000
Subject: [PATCH] Moved ecrt_domain_reg_pdo_entry() to
 ecrt_slave_config_reg_pdo_entry().

---
 include/ecrt.h        | 40 ++++++++++---------
 master/domain.c       | 13 +-----
 master/slave_config.c | 93 +++++++++++++++++++------------------------
 3 files changed, 66 insertions(+), 80 deletions(-)

diff --git a/include/ecrt.h b/include/ecrt.h
index e761ba01..07b5ce89 100644
--- a/include/ecrt.h
+++ b/include/ecrt.h
@@ -50,7 +50,7 @@
  * - Replaced slave address string with alias and position values. See
  *   ecrt_master_slave_config().
  * - Removed ecrt_master_get_slave_by_pos(), because it is no longer
- *   necessary (alias/position, slave configurations).
+ *   necessary due to alias/position addressing.
  * - Added ec_slave_config_state_t for the new method
  *   ecrt_slave_config_state().
  * - Process data memory for a domain can now be allocated externally. This
@@ -58,9 +58,10 @@
  *   added the domain methods ecrt_domain_size() and ecrt_domain_memory().
  * - Replaced the process data pointers in the Pdo entry registration
  *   functions with a process data offset, that is now returned by
- *   ecrt_domain_reg_pdo_entry(). This was necessary for the external
+ *   ecrt_slave_config_reg_pdo_entry(). This was necessary for the external
  *   domain memory. An additional advantage is, that the returned offset value
- *   is directly usable.
+ *   is directly usable. The domain's process data offset can be retrieved
+ *   with ecrt_domain_data().
  * - Replaced ecrt_slave_pdo_mapping/add/clear() with
  *   ecrt_slave_config_mapping() that is now able to specify Pdo mapping and
  *   Pdo configuration. Pdo entries mapped in this way can now immediately be
@@ -73,7 +74,7 @@
  *   of ecrt_domain_state().
  * - Former "Pdo registration" meant Pdo entry registration in fact, therefore
  *   renamed ec_pdo_reg_t to ec_pdo_entry_reg_t and ecrt_domain_register_pdo()
- *   to ecrt_domain_reg_pdo_entry().
+ *   to ecrt_slave_config_reg_pdo_entry().
  * - Removed ecrt_domain_register_pdo_range(), because it's functionality can
  *   be reached by specifying an explicit Pdo mapping and registering those
  *   Pdo entries.
@@ -415,6 +416,23 @@ int ecrt_slave_config_mapping(
         const ec_pdo_info_t pdos[] /**< List with Pdo mapping. */
         );
 
+/** Registers a Pdo entry of the given slave configuration at a domain.
+ *
+ * Searches the mapping and the Pdo configurations for the given Pdo entry. If
+ * found, the curresponding sync manager/FMMU is added to the domain and the
+ * offset of the Pdo entry's data in the domain process data is returned.
+ *
+ * \retval >=0 Offset of the Pdo entry's process data.
+ * \retval -1  Pdo entry not found.
+ * \retval -2  Failed to register Pdo entry.
+ */
+int ecrt_slave_config_reg_pdo_entry(
+        ec_slave_config_t *sc, /**< Slave configuration. */
+        uint16_t entry_index, /**< Index of the Pdo entry to register. */
+        uint8_t entry_subindex, /**< Subindex of the Pdo entry to register. */
+        ec_domain_t *domain /**< Domain. */
+        );
+
 /** Add a configuration value for an 8-bit SDO.
  *
  * \todo doc
@@ -464,20 +482,6 @@ void ecrt_slave_config_state(
  * Domain methods
  *****************************************************************************/
 
-/** Registers a single Pdo entry for a domain.
- *
- * \return On success, the function returns the offset in the domain's process
- *         data, which can be zero or greater. On failure, it returns a value
- *         less than zero.
- */
-
-int ecrt_domain_reg_pdo_entry(
-        ec_domain_t *domain, /**< Domain. */
-        ec_slave_config_t *sc, /**< Slave configuration. */
-        uint16_t entry_index, /**< Index of the Pdo entry to register. */
-        uint8_t entry_subindex /**< Subindex of the Pdo entry to register. */
-        );
-
 /** Registers a bunch of Pdo entries for a domain.
  *
  * \todo doc
diff --git a/master/domain.c b/master/domain.c
index a2afed24..80d691f6 100644
--- a/master/domain.c
+++ b/master/domain.c
@@ -278,14 +278,6 @@ ssize_t ec_show_domain_attribute(struct kobject *kobj, /**< kobject */
  *  Realtime interface
  *****************************************************************************/
 
-int ecrt_domain_reg_pdo_entry(ec_domain_t *domain, ec_slave_config_t *sc,
-        uint16_t index, uint8_t subindex)
-{
-    return ec_slave_config_reg_pdo_entry(sc, domain, index, subindex);
-}
-
-/*****************************************************************************/
-
 int ecrt_domain_reg_pdo_entry_list(ec_domain_t *domain,
         const ec_pdo_entry_reg_t *regs)
 {
@@ -298,8 +290,8 @@ int ecrt_domain_reg_pdo_entry_list(ec_domain_t *domain,
                         reg->position, reg->vendor_id, reg->product_code)))
             return -1;
 
-        if ((ret = ecrt_domain_reg_pdo_entry(domain, sc, reg->index,
-                        reg->subindex)) < 0)
+        if ((ret = ecrt_slave_config_reg_pdo_entry(sc, reg->index,
+                        reg->subindex, domain)) < 0)
             return -1;
 
         *reg->offset = ret;
@@ -371,7 +363,6 @@ void ecrt_domain_state(const ec_domain_t *domain, ec_domain_state_t *state)
 
 /** \cond */
 
-EXPORT_SYMBOL(ecrt_domain_reg_pdo_entry);
 EXPORT_SYMBOL(ecrt_domain_reg_pdo_entry_list);
 //EXPORT_SYMBOL(ecrt_domain_size);
 //EXPORT_SYMBOL(ecrt_domain_memory);
diff --git a/master/slave_config.c b/master/slave_config.c
index 4146ad00..bb9df0d4 100644
--- a/master/slave_config.c
+++ b/master/slave_config.c
@@ -221,57 +221,6 @@ int ec_slave_config_prepare_fmmu(
 
 /*****************************************************************************/
 
-/** Registers a Pdo entry.
- *
- * Searches the mapping and the Pdo configurations for the given Pdo entry. If
- * found, the curresponding sync manager/FMMU is added to the domain and the
- * offset of the Pdo entry's data in the domain process data is returned.
- *
- * \retval >=0 Offset of the Pdo entry's process data.
- * \retval -1  Pdo entry not found.
- * \retval -2  Failed to register Pdo entry.
- */
-int ec_slave_config_reg_pdo_entry(
-        ec_slave_config_t *sc, /**< Slave configuration. */
-        ec_domain_t *domain, /**< Domain. */
-        uint16_t index, /**< Index of Pdo entry to register. */
-        uint8_t subindex /**< Subindex of Pdo entry to register. */
-        )
-{
-    ec_direction_t dir;
-    ec_pdo_mapping_t *map;
-    unsigned int bit_offset, byte_offset;
-    ec_pdo_t *pdo;
-    ec_pdo_entry_t *entry;
-    int ret;
-
-    for (dir = EC_DIR_OUTPUT; dir <= EC_DIR_INPUT; dir++) {
-        map = &sc->mapping[dir];
-        bit_offset = 0;
-        list_for_each_entry(pdo, &map->pdos, list) {
-            list_for_each_entry(entry, &pdo->entries, list) {
-                if (entry->index != index || entry->subindex != subindex) {
-                    bit_offset += entry->bit_length;
-                } else {
-                    goto found;
-                }
-            }
-        }
-    }
-
-    EC_ERR("PDO entry 0x%04X:%u is not mapped in slave config %u:%u.\n",
-           index, subindex, sc->alias, sc->position);
-    return -1;
-
-found:
-    byte_offset = bit_offset / 8;
-    if ((ret = ec_slave_config_prepare_fmmu(sc, domain, dir)) < 0)
-        return -2;
-    return ret + byte_offset;
-}
-
-/*****************************************************************************/
-
 /** Outputs all information about a certain slave configuration.
 */
 ssize_t ec_slave_config_info(
@@ -504,6 +453,47 @@ int ecrt_slave_config_mapping(ec_slave_config_t *sc, unsigned int n_entries,
 
 /*****************************************************************************/
 
+int ecrt_slave_config_reg_pdo_entry(
+        ec_slave_config_t *sc, /**< Slave configuration. */
+        uint16_t index, /**< Index of Pdo entry to register. */
+        uint8_t subindex, /**< Subindex of Pdo entry to register. */
+        ec_domain_t *domain /**< Domain. */
+        )
+{
+    ec_direction_t dir;
+    ec_pdo_mapping_t *map;
+    unsigned int bit_offset, byte_offset;
+    ec_pdo_t *pdo;
+    ec_pdo_entry_t *entry;
+    int ret;
+
+    for (dir = EC_DIR_OUTPUT; dir <= EC_DIR_INPUT; dir++) {
+        map = &sc->mapping[dir];
+        bit_offset = 0;
+        list_for_each_entry(pdo, &map->pdos, list) {
+            list_for_each_entry(entry, &pdo->entries, list) {
+                if (entry->index != index || entry->subindex != subindex) {
+                    bit_offset += entry->bit_length;
+                } else {
+                    goto found;
+                }
+            }
+        }
+    }
+
+    EC_ERR("PDO entry 0x%04X:%u is not mapped in slave config %u:%u.\n",
+           index, subindex, sc->alias, sc->position);
+    return -1;
+
+found:
+    byte_offset = bit_offset / 8;
+    if ((ret = ec_slave_config_prepare_fmmu(sc, domain, dir)) < 0)
+        return -2;
+    return ret + byte_offset;
+}
+
+/*****************************************************************************/
+
 int ecrt_slave_config_sdo8(ec_slave_config_t *slave, uint16_t index,
         uint8_t subindex, uint8_t value)
 {
@@ -537,6 +527,7 @@ int ecrt_slave_config_sdo32(ec_slave_config_t *slave, uint16_t index,
 /** \cond */
 
 EXPORT_SYMBOL(ecrt_slave_config_mapping);
+EXPORT_SYMBOL(ecrt_slave_config_reg_pdo_entry);
 EXPORT_SYMBOL(ecrt_slave_config_sdo8);
 EXPORT_SYMBOL(ecrt_slave_config_sdo16);
 EXPORT_SYMBOL(ecrt_slave_config_sdo32);
-- 
GitLab