Fixed spacing and added some thoughts about the overlapping PDOs
authorFlorian Pose <fp@igh-essen.com>
Thu, 11 Aug 2011 20:44:18 +0200
changeset 2103 8c63d804ead9
parent 2102 c063334af614
child 2105 86a4a7587c43
Fixed spacing and added some thoughts about the overlapping PDOs
implementation.
master/fmmu_config.h
master/master.c
master/slave_config.c
--- a/master/fmmu_config.h	Thu Aug 11 20:20:12 2011 +0200
+++ b/master/fmmu_config.h	Thu Aug 11 20:44:18 2011 +0200
@@ -50,7 +50,7 @@
     uint8_t sync_index; /**< Index of sync manager to use. */
     ec_direction_t dir; /**< FMMU direction. */
     uint32_t logical_start_address; /**< Logical start address. */
-    size_t tx_size; /**< Transmitted (bus) size. */
+    size_t tx_size; /**< Transmitted (bus) size. FIXME */
     uint32_t domain_address;    /** Domain start address */
     unsigned int data_size; /**< Covered PDO size. */
 } ec_fmmu_config_t;
--- a/master/master.c	Thu Aug 11 20:20:12 2011 +0200
+++ b/master/master.c	Thu Aug 11 20:44:18 2011 +0200
@@ -938,24 +938,32 @@
 
             // EtherCAT datagram data
             frame_datagram_data = cur_data;
+
+            // distinguish between domain and non-domain datagrams...
+            // this is not nice... FIXME
             if (datagram->domain) {
                 unsigned int datagram_address =
                     EC_READ_U32(datagram->address);
                 int i = 0;
                 uint8_t *domain_data = datagram->data;
+
+                // FIXME all FMMU configs are taken into acount,
+                // maybe the belong to another datagram?
+                // test with large process data!
+
                 list_for_each_entry(domain_fmmu,
                         &datagram->domain->fmmu_configs, list) {
-                    if (domain_fmmu->dir == EC_DIR_OUTPUT ) {
+                    if (domain_fmmu->dir == EC_DIR_OUTPUT) {
                         unsigned int frame_offset =
                             domain_fmmu->logical_start_address
                             - datagram_address;
-                        memcpy(frame_datagram_data+frame_offset, domain_data,
-                                domain_fmmu->data_size);
+                        memcpy(frame_datagram_data + frame_offset,
+                                domain_data, domain_fmmu->data_size);
                         if (unlikely(master->debug_level > 1)) {
-                            EC_DBG("sending dg %p i=0x%02X fmmu %u fp=%u"
+                            EC_MASTER_DBG(master, 0, "Sending datagram %p"
+                                    " i=0x%02X FMMU %u fp=%u"
                                     " dp=%zu size=%u\n",
-                                   datagram, datagram->index, i,
-                                   frame_offset,
+                                   datagram, datagram->index, i, frame_offset,
                                    domain_data - datagram->data,
                                    domain_fmmu->data_size);
                             ec_print_data(domain_data,
@@ -963,7 +971,7 @@
                         }
                     }
                     domain_data += domain_fmmu->data_size;
-                    ++i;
+                    i++;
                 }
             } else {
                 memcpy(frame_datagram_data, datagram->data,
@@ -1030,14 +1038,15 @@
  * 
  * \return 0 in case of success, else < 0
  */
-void ec_master_receive_datagrams(ec_master_t *master, /**< EtherCAT master */
-                                 const uint8_t *frame_data, /**< frame data */
-                                 size_t size /**< size of the received data */
-                                 )
+void ec_master_receive_datagrams(
+        ec_master_t *master, /**< EtherCAT master */
+        const uint8_t *frame_data, /**< Frame data */
+        size_t size /**< Size of the received data */
+        )
 {
     size_t frame_size, data_size;
     uint8_t datagram_type, datagram_index;
-    unsigned int cmd_follows, matched;
+    unsigned int datagram_follows, matched;
     const uint8_t *cur_data, *frame_datagram_data;
     ec_datagram_t *datagram;
     ec_fmmu_config_t* domain_fmmu;
@@ -1072,13 +1081,15 @@
         return;
     }
 
-    cmd_follows = 1;
-    while (cmd_follows) {
+    datagram_follows = 1;
+
+    while (datagram_follows) {
+
         // process datagram header
-        datagram_type  = EC_READ_U8 (cur_data);
-        datagram_index = EC_READ_U8 (cur_data + 1);
-        data_size      = EC_READ_U16(cur_data + 6) & 0x07FF;
-        cmd_follows    = EC_READ_U16(cur_data + 6) & 0x8000;
+        datagram_type = EC_READ_U8(cur_data);
+        datagram_index = EC_READ_U8(cur_data + 1);
+        data_size = EC_READ_U16(cur_data + 6) & 0x07FF;
+        datagram_follows = EC_READ_U16(cur_data + 6) & 0x8000;
         cur_data += EC_DATAGRAM_HEADER_SIZE;
 
         if (unlikely(cur_data - frame_data
@@ -1123,13 +1134,20 @@
             cur_data += data_size + EC_DATAGRAM_FOOTER_SIZE;
             continue;
         }
+
         frame_datagram_data = cur_data;
 
+        // distinguish between domain and non-domain datagrams
+        // this is not nice FIXME
         if (datagram->domain) {
             size_t datagram_address = EC_READ_U32(datagram->address);
             int i = 0;
             uint8_t *domain_data = datagram->data;
 
+            // FIXME see ecrt_master_send_datagrams()
+            // it is not correct to walk though *all* FMMU configs,
+            // because they may not all belong to the same frame!
+
             list_for_each_entry(domain_fmmu, &datagram->domain->fmmu_configs,
                     list) {
                 if (domain_fmmu->dir == EC_DIR_INPUT) {
@@ -1138,7 +1156,8 @@
                     memcpy(domain_data, frame_datagram_data + frame_offset,
                             domain_fmmu->data_size);
                     if (unlikely(master->debug_level > 1)) {
-                        EC_DBG("receiving dg %p i=0x%02X fmmu %u fp=%u"
+                        EC_MASTER_DBG(master, 0, "Receiving datagram %p"
+                                " i=0x%02X fmmu %u fp=%u"
                                 " dp=%zu size=%u\n",
                                datagram, datagram->index, i,
                                frame_offset, domain_data - datagram->data,
@@ -1147,12 +1166,13 @@
                     }
                 }
                 domain_data += domain_fmmu->data_size;
-                ++i;
+                i++;
             }
         } else {
             // copy received data into the datagram memory
             memcpy(datagram->data, frame_datagram_data, data_size);
         }
+
         cur_data += data_size;
 
         // set the datagram's working counter
--- a/master/slave_config.c	Thu Aug 11 20:20:12 2011 +0200
+++ b/master/slave_config.c	Thu Aug 11 20:44:18 2011 +0200
@@ -161,8 +161,7 @@
         )
 {
     unsigned int i;
-    ec_fmmu_config_t *fmmu;
-    ec_fmmu_config_t *prev_fmmu;
+    ec_fmmu_config_t *fmmu, *prev_fmmu;
     uint32_t fmmu_logical_start_address;
     size_t tx_size, old_prev_tx_size;
 
@@ -184,22 +183,26 @@
     ec_fmmu_config_init(fmmu, sc, sync_index, dir);
     fmmu_logical_start_address = domain->tx_size;
     tx_size = fmmu->data_size;
+
+    // FIXME is it enough to take only the *previous* FMMU into account?
+
     if (sc->allow_overlapping_pdos && sc->used_fmmus > 0) {
-        prev_fmmu = &sc->fmmu_configs[sc->used_fmmus-1];
+        prev_fmmu = &sc->fmmu_configs[sc->used_fmmus - 1];
         if (fmmu->dir != prev_fmmu->dir && prev_fmmu->tx_size != 0) {
             // prev fmmu has opposite direction
             // and is not already paired with prev-prev fmmu
             old_prev_tx_size = prev_fmmu->tx_size;
-            prev_fmmu->tx_size = max(fmmu->data_size,prev_fmmu->data_size);
+            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;
         }
     }
-    ec_fmmu_config_domain(fmmu,domain,fmmu_logical_start_address,tx_size);
+
+    ec_fmmu_config_domain(fmmu, domain, fmmu_logical_start_address, tx_size);
     ec_mutex_unlock(&sc->master->master_mutex);
 
-    ++sc->used_fmmus;
+    sc->used_fmmus++;
     return fmmu->domain_address;
 }