Refactor fmmu->logical_start_address to fmmu->logical_domain_offset
authorDave Page <dave.page@gleeble.com>
Thu, 26 Mar 2015 17:41:57 -0400
changeset 2610 f0fdcce9874b
parent 2609 777d1a8b3a27
child 2611 f09b0623a2c1
Refactor fmmu->logical_start_address to fmmu->logical_domain_offset
master/domain.c
master/fmmu_config.c
master/fmmu_config.h
master/fsm_foe.c
master/ioctl.c
master/slave_config.c
--- a/master/domain.c	Thu Mar 26 15:16:21 2015 -0400
+++ b/master/domain.c	Thu Mar 26 17:41:57 2015 -0400
@@ -130,8 +130,8 @@
     list_add_tail(&fmmu->list, &domain->fmmu_configs);
 
     EC_MASTER_DBG(domain->master, 1, "Domain %u:"
-            " Added %u bytes, total %zu.\n",
-            domain->index, fmmu->data_size, domain->data_size);
+            " Added %u bytes.\n",
+            domain->index, fmmu->data_size);
 }
 
 /*****************************************************************************/
@@ -237,6 +237,15 @@
     const ec_datagram_pair_t *datagram_pair;
     int ret;
 
+#if 0
+    // Determine domain size from furthest extent of FMMU data
+    domain->data_size = 0;
+    list_for_each_entry(fmmu, &domain->fmmu_configs, list) {
+        domain->data_size = max(domain->data_size,
+            fmmu->logical_domain_offset + fmmu->data_size);
+    }
+#endif
+
     domain->logical_base_address = base_address;
 
     if (domain->data_size && domain->data_origin == EC_ORIG_INTERNAL) {
@@ -265,10 +274,6 @@
     }
 
     list_for_each_entry(fmmu, &domain->fmmu_configs, list) {
-
-        // Correct logical FMMU address
-        fmmu->logical_start_address += base_address;
-
         // Increment Input/Output counter to determine datagram types
         // and calculate expected working counters
         if (shall_count(fmmu, datagram_first_fmmu)) {
@@ -503,19 +508,17 @@
                     continue;
                 }
 
-                if (fmmu->logical_start_address >=
-                        logical_datagram_address + datagram_size) {
+                if (fmmu->logical_domain_offset >= datagram_size) {
                     // fmmu data contained in next datagram pair
                     break;
                 }
 
-                datagram_offset =
-                    fmmu->logical_start_address - logical_datagram_address;
+                datagram_offset = fmmu->logical_domain_offset;
 
 #if DEBUG_REDUNDANCY
                 EC_MASTER_DBG(domain->master, 1,
-                        "input fmmu log=%u size=%u offset=%u\n",
-                        fmmu->logical_start_address, fmmu->data_size,
+                        "input fmmu log_off=%u size=%u offset=%u\n",
+                        fmmu->logical_domain_offset, fmmu->data_size,
                         datagram_offset);
                 if (domain->master->debug_level > 0) {
                     ec_print_data(pair->send_buffer + datagram_offset,
--- a/master/fmmu_config.c	Thu Mar 26 15:16:21 2015 -0400
+++ b/master/fmmu_config.c	Thu Mar 26 17:41:57 2015 -0400
@@ -60,7 +60,7 @@
     fmmu->sync_index = sync_index;
     fmmu->dir = dir;
 
-    fmmu->logical_start_address = domain->data_size;
+    fmmu->logical_domain_offset = domain->data_size;
     fmmu->data_size = ec_pdo_list_total_size(
             &sc->sync_configs[sync_index].pdos);
 
@@ -79,13 +79,14 @@
         uint8_t *data /**> Configuration page memory. */
         )
 {
-    EC_CONFIG_DBG(fmmu->sc, 1, "FMMU: LogAddr 0x%08X, Size %3u,"
+    EC_CONFIG_DBG(fmmu->sc, 1, "FMMU: LogOff 0x%08X, Size %3u,"
             " PhysAddr 0x%04X, SM%u, Dir %s\n",
-            fmmu->logical_start_address, fmmu->data_size,
+            fmmu->logical_domain_offset, fmmu->data_size,
             sync->physical_start_address, fmmu->sync_index,
             fmmu->dir == EC_DIR_INPUT ? "in" : "out");
 
-    EC_WRITE_U32(data,      fmmu->logical_start_address);
+    EC_WRITE_U32(data,      fmmu->domain->logical_base_address +
+        fmmu->logical_domain_offset);
     EC_WRITE_U16(data + 4,  fmmu->data_size); // size of fmmu
     EC_WRITE_U8 (data + 6,  0x00); // logical start bit
     EC_WRITE_U8 (data + 7,  0x07); // logical end bit
--- a/master/fmmu_config.h	Thu Mar 26 15:16:21 2015 -0400
+++ b/master/fmmu_config.h	Thu Mar 26 17:41:57 2015 -0400
@@ -49,7 +49,8 @@
     const ec_domain_t *domain; /**< Domain. */
     uint8_t sync_index; /**< Index of sync manager to use. */
     ec_direction_t dir; /**< FMMU direction. */
-    uint32_t logical_start_address; /**< Logical start address. */
+    uint32_t logical_domain_offset; /**< Logical offset address relative to
+                domain->logical_base_address. */
     unsigned int data_size; /**< Covered PDO size. */
 } ec_fmmu_config_t;
 
--- a/master/fsm_foe.c	Thu Mar 26 15:16:21 2015 -0400
+++ b/master/fsm_foe.c	Thu Mar 26 17:41:57 2015 -0400
@@ -54,7 +54,7 @@
 // uint8_t  reserved
 // uint32_t PacketNo, Password, ErrorCode
 
-#define DEBUG_FOE
+//#define DEBUG_FOE
 
 /*****************************************************************************/
 
--- a/master/ioctl.c	Thu Mar 26 15:16:21 2015 -0400
+++ b/master/ioctl.c	Thu Mar 26 17:41:57 2015 -0400
@@ -544,7 +544,7 @@
     data.slave_config_position = fmmu->sc->position;
     data.sync_index = fmmu->sync_index;
     data.dir = fmmu->dir;
-    data.logical_address = fmmu->logical_start_address;
+    data.logical_address = fmmu->domain->logical_base_address + fmmu->logical_domain_offset;
     data.data_size = fmmu->data_size;
 
     up(&master->master_sem);
--- a/master/slave_config.c	Thu Mar 26 15:16:21 2015 -0400
+++ b/master/slave_config.c	Thu Mar 26 17:41:57 2015 -0400
@@ -182,7 +182,7 @@
     for (i = 0; i < sc->used_fmmus; i++) {
         fmmu = &sc->fmmu_configs[i];
         if (fmmu->domain == domain && fmmu->sync_index == sync_index)
-            return fmmu->logical_start_address;
+            return fmmu->logical_domain_offset;
     }
 
     if (sc->used_fmmus == EC_MAX_FMMUS) {
@@ -216,7 +216,7 @@
             prev_fmmu->tx_size = max(fmmu->data_size, prev_fmmu->data_size);
             domain->tx_size += prev_fmmu->tx_size - old_prev_tx_size;
             tx_size = 0;
-            fmmu_logical_start_address = prev_fmmu->logical_start_address;
+            fmmu_logical_start_address = prev_fmmu->logical_domain_offset;
         }
     }
 
@@ -227,7 +227,7 @@
     sc->used_fmmus++;
     up(&sc->master->master_sem);
 
-    return fmmu->logical_start_address;
+    return fmmu->logical_domain_offset;
 }
 
 /*****************************************************************************/