Domain datagram working counter calculation bugfix: increment expected wc for a given slave & direction just once for each datagram
authorDominik Staubli <ch1010252@ch10pc423>
Thu, 21 Jan 2010 11:09:31 +0100
changeset 1798 e7733f825982
parent 1610 d46de2278ac6
child 1799 f228415225b7
Domain datagram working counter calculation bugfix: increment expected wc for a given slave & direction just once for each datagram
This bug occurs if you configure more than one SM in the same direction on the same slave
master/domain.c
master/slave_config.c
master/slave_config.h
--- a/master/domain.c	Mon Jan 04 14:17:31 2010 +0100
+++ b/master/domain.c	Thu Jan 21 11:09:31 2010 +0100
@@ -203,6 +203,7 @@
     unsigned int datagram_count;
     unsigned int datagram_used[EC_DIR_COUNT];
     ec_fmmu_config_t *fmmu;
+    ec_fmmu_config_t *fmmu_temp;
     const ec_datagram_t *datagram;
     int ret;
 
@@ -225,15 +226,21 @@
     datagram_count = 0;
     datagram_used[EC_DIR_OUTPUT] = 0;
     datagram_used[EC_DIR_INPUT] = 0;
-
+    list_for_each_entry(fmmu_temp, &domain->fmmu_configs, list) {
+       ec_slave_config_t *sc = (ec_slave_config_t *)fmmu_temp->sc; // we have to remove the constness, sorry
+       sc->used_for_fmmu_datagram[fmmu_temp->dir] = 0;
+    }
     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
-        datagram_used[fmmu->dir]++;
-
+        if (fmmu->sc->used_for_fmmu_datagram[fmmu->dir] == 0) {
+            ec_slave_config_t *sc = (ec_slave_config_t *)fmmu->sc;
+            datagram_used[fmmu->dir]++;
+            sc->used_for_fmmu_datagram[fmmu->dir] = 1;
+        }
         // If the current FMMU's data do not fit in the current datagram,
         // allocate a new one.
         if (datagram_size + fmmu->data_size > EC_MAX_DATA_SIZE) {
@@ -248,6 +255,10 @@
             datagram_count++;
             datagram_used[EC_DIR_OUTPUT] = 0;
             datagram_used[EC_DIR_INPUT] = 0;
+            list_for_each_entry(fmmu_temp, &domain->fmmu_configs, list) {
+                ec_slave_config_t *sc = (ec_slave_config_t *)fmmu_temp->sc;
+               sc->used_for_fmmu_datagram[fmmu_temp->dir] = 0;
+            }
         }
 
         datagram_size += fmmu->data_size;
--- a/master/slave_config.c	Mon Jan 04 14:17:31 2010 +0100
+++ b/master/slave_config.c	Thu Jan 21 11:09:31 2010 +0100
@@ -75,7 +75,8 @@
         ec_sync_config_init(&sc->sync_configs[i]);
 
     sc->used_fmmus = 0;
-
+    sc->used_for_fmmu_datagram[EC_DIR_INPUT] = 0;
+    sc->used_for_fmmu_datagram[EC_DIR_OUTPUT] = 0;
     sc->dc_assign_activate = 0x0000;
     sc->dc_sync[0].cycle_time = 0x00000000;
     sc->dc_sync[1].cycle_time = 0x00000000;
--- a/master/slave_config.h	Mon Jan 04 14:17:31 2010 +0100
+++ b/master/slave_config.h	Thu Jan 21 11:09:31 2010 +0100
@@ -70,7 +70,7 @@
                                                    configurations. */
     ec_fmmu_config_t fmmu_configs[EC_MAX_FMMUS]; /**< FMMU configurations. */
     uint8_t used_fmmus; /**< Number of FMMUs used. */
-
+    unsigned int used_for_fmmu_datagram[EC_DIR_COUNT];
     uint16_t dc_assign_activate; /**< Vendor-specific AssignActivate word. */
     ec_sync_signal_t dc_sync[EC_SYNC_SIGNAL_COUNT]; /**< DC sync signals. */