Increment injection_seq on slave state changes
authorMartin Troxler <ch1010277@ch10pc446>
Tue, 14 Dec 2010 14:00:19 +0100
changeset 2017 4b16e2dce5fb
parent 2016 4624979ec993
child 2018 6c05411fee9b
Increment injection_seq on slave state changes
master/fsm_slave.c
master/fsm_slave.h
master/master.c
--- a/master/fsm_slave.c	Mon Dec 13 17:38:24 2010 +0100
+++ b/master/fsm_slave.c	Tue Dec 14 14:00:19 2010 +0100
@@ -94,19 +94,21 @@
  *
  * If the state machine's datagram is not sent or received yet, the execution
  * of the state machine is delayed to the next cycle.
- */
-void ec_fsm_slave_exec(
+ *
+ * \return true, if the state machine was executed
+ */
+int ec_fsm_slave_exec(
         ec_fsm_slave_t *fsm /**< Slave state machine. */
         )
 {
     if (fsm->datagram->state == EC_DATAGRAM_SENT
         || fsm->datagram->state == EC_DATAGRAM_QUEUED) {
         // datagram was not sent or received yet.
-        return;
+        return 0;
     }
 
     fsm->state(fsm);
-    return;
+    return 1;
 }
 
 /*****************************************************************************/
--- a/master/fsm_slave.h	Mon Dec 13 17:38:24 2010 +0100
+++ b/master/fsm_slave.h	Tue Dec 14 14:00:19 2010 +0100
@@ -67,7 +67,7 @@
 void ec_fsm_slave_init(ec_fsm_slave_t *, ec_slave_t *, ec_datagram_t *);
 void ec_fsm_slave_clear(ec_fsm_slave_t *);
 
-void ec_fsm_slave_exec(ec_fsm_slave_t *);
+int ec_fsm_slave_exec(ec_fsm_slave_t *);
 void ec_fsm_slave_ready(ec_fsm_slave_t *);
 
 /*****************************************************************************/
--- a/master/master.c	Mon Dec 13 17:38:24 2010 +0100
+++ b/master/master.c	Tue Dec 14 14:00:19 2010 +0100
@@ -1256,7 +1256,6 @@
 {
     ec_master_t *master = (ec_master_t *) priv_data;
     ec_slave_t *slave = NULL;
-    int fsm_exec;
     size_t sent_bytes;
 
     // send interval in IDLE phase
@@ -1275,24 +1274,21 @@
         up(&master->io_sem);
 
         if (master->injection_seq_rt == master->injection_seq_fsm) {
-            fsm_exec = 0;
             // execute master & slave state machines
             if (down_interruptible(&master->master_sem))
                 break;
-            fsm_exec = ec_fsm_master_exec(&master->fsm);
+            if (ec_fsm_master_exec(&master->fsm))
+                master->injection_seq_fsm++;
             for (slave = master->slaves;
                     slave < master->slaves + master->slave_count;
                     slave++) {
-                ec_fsm_slave_exec(&slave->fsm);
+                if (ec_fsm_slave_exec(&slave->fsm))
+                    master->injection_seq_fsm++;
             }
             up(&master->master_sem);
-
-            // queue and send
-            down(&master->io_sem);
-            if (fsm_exec) {
-                master->injection_seq_rt++;
-            }
-        }
+        }
+        // queue and send
+        down(&master->io_sem);
         ecrt_master_send(master);
         sent_bytes = master->main_device.tx_skb[
             master->main_device.tx_ring_index]->len;
@@ -1327,7 +1323,6 @@
 {
     ec_master_t *master = (ec_master_t *) priv_data;
     ec_slave_t *slave = NULL;
-    int fsm_exec;
 
     EC_MASTER_DBG(master, 1, "Operation thread running"
             " with fsm interval = %u us, max data size=%zu\n",
@@ -1340,21 +1335,18 @@
             // output statistics
             ec_master_output_stats(master);
 
-            fsm_exec = 0;
             // execute master & slave state machines
             if (down_interruptible(&master->master_sem))
                 break;
-            fsm_exec = ec_fsm_master_exec(&master->fsm);
+            if (ec_fsm_master_exec(&master->fsm))
+                master->injection_seq_fsm++;
             for (slave = master->slaves;
                     slave < master->slaves + master->slave_count;
                     slave++) {
-                ec_fsm_slave_exec(&slave->fsm);
+                if (ec_fsm_slave_exec(&slave->fsm))
+                    master->injection_seq_fsm++;
             }
             up(&master->master_sem);
-
-            // inject datagrams (let the rt thread queue them, see ecrt_master_send)
-            if (fsm_exec)
-                master->injection_seq_fsm++;
         }
 
 #ifdef EC_USE_HRTIMER