master/fsm_change.c
changeset 738 880c6153101f
parent 713 ae41cadd25b6
child 798 5a58606726f3
--- a/master/fsm_change.c	Wed Sep 19 11:52:58 2007 +0000
+++ b/master/fsm_change.c	Wed Sep 19 17:17:45 2007 +0000
@@ -66,6 +66,7 @@
 {
     fsm->state = NULL;
     fsm->datagram = datagram;
+    fsm->spontaneous_change = 0;
 }
 
 /*****************************************************************************/
@@ -223,6 +224,7 @@
     // read AL status from slave
     ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2);
     fsm->retries = EC_FSM_RETRIES;
+    fsm->spontaneous_change = 0;
     fsm->state = ec_fsm_change_state_status;
 }
 
@@ -281,10 +283,11 @@
             // Slave spontaneously changed its state just before the new state
             // was written. Accept current state as old state and wait for
             // state change
+            fsm->spontaneous_change = 1;
             fsm->old_state = slave->current_state;
             EC_WARN("Slave %i changed to %s in the meantime.\n",
                     slave->ring_position, cur_state);
-            goto again;
+            goto check_again;
         }
 
         // state change error
@@ -309,11 +312,11 @@
         ec_state_string(fsm->requested_state, state_str);
         fsm->state = ec_fsm_change_state_error;
         EC_ERR("Timeout while setting state %s on slave %i.\n",
-               state_str, slave->ring_position);
-        return;
-    }
-
- again:
+                state_str, slave->ring_position);
+        return;
+    }
+
+ check_again:
     // no timeout yet. check again
     ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2);
     fsm->retries = EC_FSM_RETRIES;