From f4199b7f60092547a67429a5f7ce74c90c1f68e6 Mon Sep 17 00:00:00 2001 From: Florian Pose Date: Mon, 17 Mar 2008 14:16:16 +0000 Subject: [PATCH] Fixed bug in copying sync managers. Now making a deep copy. --- master/slave.c | 5 ++--- master/sync.c | 22 ++++++++++++++++++++++ master/sync.h | 1 + 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/master/slave.c b/master/slave.c index ec2a4c42..207cef20 100644 --- a/master/slave.c +++ b/master/slave.c @@ -502,9 +502,8 @@ int ec_slave_fetch_sii_syncs( return -1; } - // copy existing sync managers - memcpy(syncs, slave->sii.syncs, - slave->sii.sync_count * sizeof(ec_sync_t)); + for (i = 0; i < slave->sii.sync_count; i++) + ec_sync_init_copy(syncs + i, slave->sii.syncs + i); // initialize new sync managers for (i = 0; i < count; i++, data += 8) { diff --git a/master/sync.c b/master/sync.c index 7a2023b7..c1af279c 100644 --- a/master/sync.c +++ b/master/sync.c @@ -62,6 +62,28 @@ void ec_sync_init( /*****************************************************************************/ +/** Copy constructor. + */ +void ec_sync_init_copy( + ec_sync_t *sync, /**< EtherCAT sync manager. */ + const ec_sync_t *other /**< Sync manager to copy from. */ + ) +{ + sync->slave = other->slave; + sync->index = other->index; + sync->physical_start_address = other->physical_start_address; + sync->length = other->length; + sync->control_register = other->control_register; + sync->enable = other->enable; + + ec_pdo_mapping_init(&sync->mapping); + ec_pdo_mapping_copy(&sync->mapping, &other->mapping); + + sync->mapping_source = other->mapping_source; +} + +/*****************************************************************************/ + /** Destructor. */ void ec_sync_clear( diff --git a/master/sync.h b/master/sync.h index b0049563..7995d4e9 100644 --- a/master/sync.h +++ b/master/sync.h @@ -76,6 +76,7 @@ typedef struct { /*****************************************************************************/ void ec_sync_init(ec_sync_t *, ec_slave_t *, unsigned int); +void ec_sync_init_copy(ec_sync_t *, const ec_sync_t *); void ec_sync_clear(ec_sync_t *); void ec_sync_config(const ec_sync_t *, uint16_t, uint8_t *);