Added bitwise Pdo registration.
--- a/include/ecrt.h Wed May 28 07:19:33 2008 +0000
+++ b/include/ecrt.h Wed May 28 07:26:28 2008 +0000
@@ -58,11 +58,13 @@
* added the domain methods ecrt_domain_size() and
* ecrt_domain_external_memory().
* - Replaced the process data pointers in the Pdo entry registration
- * functions with a process data offset, that is now returned by
- * 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. If the domain's process data is allocated internally,
- * the start address can be retrieved with ecrt_domain_data().
+ * functions with a process data offset, that is now returned either byte-
+ * or bitwise by ecrt_slave_config_reg_pdo_entry() or
+ * ecrt_slave_config_reg_pdo_entry_bitwise(), respectively. This was
+ * necessary for the external domain memory. An additional advantage is,
+ * that the returned offset is immediately valid. If the domain's
+ * process data is allocated internally, the start address can be retrieved
+ * with ecrt_domain_data().
* - Replaced ecrt_slave_pdo_mapping/add/clear() with
* ecrt_slave_config_pdo_assign_add() to add a Pdo to a sync manager's Pdo
* assignment and ecrt_slave_config_pdo_mapping_add() to add a Pdo entry to a
@@ -238,7 +240,8 @@
/** List record type for Pdo entry mass-registration.
*
* This type is used for the array parameter of the
- * ecrt_domain_reg_pdo_entry_list() convenience function.
+ * ecrt_domain_reg_pdo_entry_list() and
+ * ecrt_domain_reg_pdo_entry_list_bitwise() convenience functions.
*/
typedef struct {
uint16_t alias; /**< Slave alias address. */
@@ -248,7 +251,10 @@
uint16_t index; /**< Pdo entry index. */
uint8_t subindex; /**< Pdo entry subindex. */
unsigned int *offset; /**< Pointer to a variable to store the Pdo's
- offset in the process data. */
+ offset in the process data. This can either be byte-
+ or bitwise, depending on whether
+ ecrt_domain_reg_pdo_entry_list() or
+ ecrt_domain_reg_pdo_entry_list_bitwise() was called. */
} ec_pdo_entry_reg_t;
/*****************************************************************************/
@@ -518,6 +524,7 @@
* \retval >=0 Success: Offset of the Pdo entry's process data.
* \retval -1 Error: Pdo entry not found.
* \retval -2 Error: Failed to register Pdo entry.
+ * \retval -3 Error: Pdo entry is not byte-aligned.
*/
int ecrt_slave_config_reg_pdo_entry(
ec_slave_config_t *sc, /**< Slave configuration. */
@@ -526,6 +533,23 @@
ec_domain_t *domain /**< Domain. */
);
+/** Registers a Pdo entry for process data exchange in a domain.
+ *
+ * Bitwise registration function.
+ *
+ * \see ecrt_slave_config_reg_pdo_entry().
+ *
+ * \retval >=0 Success: Bit offset of the Pdo entry's process data.
+ * \retval -1 Error: Pdo entry not found.
+ * \retval -2 Error: Failed to register Pdo entry.
+ */
+int ecrt_slave_config_reg_pdo_entry_bitwise(
+ 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 an Sdo configuration.
*
* An Sdo configuration is stored in the slave configuration object and is
@@ -623,6 +647,22 @@
registrations. */
);
+/** Registers a bunch of Pdo entries for a domain.
+ *
+ * Bitwise registration.
+ *
+ * \see ecrt_domain_reg_pdo_entry_list()
+ *
+ * \attention The registration array has to be terminated with an empty
+ * structure, or one with the \a index field set to zero!
+ * \return 0 on success, else non-zero.
+ */
+int ecrt_domain_reg_pdo_entry_list_bitwise(
+ ec_domain_t *domain, /**< Domain. */
+ const ec_pdo_entry_reg_t *pdo_entry_regs /**< Array of Pdo
+ registrations. */
+ );
+
/** Returns the current size of the domain's process data.
*
* \return Size of the process data image.
--- a/master/domain.c Wed May 28 07:19:33 2008 +0000
+++ b/master/domain.c Wed May 28 07:26:28 2008 +0000
@@ -401,6 +401,30 @@
/*****************************************************************************/
+int ecrt_domain_reg_pdo_entry_list_bitwise(ec_domain_t *domain,
+ const ec_pdo_entry_reg_t *regs)
+{
+ const ec_pdo_entry_reg_t *reg;
+ ec_slave_config_t *sc;
+ int ret;
+
+ for (reg = regs; reg->index; reg++) {
+ if (!(sc = ecrt_master_slave_config(domain->master, reg->alias,
+ reg->position, reg->vendor_id, reg->product_code)))
+ return -1;
+
+ if ((ret = ecrt_slave_config_reg_pdo_entry_bitwise(sc, reg->index,
+ reg->subindex, domain)) < 0)
+ return -1;
+
+ *reg->offset = ret;
+ }
+
+ return 0;
+}
+
+/*****************************************************************************/
+
size_t ecrt_domain_size(ec_domain_t *domain)
{
return domain->data_size;
--- a/master/slave_config.c Wed May 28 07:19:33 2008 +0000
+++ b/master/slave_config.c Wed May 28 07:26:28 2008 +0000
@@ -193,10 +193,11 @@
* is written to the slave during the configuration. The FMMU configuration
* is done in a way, that the complete data range of the corresponding sync
* manager is covered. Seperate FMMUs are configured for each domain. If the
- * FMMU configuration is already prepared, the function returns with success.
- *
- * \retval >=0 Logical offset address.
- * \retval -1 FMMU limit reached.
+ * FMMU configuration is already prepared, the function does nothing and
+ * returns with success.
+ *
+ * \retval >=0 Success, logical offset byte address.
+ * \retval -1 Error, FMMU limit reached.
*/
int ec_slave_config_prepare_fmmu(
ec_slave_config_t *sc, /**< Slave configuration. */
@@ -609,9 +610,33 @@
ec_domain_t *domain /**< Domain. */
)
{
+ int ret = ecrt_slave_config_reg_pdo_entry_bitwise(
+ sc, index, subindex, domain);
+
+ if (ret < 0)
+ return ret;
+
+ if (ret % 8) {
+ EC_ERR("Bytewise Pdo entry registration requested, but the result is "
+ "not byte-aligned.\n");
+ return -3;
+ }
+
+ return ret / 8;
+}
+
+/*****************************************************************************/
+
+int ecrt_slave_config_reg_pdo_entry_bitwise(
+ 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_list_t *pdos;
- unsigned int bit_offset, byte_offset;
+ unsigned int bit_offset;
ec_pdo_t *pdo;
ec_pdo_entry_t *entry;
int ret;
@@ -635,10 +660,9 @@
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;
+ return ret * 8 + bit_offset;
}
/*****************************************************************************/