Removed slave online flag.
authorFlorian Pose <fp@igh-essen.com>
Fri, 25 Apr 2008 12:45:44 +0000
changeset 906 f95e3e33c0cf
parent 905 6d74ebc603ee
child 907 570ae1c64465
Removed slave online flag.
master/ethernet.c
master/fsm_master.c
master/slave.c
master/slave.h
--- a/master/ethernet.c	Fri Apr 25 12:23:52 2008 +0000
+++ b/master/ethernet.c	Fri Apr 25 12:45:44 2008 +0000
@@ -358,8 +358,7 @@
 
 void ec_eoe_state_rx_start(ec_eoe_t *eoe /**< EoE handler */)
 {
-    if (eoe->slave->online_state == EC_SLAVE_OFFLINE ||
-            !eoe->slave->master->main_device.link_state)
+    if (eoe->slave->error_flag || !eoe->slave->master->main_device.link_state)
         return;
 
     ec_slave_mbox_prepare_check(eoe->slave, &eoe->datagram);
@@ -559,8 +558,7 @@
     unsigned int wakeup = 0;
 #endif
 
-    if (eoe->slave->online_state == EC_SLAVE_OFFLINE ||
-            !eoe->slave->master->main_device.link_state)
+    if (eoe->slave->error_flag || !eoe->slave->master->main_device.link_state)
         return;
 
     spin_lock_bh(&eoe->tx_queue_lock);
--- a/master/fsm_master.c	Fri Apr 25 12:23:52 2008 +0000
+++ b/master/fsm_master.c	Fri Apr 25 12:45:44 2008 +0000
@@ -190,23 +190,16 @@
     if (datagram->state == EC_DATAGRAM_TIMED_OUT)
         return; // always retry
 
-    if (datagram->state != EC_DATAGRAM_RECEIVED) { // link is down
-        fsm->slaves_responding = 0;
-        list_for_each_entry(slave, &master->slaves, list) {
-            ec_slave_set_online_state(slave, EC_SLAVE_OFFLINE);
-        }
-        fsm->state = ec_fsm_master_state_error;
-        return;
-    }
-
     // bus topology change?
     if (datagram->working_counter != fsm->slaves_responding) {
         fsm->topology_change_pending = 1;
         fsm->slaves_responding = datagram->working_counter;
-
-        EC_INFO("%u slave%s responding.\n",
-                fsm->slaves_responding,
-                fsm->slaves_responding == 1 ? "" : "s");
+        EC_INFO("%u slave(s) responding.\n", fsm->slaves_responding);
+    }
+
+    if (datagram->state != EC_DATAGRAM_RECEIVED) { // link is down
+        fsm->state = ec_fsm_master_state_error;
+        return;
     }
 
     // slave states changed?
@@ -304,7 +297,6 @@
 {
     ec_master_t *master = fsm->master;
     ec_sii_write_request_t *request;
-    ec_slave_t *slave;
 
     // search the first request to be processed
     while (1) {
@@ -320,19 +312,10 @@
         request->state = EC_REQUEST_BUSY;
         up(&master->sii_sem);
 
-        slave = request->slave;
-        if (slave->online_state == EC_SLAVE_OFFLINE) {
-            EC_ERR("Discarding SII data, slave %i offline.\n",
-                    slave->ring_position);
-            request->state = EC_REQUEST_FAILURE;
-            wake_up(&master->sii_queue);
-            continue;
-        }
-
         // found pending SII write operation. execute it!
         if (master->debug_level)
-            EC_DBG("Writing SII data to slave %i...\n",
-                    slave->ring_position);
+            EC_DBG("Writing SII data to slave %u...\n",
+                    request->slave->ring_position);
         fsm->sii_request = request;
         fsm->sii_index = 0;
         ec_fsm_sii_write(&fsm->fsm_sii, request->slave, request->word_offset,
@@ -414,7 +397,6 @@
 
         slave = request->slave;
         if (slave->current_state == EC_SLAVE_STATE_INIT ||
-                slave->online_state == EC_SLAVE_OFFLINE ||
                 slave->error_flag) {
             EC_ERR("Discarding Sdo request, slave %u not ready.\n",
                     slave->ring_position);
@@ -425,7 +407,7 @@
 
         // Found pending Sdo request. Execute it!
         if (master->debug_level)
-            EC_DBG("Processing Sdo request for slave %i...\n",
+            EC_DBG("Processing Sdo request for slave %u...\n",
                     slave->ring_position);
 
         // Start uploading Sdo
@@ -459,7 +441,6 @@
     // FIXME do not check all slaves in every cycle...
     list_for_each_entry(slave, &master->slaves, list) {
         if (slave->error_flag
-                || slave->online_state == EC_SLAVE_OFFLINE
                 || slave->requested_state == EC_SLAVE_STATE_UNKNOWN
                 || (slave->current_state == slave->requested_state
                     && slave->self_configured)) continue;
@@ -529,7 +510,6 @@
                 || slave->sdo_dictionary_fetched
                 || slave->current_state == EC_SLAVE_STATE_INIT
                 || jiffies - slave->jiffies_preop < EC_WAIT_SDO_DICT * HZ
-                || slave->online_state == EC_SLAVE_OFFLINE
                 || slave->error_flag) continue;
 
             if (master->debug_level) {
@@ -608,17 +588,20 @@
     }
 
     // did the slave not respond to its station address?
-    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
+    if (datagram->working_counter != 1) {
+        if (!slave->error_flag) {
+            slave->error_flag = 1;
+            if (fsm->master->debug_level)
+                EC_DBG("Slave %u did not respond to state query.\n",
+                        fsm->slave->ring_position);
+        }
+        fsm->topology_change_pending = 1;
+        fsm->state = ec_fsm_master_state_error;
+        return;
+    }
+
+    // a single 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);
 
     // check, if new slave state has to be acknowledged
     if (slave->current_state & EC_SLAVE_STATE_ACK_ERR && !slave->error_flag) {
--- a/master/slave.c	Fri Apr 25 12:23:52 2008 +0000
+++ b/master/slave.c	Fri Apr 25 12:45:44 2008 +0000
@@ -118,7 +118,6 @@
     slave->config = NULL;
     slave->requested_state = EC_SLAVE_STATE_PREOP;
     slave->current_state = EC_SLAVE_STATE_UNKNOWN;
-    slave->online_state = EC_SLAVE_ONLINE;
     slave->self_configured = 0;
     slave->error_flag = 0;
 
@@ -329,35 +328,6 @@
 /*****************************************************************************/
 
 /**
- * Sets the online state of a slave.
- */
-
-void ec_slave_set_online_state(ec_slave_t *slave, /**< EtherCAT slave */
-        ec_slave_online_state_t new_state /**< new online state */
-        )
-{
-    if (new_state == EC_SLAVE_OFFLINE &&
-            slave->online_state == EC_SLAVE_ONLINE) {
-        if (slave->master->debug_level)
-            EC_DBG("Slave %u: offline.\n", slave->ring_position);
-    }
-    else if (new_state == EC_SLAVE_ONLINE &&
-            slave->online_state == EC_SLAVE_OFFLINE) {
-        slave->error_flag = 0; // clear error flag
-        if (slave->master->debug_level) {
-            char cur_state[EC_STATE_STRING_SIZE];
-            ec_state_string(slave->current_state, cur_state);
-            EC_DBG("Slave %u: online (%s).\n",
-                   slave->ring_position, cur_state);
-        }
-    }
-
-    slave->online_state = new_state;
-}
-
-/*****************************************************************************/
-
-/**
  * Request a slave state and resets the error flag.
  */
 
--- a/master/slave.h	Fri Apr 25 12:23:52 2008 +0000
+++ b/master/slave.h	Fri Apr 25 12:45:44 2008 +0000
@@ -82,15 +82,6 @@
 
 /*****************************************************************************/
 
-/** EtherCAT slave online state.
- */
-typedef enum {
-    EC_SLAVE_OFFLINE,
-    EC_SLAVE_ONLINE
-} ec_slave_online_state_t;
-
-/*****************************************************************************/
-
 /** Supported mailbox protocols.
  */
 enum {
@@ -182,7 +173,6 @@
     ec_slave_config_t *config; /**< Current configuration. */
     ec_slave_state_t requested_state; /**< Requested application state. */
     ec_slave_state_t current_state; /**< Current application state. */
-    ec_slave_online_state_t online_state; /**< online state */
     unsigned int self_configured; /**< Slave was configured by this master. */
     unsigned int error_flag; /**< Stop processing after an error. */
 
@@ -220,7 +210,6 @@
 
 void ec_slave_request_state(ec_slave_t *, ec_slave_state_t);
 void ec_slave_set_state(ec_slave_t *, ec_slave_state_t);
-void ec_slave_set_online_state(ec_slave_t *, ec_slave_online_state_t);
 
 // SII categories
 int ec_slave_fetch_sii_strings(ec_slave_t *, const uint8_t *, size_t);