master/fsm_change.c
branchstable-1.3
changeset 1746 72e7507b3f1b
parent 1745 07fd94c5119d
--- a/master/fsm_change.c	Thu Sep 13 11:08:46 2007 +0000
+++ b/master/fsm_change.c	Wed Oct 03 08:58:01 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;