Central CoE timeouts; retry on CoE response mismatch.
authorFlorian Pose <fp@igh-essen.com>
Mon, 23 Jun 2008 12:03:37 +0000
changeset 1053 0cb9604cbaa7
parent 1052 22b509f8c898
child 1054 4c16fe64b403
Central CoE timeouts; retry on CoE response mismatch.
master/fsm_coe.c
master/fsm_coe_map.c
master/fsm_slave_config.c
master/sdo_request.c
--- a/master/fsm_coe.c	Mon Jun 23 10:31:26 2008 +0000
+++ b/master/fsm_coe.c	Mon Jun 23 12:03:37 2008 +0000
@@ -45,6 +45,12 @@
 
 /*****************************************************************************/
 
+/** Maximum time in ms to wait for responses when reading out the dictionary.
+ */
+#define EC_FSM_COE_DICT_TIMEOUT 3000
+
+/*****************************************************************************/
+
 void ec_fsm_coe_dict_start(ec_fsm_coe_t *);
 void ec_fsm_coe_dict_request(ec_fsm_coe_t *);
 void ec_fsm_coe_dict_check(ec_fsm_coe_t *);
@@ -357,7 +363,7 @@
     if (!ec_slave_mbox_check(datagram)) {
         unsigned long diff_ms =
             (datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ;
-        if (diff_ms >= 100) {
+        if (diff_ms >= EC_FSM_COE_DICT_TIMEOUT) {
             fsm->state = ec_fsm_coe_error;
             EC_ERR("Timeout while checking Sdo dictionary on slave %u.\n",
                    slave->ring_position);
@@ -454,10 +460,14 @@
 
     if (EC_READ_U16(data) >> 12 != 0x8 || // Sdo information
         (EC_READ_U8 (data + 2) & 0x7F) != 0x02) { // Get OD List response
-        EC_ERR("Invalid Sdo list response at slave %u!\n",
-               slave->ring_position);
-        ec_print_data(data, rec_size);
-        fsm->state = ec_fsm_coe_error;
+        if (fsm->slave->master->debug_level) {
+            EC_DBG("Invalid Sdo list response at slave %u! Retrying...\n",
+                    slave->ring_position);
+            ec_print_data(data, rec_size);
+        }
+        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
+        fsm->retries = EC_FSM_RETRIES;
+        fsm->state = ec_fsm_coe_dict_check;
         return;
     }
 
@@ -597,7 +607,7 @@
     if (!ec_slave_mbox_check(datagram)) {
         unsigned long diff_ms =
             (datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ;
-        if (diff_ms >= 100) {
+        if (diff_ms >= EC_FSM_COE_DICT_TIMEOUT) {
             fsm->state = ec_fsm_coe_error;
             EC_ERR("Timeout while checking Sdo description on slave %u.\n",
                    slave->ring_position);
@@ -697,11 +707,16 @@
     if (EC_READ_U16(data) >> 12 != 0x8 || // Sdo information
         (EC_READ_U8 (data + 2) & 0x7F) != 0x04 || // Object desc. response
         EC_READ_U16(data + 6) != sdo->index) { // Sdo index
-        EC_ERR("Invalid object description response at slave %u while"
-               " fetching Sdo 0x%04X!\n", slave->ring_position,
-               sdo->index);
-        ec_print_data(data, rec_size);
-        fsm->state = ec_fsm_coe_error;
+        if (fsm->slave->master->debug_level) {
+            EC_DBG("Invalid object description response at slave %u while"
+                    " fetching Sdo 0x%04X!\n", slave->ring_position,
+                    sdo->index);
+            ec_print_data(data, rec_size);
+        }
+        // check for CoE response again
+        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
+        fsm->retries = EC_FSM_RETRIES;
+        fsm->state = ec_fsm_coe_dict_desc_check;
         return;
     }
 
@@ -827,7 +842,7 @@
     if (!ec_slave_mbox_check(datagram)) {
         unsigned long diff_ms =
             (datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ;
-        if (diff_ms >= 100) {
+        if (diff_ms >= EC_FSM_COE_DICT_TIMEOUT) {
             fsm->state = ec_fsm_coe_error;
             EC_ERR("Timeout while checking Sdo entry on slave %u.\n",
                    slave->ring_position);
@@ -929,11 +944,16 @@
         (EC_READ_U8(data + 2) & 0x7F) != 0x06 || // Entry desc. response
         EC_READ_U16(data + 6) != sdo->index || // Sdo index
         EC_READ_U8(data + 8) != fsm->subindex) { // Sdo subindex
-        EC_ERR("Invalid entry description response at slave %u while"
-               " fetching Sdo entry 0x%04X:%02X!\n", slave->ring_position,
-               sdo->index, fsm->subindex);
-        ec_print_data(data, rec_size);
-        fsm->state = ec_fsm_coe_error;
+        if (fsm->slave->master->debug_level) {
+            EC_DBG("Invalid entry description response at slave %u while"
+                    " fetching Sdo entry 0x%04X:%02X!\n", slave->ring_position,
+                    sdo->index, fsm->subindex);
+            ec_print_data(data, rec_size);
+        }
+        // check for CoE response again
+        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
+        fsm->retries = EC_FSM_RETRIES;
+        fsm->state = ec_fsm_coe_dict_entry_check;
         return;
     }
 
@@ -1101,7 +1121,7 @@
                 (jiffies - fsm->request->jiffies_sent) * 1000 / HZ;
             if (diff_ms < fsm->request->response_timeout) {
                 if (fsm->slave->master->debug_level) {
-                    EC_DBG("Slave %u did no respond to Sdo download request. "
+                    EC_DBG("Slave %u did not respond to Sdo download request. "
                             "Retrying after %u ms...\n",
                             slave->ring_position, (u32) diff_ms);
                     // no response; send request datagram again
@@ -1156,10 +1176,10 @@
     if (!ec_slave_mbox_check(datagram)) {
         unsigned long diff_ms =
             (datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ;
-        if (diff_ms >= 100) {
+        if (diff_ms >= fsm->request->response_timeout) {
             fsm->state = ec_fsm_coe_error;
-            EC_ERR("Timeout while checking Sdo configuration on slave %u.\n",
-                   slave->ring_position);
+            EC_ERR("Timeout while waiting for Sdo download response on "
+                    "slave %u.\n", slave->ring_position);
             return;
         }
 
@@ -1260,12 +1280,15 @@
         EC_READ_U8 (data + 2) >> 5 != 0x3 || // Download response
         EC_READ_U16(data + 3) != request->index || // index
         EC_READ_U8 (data + 5) != request->subindex) { // subindex
-        fsm->state = ec_fsm_coe_error;
-        EC_ERR("Sdo download 0x%04X:%02X (%u bytes) failed:\n",
-               request->index, request->subindex, request->data_size);
-        EC_ERR("Invalid Sdo download response at slave %u!\n",
-               slave->ring_position);
-        ec_print_data(data, rec_size);
+        if (slave->master->debug_level) {
+            EC_DBG("Invalid Sdo download response at slave %u! Retrying...\n",
+                    slave->ring_position);
+            ec_print_data(data, rec_size);
+        }
+        // check for CoE response again
+        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
+        fsm->retries = EC_FSM_RETRIES;
+        fsm->state = ec_fsm_coe_down_check;
         return;
     }
 
@@ -1518,12 +1541,15 @@
                 EC_READ_U8 (data + 2) >> 5 != 0x2 || // upload response
                 EC_READ_U16(data + 3) != request->index || // index
                 EC_READ_U8 (data + 5) != request->subindex) { // subindex
-            fsm->state = ec_fsm_coe_error;
-            EC_ERR("Sdo upload 0x%04X:%02X failed:\n",
-                    request->index, request->subindex);
-            EC_ERR("Invalid Sdo upload expedited response at slave %u!\n",
-                    slave->ring_position);
-            ec_print_data(data, rec_size);
+            if (fsm->slave->master->debug_level) {
+                EC_DBG("Invalid Sdo upload expedited response at slave %u!\n",
+                        slave->ring_position);
+                ec_print_data(data, rec_size);
+            }
+            // check for CoE response again
+            ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
+            fsm->retries = EC_FSM_RETRIES;
+            fsm->state = ec_fsm_coe_up_check;
             return;
         }
 
@@ -1559,12 +1585,15 @@
                 EC_READ_U8 (data + 2) >> 5 != 0x2 || // upload response
                 EC_READ_U16(data + 3) != request->index || // index
                 EC_READ_U8 (data + 5) != request->subindex) { // subindex
-            fsm->state = ec_fsm_coe_error;
-            EC_ERR("Sdo upload 0x%04X:%02X failed:\n",
-                    request->index, request->subindex);
-            EC_ERR("Invalid Sdo normal upload response at slave %u!\n",
-                    slave->ring_position);
-            ec_print_data(data, rec_size);
+            if (fsm->slave->master->debug_level) {
+                EC_DBG("Invalid Sdo normal upload response at slave %u!\n",
+                        slave->ring_position);
+                ec_print_data(data, rec_size);
+            }
+            // check for CoE response again
+            ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
+            fsm->retries = EC_FSM_RETRIES;
+            fsm->state = ec_fsm_coe_up_check;
             return;
         }
 
@@ -1694,10 +1723,10 @@
     if (!ec_slave_mbox_check(datagram)) {
         unsigned long diff_ms =
             (datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ;
-        if (diff_ms >= 100) {
+        if (diff_ms >= fsm->request->response_timeout) {
             fsm->state = ec_fsm_coe_error;
-            EC_ERR("Timeout while checking Sdo upload segment on slave %u.\n",
-                   slave->ring_position);
+            EC_ERR("Timeout while waiting for Sdo upload segment response "
+                    "on slave %u.\n", slave->ring_position);
             return;
         }
 
@@ -1794,11 +1823,15 @@
 
     if (EC_READ_U16(data) >> 12 != 0x3 || // Sdo response
         EC_READ_U8 (data + 2) >> 5 != 0x0) { // upload segment response
-        EC_ERR("Sdo upload 0x%04X:%02X failed:\n", request->index, request->subindex);
-        EC_ERR("Invalid Sdo upload segment response at slave %u!\n",
+        if (fsm->slave->master->debug_level) {
+            EC_DBG("Invalid Sdo upload segment response at slave %u!\n",
                slave->ring_position);
-        ec_print_data(data, rec_size);
-        fsm->state = ec_fsm_coe_error;
+            ec_print_data(data, rec_size);
+        }
+        // check for CoE response again
+        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
+        fsm->retries = EC_FSM_RETRIES;
+        fsm->state = ec_fsm_coe_up_seg_check;
         return;
     }
 
--- a/master/fsm_coe_map.c	Mon Jun 23 10:31:26 2008 +0000
+++ b/master/fsm_coe_map.c	Mon Jun 23 12:03:37 2008 +0000
@@ -61,12 +61,6 @@
 
 /*****************************************************************************/
 
-/** Sdo upload timeout in ms for reading Pdo assigment/mapping.
- */
-#define EC_FSM_COE_MAP_UPLOAD_TIMEOUT 3000
-
-/*****************************************************************************/
-
 /**
    Constructor.
 */
@@ -79,7 +73,6 @@
     fsm->fsm_coe = fsm_coe;
     fsm->state = NULL;
     ec_sdo_request_init(&fsm->request);
-    fsm->request.response_timeout = EC_FSM_COE_MAP_UPLOAD_TIMEOUT;
     ec_pdo_list_init(&fsm->pdos);
 }
 
--- a/master/fsm_slave_config.c	Mon Jun 23 10:31:26 2008 +0000
+++ b/master/fsm_slave_config.c	Mon Jun 23 12:03:37 2008 +0000
@@ -44,10 +44,6 @@
 #include "slave_config.h"
 #include "fsm_slave_config.h"
 
-/** Time in ms to wait for a response when downloading Sdo configurations.
- */
-#define EC_FSM_SLAVE_CONF_SDO_CONF_TIMEOUT 3000
-
 /*****************************************************************************/
 
 void ec_fsm_slave_config_state_start(ec_fsm_slave_config_t *);
@@ -452,7 +448,6 @@
     fsm->request = list_entry(fsm->slave->config->sdo_configs.next,
             ec_sdo_request_t, list);
     ecrt_sdo_request_write(fsm->request);
-    fsm->request->response_timeout = EC_FSM_SLAVE_CONF_SDO_CONF_TIMEOUT;
     ec_fsm_coe_transfer(&fsm->fsm_coe, fsm->slave, fsm->request);
     ec_fsm_coe_exec(&fsm->fsm_coe); // execute immediately
 }
--- a/master/sdo_request.c	Mon Jun 23 10:31:26 2008 +0000
+++ b/master/sdo_request.c	Mon Jun 23 12:03:37 2008 +0000
@@ -44,6 +44,12 @@
 
 /*****************************************************************************/
 
+/** Default timeout in ms to wait for Sdo transfer responses.
+ */
+#define EC_SDO_REQUEST_RESPONSE_TIMEOUT 3000
+
+/*****************************************************************************/
+
 void ec_sdo_request_clear_data(ec_sdo_request_t *);
 
 /*****************************************************************************/
@@ -71,7 +77,7 @@
     req->data_size = 0;
     req->dir = EC_DIR_OUTPUT;
     req->issue_timeout = 0; // no timeout
-    req->response_timeout = 0; // immediate response required
+    req->response_timeout = EC_SDO_REQUEST_RESPONSE_TIMEOUT;
     req->state = EC_REQUEST_INIT;
     req->abort_code = 0x00000000;
 }