From d6b0e622fb40590b033420975f18f1a5a6705a4e Mon Sep 17 00:00:00 2001 From: Florian Pose <fp@igh-essen.com> Date: Tue, 13 May 2008 16:07:06 +0000 Subject: [PATCH] Improved working counter output; fixed problem with slaves that have a single sync manager used for outputs. --- master/domain.c | 19 ++++++++++++++----- master/slave.c | 27 +++++++++++++++++---------- master/sync.c | 23 ++++++++++++++++------- 3 files changed, 47 insertions(+), 22 deletions(-) diff --git a/master/domain.c b/master/domain.c index 361e6239..60a93503 100644 --- a/master/domain.c +++ b/master/domain.c @@ -196,10 +196,18 @@ void ec_domain_add_fmmu_config( ec_fmmu_config_t *fmmu /**< FMMU configuration. */ ) { + unsigned int wc_increment; fmmu->domain = domain; domain->data_size += fmmu->data_size; - domain->expected_working_counter += working_counter_increment[fmmu->dir]; + wc_increment = working_counter_increment[fmmu->dir]; + domain->expected_working_counter += wc_increment; + + if (domain->master->debug_level) + EC_DBG("Domain %u: Added %u bytes (now %u) with dir %u -> WC %u" + " (now %u).\n", domain->index, fmmu->data_size, + domain->data_size, fmmu->dir, wc_increment, + domain->expected_working_counter); } /*****************************************************************************/ @@ -439,13 +447,14 @@ void ecrt_domain_process(ec_domain_t *domain) jiffies - domain->notify_jiffies > HZ) { domain->notify_jiffies = jiffies; if (domain->working_counter_changes == 1) { - EC_INFO("Domain %u working counter change: %u\n", domain->index, - domain->working_counter); + EC_INFO("Domain %u: Working counter changed to %u/%u.\n", + domain->index, domain->working_counter, + domain->expected_working_counter); } else { - EC_INFO("Domain %u: %u working counter changes. Currently %u\n", + EC_INFO("Domain %u: %u working counter changes. Currently %u/%u.\n", domain->index, domain->working_counter_changes, - domain->working_counter); + domain->working_counter, domain->expected_working_counter); } domain->working_counter_changes = 0; } diff --git a/master/slave.c b/master/slave.c index 26a0826f..b542f595 100644 --- a/master/slave.c +++ b/master/slave.c @@ -1164,14 +1164,14 @@ ssize_t ec_store_slave_attribute(struct kobject *kobj, /**< slave's kobject */ /*****************************************************************************/ -/** - * Get the sync manager for either Rx- or Tx-Pdos. +/** Get the sync manager for either Rx- or Tx-Pdos. + * + * \todo This seems not to be correct in every case... * \return pointer to sync manager, or NULL. */ - ec_sync_t *ec_slave_get_pdo_sync( - ec_slave_t *slave, /**< EtherCAT slave */ - ec_direction_t dir /**< input or output */ + ec_slave_t *slave, /**< EtherCAT slave. */ + ec_direction_t dir /**< Input or output. */ ) { unsigned int sync_index; @@ -1181,11 +1181,18 @@ ec_sync_t *ec_slave_get_pdo_sync( return NULL; } - sync_index = (unsigned int) dir; - if (slave->sii.mailbox_protocols) sync_index += 2; - - if (sync_index >= slave->sii.sync_count) - return NULL; + if (slave->sii.sync_count != 1) { + sync_index = (unsigned int) dir; + if (slave->sii.mailbox_protocols) sync_index += 2; + + if (sync_index >= slave->sii.sync_count) + return NULL; + } else { // sync_count == 1 + // A single sync manager may be used for inputs OR outputs! + if (ec_sync_direction(&slave->sii.syncs[0]) != dir) + return NULL; + sync_index = 0; + } return &slave->sii.syncs[sync_index]; } diff --git a/master/sync.c b/master/sync.c index ad5d1d6c..de6cd37e 100644 --- a/master/sync.c +++ b/master/sync.c @@ -144,13 +144,22 @@ ec_direction_t ec_sync_direction( { int index = sync->index; - if (sync->slave && sync->slave->sii.mailbox_protocols) { - index -= 2; - } - - if (index < 0 || index > 1) { - EC_WARN("ec_sync_get_direction(): invalid sync manager index.\n"); - return EC_DIR_OUTPUT; + if (sync->slave->sii.sync_count != 1) { + if (sync->slave && sync->slave->sii.mailbox_protocols) { + index -= 2; + } + + if (index < 0 || index > 1) { + EC_WARN("ec_sync_get_direction(): invalid sync manager index.\n"); + return EC_DIR_OUTPUT; + } + } else { // sync_count == 1 + if (!list_empty(&sync->pdos.list)) { + const ec_pdo_t *pdo = + list_entry(sync->pdos.list.next, ec_pdo_t, list); + return pdo->dir; + } + } return (ec_direction_t) index; -- GitLab