Improved handling for spontaneous AL state changes.
authorFlorian Pose <fp@igh-essen.com>
Wed, 19 Sep 2007 17:17:45 +0000
changeset 738 880c6153101f
parent 737 5a770085161c
child 739 4a02162a6301
Improved handling for spontaneous AL state changes.
NEWS
master/fsm_change.c
master/fsm_change.h
master/fsm_slave.c
--- a/NEWS	Wed Sep 19 11:52:58 2007 +0000
+++ b/NEWS	Wed Sep 19 17:17:45 2007 +0000
@@ -6,6 +6,7 @@
 
 Changes in version 1.3.2:
 
+* Improved handling for spontaneous AL state changes.
 * Master takes mailbox sync manager configurations from EEPROM words
   0x0018-0x001b, if no sync manager configurations are provided.
 * Calculate checksum when writing EEPROM or alias address.
--- 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;
--- a/master/fsm_change.h	Wed Sep 19 11:52:58 2007 +0000
+++ b/master/fsm_change.h	Wed Sep 19 17:17:45 2007 +0000
@@ -78,6 +78,7 @@
     ec_slave_state_t old_state; /**< prior slave state */
     unsigned long jiffies_start; /**< change timer */
     uint8_t take_time; /**< take sending timestamp */
+    uint8_t spontaneous_change; /**< spontaneous state change detected */
 };
 
 /*****************************************************************************/
--- a/master/fsm_slave.c	Wed Sep 19 11:52:58 2007 +0000
+++ b/master/fsm_slave.c	Wed Sep 19 17:17:45 2007 +0000
@@ -595,7 +595,8 @@
     if (ec_fsm_change_exec(&fsm->fsm_change)) return;
 
     if (!ec_fsm_change_success(&fsm->fsm_change)) {
-        slave->error_flag = 1;
+        if (!fsm->fsm_change.spontaneous_change)
+            slave->error_flag = 1;
         fsm->state = ec_fsm_slave_state_error;
         return;
     }
@@ -799,7 +800,8 @@
     if (ec_fsm_change_exec(&fsm->fsm_change)) return;
 
     if (!ec_fsm_change_success(&fsm->fsm_change)) {
-        slave->error_flag = 1;
+        if (!fsm->fsm_change.spontaneous_change)
+            slave->error_flag = 1;
         fsm->state = ec_fsm_slave_state_error;
         return;
     }
@@ -1077,7 +1079,8 @@
     if (ec_fsm_change_exec(&fsm->fsm_change)) return;
 
     if (!ec_fsm_change_success(&fsm->fsm_change)) {
-        fsm->slave->error_flag = 1;
+        if (!fsm->fsm_change.spontaneous_change)
+            fsm->slave->error_flag = 1;
         fsm->state = ec_fsm_slave_state_error;
         return;
     }
@@ -1117,7 +1120,8 @@
     if (ec_fsm_change_exec(&fsm->fsm_change)) return;
 
     if (!ec_fsm_change_success(&fsm->fsm_change)) {
-        slave->error_flag = 1;
+        if (!fsm->fsm_change.spontaneous_change)
+            slave->error_flag = 1;
         fsm->state = ec_fsm_slave_state_error;
         return;
     }