Ack timeout in FSM.
authorFlorian Pose <fp@igh-essen.com>
Tue, 18 Jul 2006 16:42:52 +0000
changeset 301 dfe8192a7e19
parent 300 9cb024c1d080
child 302 ad630f38cca1
Ack timeout in FSM.
master/fsm.c
--- a/master/fsm.c	Tue Jul 18 16:40:32 2006 +0000
+++ b/master/fsm.c	Tue Jul 18 16:42:52 2006 +0000
@@ -1784,6 +1784,8 @@
         return;
     }
 
+    fsm->change_start = get_cycles();
+
     // read new AL status
     ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2);
     ec_master_queue_datagram(fsm->master, datagram);
@@ -1801,6 +1803,7 @@
 {
     ec_datagram_t *datagram = &fsm->datagram;
     ec_slave_t *slave = fsm->slave;
+    ec_slave_state_t ack_state;
 
     if (datagram->state != EC_CMD_RECEIVED || datagram->working_counter != 1) {
         fsm->change_state = ec_fsm_change_error;
@@ -1808,18 +1811,27 @@
         return;
     }
 
-    slave->current_state = EC_READ_U8(datagram->data);
-
-    if (slave->current_state == fsm->change_new) {
+    ack_state = EC_READ_U8(datagram->data);
+
+    if (ack_state == slave->current_state) {
         fsm->change_state = ec_fsm_change_error;
         EC_INFO("Acknowleged state 0x%02X on slave %i.\n",
                 slave->current_state, slave->ring_position);
         return;
     }
 
-    fsm->change_state = ec_fsm_change_error;
-    EC_WARN("Failed to acknowledge state 0x%02X on slave %i"
-            " - Timeout!\n", fsm->change_new, slave->ring_position);
+    if (get_cycles() - fsm->change_start >= (cycles_t) 100 * cpu_khz) {
+        // timeout while checking
+        slave->current_state = EC_SLAVE_STATE_UNKNOWN;
+        fsm->change_state = ec_fsm_change_error;
+        EC_ERR("Timeout while acknowleging state 0x%02X on slave %i.\n",
+               fsm->change_new, slave->ring_position);
+        return;
+    }
+
+    // reread new AL status
+    ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2);
+    ec_master_queue_datagram(fsm->master, datagram);
 }
 
 /*****************************************************************************/