Better handling of unexpected working counters; introduced
authorFlorian Pose <fp@igh-essen.com>
Wed, 12 Sep 2007 10:07:55 +0000
changeset 713 ae41cadd25b6
parent 712 14f899ac51f0
child 714 898f87414af1
Better handling of unexpected working counters; introduced
ec_datagram_print_wc_error().
master/datagram.c
master/datagram.h
master/fsm_change.c
master/fsm_coe.c
master/fsm_master.c
master/fsm_sii.c
master/fsm_slave.c
--- a/master/datagram.c	Wed Sep 12 10:00:39 2007 +0000
+++ b/master/datagram.c	Wed Sep 12 10:07:55 2007 +0000
@@ -299,3 +299,23 @@
 }
 
 /*****************************************************************************/
+
+/**
+ * Evaluates the working counter of a single-cast datagram.
+ * Outputs an error message.
+ */
+
+void ec_datagram_print_wc_error(
+        const ec_datagram_t *datagram
+        )
+{
+    if (datagram->working_counter == 0)
+        printk("No response.");
+    else if (datagram->working_counter > 1)
+        printk("%u slaves responded!", datagram->working_counter);
+    else
+        printk("Success.");
+    printk("\n");
+}
+
+/*****************************************************************************/
--- a/master/datagram.h	Wed Sep 12 10:00:39 2007 +0000
+++ b/master/datagram.h	Wed Sep 12 10:07:55 2007 +0000
@@ -121,6 +121,8 @@
 int ec_datagram_bwr(ec_datagram_t *, uint16_t, size_t);
 int ec_datagram_lrw(ec_datagram_t *, uint32_t, size_t);
 
+void ec_datagram_print_wc_error(const ec_datagram_t *);
+
 /*****************************************************************************/
 
 #endif
--- a/master/fsm_change.c	Wed Sep 12 10:00:39 2007 +0000
+++ b/master/fsm_change.c	Wed Sep 12 10:07:55 2007 +0000
@@ -190,13 +190,14 @@
         fsm->jiffies_start = datagram->jiffies_sent;
     }
 
-    if (datagram->working_counter != 1) {
+    if (datagram->working_counter == 0) {
         if (datagram->jiffies_received - fsm->jiffies_start >= 3 * HZ) {
             char state_str[EC_STATE_STRING_SIZE];
             ec_state_string(fsm->requested_state, state_str);
             fsm->state = ec_fsm_change_state_error;
-            EC_ERR("Failed to set state %s on slave %i: Slave did not"
-                   " respond.\n", state_str, fsm->slave->ring_position);
+            EC_ERR("Failed to set state %s on slave %i: ",
+                    state_str, fsm->slave->ring_position);
+            ec_datagram_print_wc_error(datagram);
             return;
         }
 
@@ -207,6 +208,16 @@
         return;
     }
 
+    if (unlikely(datagram->working_counter > 1)) {
+        char state_str[EC_STATE_STRING_SIZE];
+        ec_state_string(fsm->requested_state, state_str);
+        fsm->state = ec_fsm_change_state_error;
+        EC_ERR("Failed to set state %s on slave %i: ",
+                state_str, fsm->slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
+        return;
+    }
+
     fsm->take_time = 1;
 
     // read AL status from slave
@@ -242,8 +253,9 @@
         char req_state[EC_STATE_STRING_SIZE];
         ec_state_string(fsm->requested_state, req_state);
         fsm->state = ec_fsm_change_state_error;
-        EC_ERR("Failed to check state %s on slave %i.\n",
+        EC_ERR("Failed to check state %s on slave %i: ",
                req_state, slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -372,7 +384,8 @@
     }
 
     if (datagram->working_counter != 1) {
-        EC_WARN("Reception of AL status code datagram failed.\n");
+        EC_WARN("Reception of AL status code datagram failed: ");
+        ec_datagram_print_wc_error(datagram);
     }
     else {
         if ((code = EC_READ_U16(datagram->data))) {
@@ -433,8 +446,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_change_state_error;
-        EC_ERR("Reception of state ack datagram failed - slave %i did not"
-               " respond.\n", slave->ring_position);
+        EC_ERR("Reception of state ack datagram failed on slave %i: ",
+                slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -471,8 +485,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_change_state_error;
-        EC_ERR("Reception of state ack check datagram failed - slave %i did"
-               " not respond.\n", slave->ring_position);
+        EC_ERR("Reception of state ack check datagram failed on slave %i: ",
+                slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
--- a/master/fsm_coe.c	Wed Sep 12 10:00:39 2007 +0000
+++ b/master/fsm_coe.c	Wed Sep 12 10:07:55 2007 +0000
@@ -289,8 +289,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_coe_error;
-        EC_ERR("Reception of CoE dictionary request failed - slave %i did"
-               " not respond.\n", slave->ring_position);
+        EC_ERR("Reception of CoE dictionary request failed on slave %i: ",
+                slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -325,9 +326,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_coe_error;
-        EC_ERR("Reception of CoE mailbox check datagram failed - slave %i did"
-               " not respond.\n",
+        EC_ERR("Reception of CoE mailbox check datagram failed on slave %i: ",
                slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -381,8 +382,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_coe_error;
-        EC_ERR("Reception of CoE dictionary response failed - slave %i did"
-               " not respond.\n", slave->ring_position);
+        EC_ERR("Reception of CoE dictionary response failed on slave %i: ",
+                slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -506,8 +508,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_coe_error;
-        EC_ERR("Reception of CoE SDO description request failed - slave %i did"
-               " not respond.\n", slave->ring_position);
+        EC_ERR("Reception of CoE SDO description"
+                " request failed on slave %i: ", slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -542,8 +545,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_coe_error;
-        EC_ERR("Reception of CoE mailbox check datagram failed - slave %i did"
-               " not respond.\n", slave->ring_position);
+        EC_ERR("Reception of CoE mailbox check"
+                " datagram failed on slave %i: ", slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -596,8 +600,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_coe_error;
-        EC_ERR("Reception of CoE SDO description response failed - slave %i"
-               " did not respond.\n", slave->ring_position);
+        EC_ERR("Reception of CoE SDO description"
+                " response failed on slave %i: ", slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -709,8 +714,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_coe_error;
-        EC_ERR("Reception of CoE SDO entry request failed - slave %i did"
-               " not respond.\n", slave->ring_position);
+        EC_ERR("Reception of CoE SDO entry request failed on slave %i: ",
+                slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -746,8 +752,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_coe_error;
-        EC_ERR("Reception of CoE mailbox check datagram failed - slave %i did"
-               " not respond.\n", slave->ring_position);
+        EC_ERR("Reception of CoE mailbox check"
+                " datagram failed on slave %i: ", slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -801,8 +808,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_coe_error;
-        EC_ERR("Reception of CoE SDO description response failed - slave %i"
-               " did not respond.\n", slave->ring_position);
+        EC_ERR("Reception of CoE SDO description"
+                " response failed on slave %i: ", slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -991,8 +999,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_coe_error;
-        EC_ERR("Reception of CoE download request failed - slave %i did not"
-               " respond.\n", slave->ring_position);
+        EC_ERR("Reception of CoE download request failed on slave %i: ",
+                slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -1027,8 +1036,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_coe_error;
-        EC_ERR("Reception of CoE mailbox check datagram failed - slave %i did"
-               " not respond.\n", slave->ring_position);
+        EC_ERR("Reception of CoE mailbox check"
+                " datagram failed on slave %i: ", slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -1080,8 +1090,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_coe_error;
-        EC_ERR("Reception of CoE download response failed - slave %i did not"
-               " respond.\n", slave->ring_position);
+        EC_ERR("Reception of CoE download response failed on slave %i: ",
+                slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -1200,8 +1211,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_coe_error;
-        EC_ERR("Reception of CoE upload request failed - slave %i did not"
-               " respond.\n", slave->ring_position);
+        EC_ERR("Reception of CoE upload request failed on slave %i: ",
+                slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -1236,8 +1248,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_coe_error;
-        EC_ERR("Reception of CoE mailbox check datagram failed - slave %i did"
-               " not respond.\n", slave->ring_position);
+        EC_ERR("Reception of CoE mailbox check"
+                " datagram failed on slave %i: ", slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -1294,8 +1307,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_coe_error;
-        EC_ERR("Reception of CoE upload response failed - slave %i did not"
-               " respond.\n", slave->ring_position);
+        EC_ERR("Reception of CoE upload response failed on slave %i: ",
+                slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -1439,8 +1453,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_coe_error;
-        EC_ERR("Reception of CoE upload segment request failed - slave %i did"
-               " not respond.\n", slave->ring_position);
+        EC_ERR("Reception of CoE upload segment"
+                " request failed on slave %i: ", slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -1475,8 +1490,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_coe_error;
-        EC_ERR("Reception of CoE mailbox check datagram failed - slave %i did"
-               " not respond.\n", slave->ring_position);
+        EC_ERR("Reception of CoE mailbox check"
+                " datagram failed on slave %i: ", slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -1533,8 +1549,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_coe_error;
-        EC_ERR("Reception of CoE upload segment response failed - slave %i"
-               " did not respond.\n", slave->ring_position);
+        EC_ERR("Reception of CoE upload segment"
+                " response failed on slave %i: ", slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
--- a/master/fsm_master.c	Wed Sep 12 10:00:39 2007 +0000
+++ b/master/fsm_master.c	Wed Sep 12 10:07:55 2007 +0000
@@ -587,18 +587,21 @@
 
     if (datagram->state != EC_DATAGRAM_RECEIVED) {
         EC_ERR("Failed to receive AL state datagram for slave %i"
-                " (datagram state %i)\n", slave->ring_position, datagram->state);
+                " (datagram state %i)\n",
+                slave->ring_position, datagram->state);
         fsm->state = ec_fsm_master_state_error;
         return;
     }
 
     // did the slave not respond to its station address?
-    if (datagram->working_counter != 1) {
+    if (datagram->working_counter == 0) {
         ec_slave_set_online_state(slave, EC_SLAVE_OFFLINE);
         ec_fsm_master_action_next_slave_state(fsm);
         return;
     }
 
+    // FIXME what to to on multiple response?
+
     // slave responded
     ec_slave_set_state(slave, EC_READ_U8(datagram->data)); // set app state first
     ec_slave_set_online_state(slave, EC_SLAVE_ONLINE);
@@ -774,8 +777,9 @@
     }
 
     if (datagram->working_counter != 1) {
-        EC_ERR("Failed to write station address - slave %i did not respond.\n",
+        EC_ERR("Failed to write station address of slave %i: ",
                slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         fsm->state = ec_fsm_master_state_error;
         return;
     }
--- a/master/fsm_sii.c	Wed Sep 12 10:00:39 2007 +0000
+++ b/master/fsm_sii.c	Wed Sep 12 10:07:55 2007 +0000
@@ -196,8 +196,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_sii_error;
-        EC_ERR("Reception of SII read datagram failed - slave %i did not"
-               " respond.\n", fsm->slave->ring_position);
+        EC_ERR("Reception of SII read datagram failed on slave %i: ",
+                fsm->slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -242,8 +243,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_sii_error;
-        EC_ERR("Reception of SII check/fetch datagram failed - slave %i did"
-               " not respond\n", fsm->slave->ring_position);
+        EC_ERR("Reception of SII check/fetch datagram failed on slave %i: ",
+                fsm->slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -338,8 +340,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_sii_error;
-        EC_ERR("Reception of SII write datagram failed - slave %i did not"
-               " respond.\n", fsm->slave->ring_position);
+        EC_ERR("Reception of SII write datagram failed on slave %i: ",
+                fsm->slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -375,8 +378,9 @@
 
     if (datagram->working_counter != 1) {
         fsm->state = ec_fsm_sii_error;
-        EC_ERR("Reception of SII write check datagram failed - slave %i did"
-               " not respond.\n", fsm->slave->ring_position);
+        EC_ERR("Reception of SII write check datagram failed on slave %i: ",
+                fsm->slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
--- a/master/fsm_slave.c	Wed Sep 12 10:00:39 2007 +0000
+++ b/master/fsm_slave.c	Wed Sep 12 10:07:55 2007 +0000
@@ -226,8 +226,9 @@
     if (datagram->working_counter != 1) {
         fsm->slave->error_flag = 1;
         fsm->state = ec_fsm_slave_state_error;
-        EC_ERR("Failed to write station address - slave %i did not respond.\n",
+        EC_ERR("Failed to write station address on slave %i: ",
                fsm->slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -243,7 +244,9 @@
    Slave scan state: STATE.
 */
 
-void ec_fsm_slave_scan_state_state(ec_fsm_slave_t *fsm /**< slave state machine */)
+void ec_fsm_slave_scan_state_state(
+        ec_fsm_slave_t *fsm /**< slave state machine */
+        )
 {
     ec_datagram_t *datagram = fsm->datagram;
     ec_slave_t *slave = fsm->slave;
@@ -262,8 +265,9 @@
     if (datagram->working_counter != 1) {
         fsm->slave->error_flag = 1;
         fsm->state = ec_fsm_slave_state_error;
-        EC_ERR("Failed to read AL state - slave %i did not respond.\n",
+        EC_ERR("Failed to read AL state of slave %i: ",
                fsm->slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -306,8 +310,9 @@
     if (datagram->working_counter != 1) {
         fsm->slave->error_flag = 1;
         fsm->state = ec_fsm_slave_state_error;
-        EC_ERR("Failed to read base data - slave %i did not respond.\n",
+        EC_ERR("Failed to read base data from slave %i: ",
                slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -352,8 +357,9 @@
     if (datagram->working_counter != 1) {
         fsm->slave->error_flag = 1;
         fsm->state = ec_fsm_slave_state_error;
-        EC_ERR("Failed to read DL status - slave %i did not respond.\n",
+        EC_ERR("Failed to read DL status from slave %i: ",
                slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -644,8 +650,9 @@
     if (datagram->working_counter != 1) {
         fsm->slave->error_flag = 1;
         fsm->state = ec_fsm_slave_state_error;
-        EC_ERR("Failed to clear FMMUs - slave %i did not respond.\n",
+        EC_ERR("Failed to clear FMMUs of slave %i: ",
                fsm->slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -726,8 +733,9 @@
     if (datagram->working_counter != 1) {
         slave->error_flag = 1;
         fsm->state = ec_fsm_slave_state_error;
-        EC_ERR("Failed to set sync managers - slave %i did not respond.\n",
+        EC_ERR("Failed to set sync managers of slave %i: ",
                slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -941,8 +949,9 @@
     if (datagram->working_counter != 1) {
         slave->error_flag = 1;
         fsm->state = ec_fsm_slave_state_error;
-        EC_ERR("Failed to set process data sync managers - slave %i did not"
-               " respond.\n", slave->ring_position);
+        EC_ERR("Failed to set process data sync managers of slave %i: ",
+                slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }
 
@@ -1002,8 +1011,9 @@
     if (datagram->working_counter != 1) {
         slave->error_flag = 1;
         fsm->state = ec_fsm_slave_state_error;
-        EC_ERR("Failed to set FMMUs - slave %i did not respond.\n",
+        EC_ERR("Failed to set FMMUs of slave %i: ",
                slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
         return;
     }