Allow the slave to not respond to the mailbox sync manager configuration
authorFlorian Pose <fp@igh-essen.com>
Tue, 27 Jan 2009 14:14:37 +0000
changeset 1347 41360ffdcb14
parent 1346 eecc75468e08
child 1348 8db0f72ace11
Allow the slave to not respond to the mailbox sync manager configuration
datagram for a certain time.
TODO
master/fsm_slave_config.c
master/fsm_slave_config.h
--- a/TODO	Tue Jan 27 09:40:05 2009 +0000
+++ b/TODO	Tue Jan 27 14:14:37 2009 +0000
@@ -26,7 +26,6 @@
 * Bus simulator interface.
 * Implement ecrt_master_slave() in kernel space.
 * Rename phy-commands to register commands.
-* Timeout for sync manager config after clearing.
 
 Future issues:
 
--- a/master/fsm_slave_config.c	Tue Jan 27 09:40:05 2009 +0000
+++ b/master/fsm_slave_config.c	Tue Jan 27 14:14:37 2009 +0000
@@ -451,6 +451,8 @@
             slave->sii.boot_tx_mailbox_size;
     }
 
+    fsm->take_time = 1;
+
     fsm->retries = EC_FSM_RETRIES;
     fsm->state = ec_fsm_slave_config_state_mbox_sync;
 }
@@ -479,7 +481,36 @@
         return;
     }
 
-    if (datagram->working_counter != 1) {
+    if (fsm->take_time) {
+        fsm->take_time = 0;
+        fsm->jiffies_start = datagram->jiffies_sent;
+    }
+
+    /* Because the sync manager configurations are cleared during the last
+     * cycle, some slaves do not immediately respond to the mailbox sync
+     * manager configuration datagram. Therefore, resend the datagram for
+     * a certain time, if the slave does not respond.
+     */
+    if (datagram->working_counter == 0) {
+        unsigned long diff = datagram->jiffies_received - fsm->jiffies_start;
+
+        if (diff >= HZ) {
+            slave->error_flag = 1;
+            fsm->state = ec_fsm_slave_config_state_error;
+            EC_ERR("Timeout while configuring mailbox sync managers of"
+                    " slave %u.\n", slave->ring_position);
+            return;
+        }
+        else if (slave->master->debug_level) {
+            EC_DBG("Resending after %u ms...\n",
+                    (unsigned int) diff * 1000 / HZ);
+        }
+
+        // send configuration datagram again
+        fsm->retries = EC_FSM_RETRIES;
+        return;
+    }
+    else if (datagram->working_counter != 1) {
         slave->error_flag = 1;
         fsm->state = ec_fsm_slave_config_state_error;
         EC_ERR("Failed to set sync managers of slave %u: ",
--- a/master/fsm_slave_config.h	Tue Jan 27 09:40:05 2009 +0000
+++ b/master/fsm_slave_config.h	Tue Jan 27 14:14:37 2009 +0000
@@ -60,6 +60,8 @@
     unsigned int retries; /**< Retries on datagram timeout. */
     ec_sdo_request_t *request; /**< SDO request for SDO configuration. */
     ec_sdo_request_t request_copy; /**< Copied SDO request. */
+    unsigned long jiffies_start; /**< For timeout calculations. */
+    unsigned int take_time; /**< Store jiffies after datagram reception. */
 };
 
 /*****************************************************************************/