Ignore queued datagrams while waiting in ec_master_sync_io().
authorFlorian Pose <fp@igh-essen.com>
Mon, 12 Feb 2007 10:39:52 +0000
changeset 548 f5d41a52a8aa
parent 547 dda827b8e578
child 549 67be4381c820
Ignore queued datagrams while waiting in ec_master_sync_io().
master/master.c
--- a/master/master.c	Mon Feb 12 09:04:49 2007 +0000
+++ b/master/master.c	Mon Feb 12 10:39:52 2007 +0000
@@ -1452,22 +1452,25 @@
 void ec_master_sync_io(ec_master_t *master /**< EtherCAT master */)
 {
     ec_datagram_t *datagram;
-    unsigned int datagrams_waiting;
-
-    // send datagrams
+    unsigned int datagrams_sent;
+
+    // send all datagrams
     ecrt_master_send(master);
 
     while (1) { // active waiting
         ecrt_master_receive(master); // receive and dequeue datagrams
 
         // count number of datagrams still waiting for response
-        datagrams_waiting = 0;
+        datagrams_sent = 0;
         list_for_each_entry(datagram, &master->datagram_queue, queue) {
-            datagrams_waiting++;
-        }
-
-        // if there are no more datagrams waiting, abort loop.
-        if (!datagrams_waiting) break;
+            // there may be another process that queued commands
+            // in the meantime.
+            if (datagram->state == EC_DATAGRAM_QUEUED) continue;
+            datagrams_sent++;
+        }
+
+        // abort loop if there are no more datagrams marked as sent.
+        if (!datagrams_sent) break;
     }
 }