Abort requests started for slave_configs that don't have any actual slaves.
authorGavin Lambert <gavinl@compacsort.com>
Tue, 14 Apr 2015 09:35:15 -0400
changeset 2620 0e4d098db815
parent 2619 f2bc4000e47a
child 2621 a26dee45c467
Abort requests started for slave_configs that don't have any actual slaves.
master/fsm_master.c
master/master.c
master/master.h
master/slave_config.c
master/slave_config.h
--- a/master/fsm_master.c	Tue Apr 14 09:34:15 2015 -0400
+++ b/master/fsm_master.c	Tue Apr 14 09:35:15 2015 -0400
@@ -246,6 +246,9 @@
         return;
     }
 
+    // check for detached config requests
+    ec_master_expire_slave_config_requests(fsm->master);
+
     ec_datagram_brd(fsm->datagram, 0x0130, 2);
     ec_datagram_zero(fsm->datagram);
     fsm->datagram->device_index = fsm->dev_idx;
--- a/master/master.c	Tue Apr 14 09:34:15 2015 -0400
+++ b/master/master.c	Tue Apr 14 09:35:15 2015 -0400
@@ -1785,6 +1785,21 @@
 
 /*****************************************************************************/
 
+/** Abort active requests for slave configs without attached slaves.
+ */
+void ec_master_expire_slave_config_requests(
+        ec_master_t *master /**< EtherCAT master. */
+        )
+{
+    ec_slave_config_t *sc;
+
+    list_for_each_entry(sc, &master->configs, list) {
+        ec_slave_config_expire_disconnected_requests(sc);
+    }
+}
+
+/*****************************************************************************/
+
 /** Common implementation for ec_master_find_slave()
  * and ec_master_find_slave_const().
  */
--- a/master/master.h	Tue Apr 14 09:34:15 2015 -0400
+++ b/master/master.h	Tue Apr 14 09:35:15 2015 -0400
@@ -351,6 +351,7 @@
 // misc.
 void ec_master_set_send_interval(ec_master_t *, unsigned int);
 void ec_master_attach_slave_configs(ec_master_t *);
+void ec_master_expire_slave_config_requests(ec_master_t *);
 ec_slave_t *ec_master_find_slave(ec_master_t *, uint16_t, uint16_t);
 const ec_slave_t *ec_master_find_slave_const(const ec_master_t *, uint16_t,
         uint16_t);
--- a/master/slave_config.c	Tue Apr 14 09:34:15 2015 -0400
+++ b/master/slave_config.c	Tue Apr 14 09:35:15 2015 -0400
@@ -553,6 +553,36 @@
     return NULL;
 }
 
+/*****************************************************************************/
+
+/** Expires any requests that have been started on a detached slave.
+ */
+void ec_slave_config_expire_disconnected_requests(
+        ec_slave_config_t *sc /**< Slave configuration. */
+        )
+{
+    ec_sdo_request_t *sdo_req;
+    ec_reg_request_t *reg_req;
+
+    if (sc->slave) { return; }
+    
+    list_for_each_entry(sdo_req, &sc->sdo_requests, list) {
+        if (sdo_req->state == EC_INT_REQUEST_QUEUED ||
+                sdo_req->state == EC_INT_REQUEST_BUSY) {
+            EC_CONFIG_DBG(sc, 1, "Aborting SDO request; no slave attached.\n");
+            sdo_req->state = EC_INT_REQUEST_FAILURE;
+        }
+    }
+    
+    list_for_each_entry(reg_req, &sc->reg_requests, list) {
+        if (reg_req->state == EC_INT_REQUEST_QUEUED ||
+                reg_req->state == EC_INT_REQUEST_BUSY) {
+            EC_CONFIG_DBG(sc, 1, "Aborting register request; no slave attached.\n");
+            reg_req->state = EC_INT_REQUEST_FAILURE;
+        }
+    }
+}
+
 /******************************************************************************
  *  Application interface
  *****************************************************************************/
--- a/master/slave_config.h	Tue Apr 14 09:34:15 2015 -0400
+++ b/master/slave_config.h	Tue Apr 14 09:35:15 2015 -0400
@@ -174,6 +174,7 @@
         unsigned int);
 ec_voe_handler_t *ec_slave_config_find_voe_handler(ec_slave_config_t *,
         unsigned int);
+void ec_slave_config_expire_disconnected_requests(ec_slave_config_t *);
 
 ec_sdo_request_t *ecrt_slave_config_create_sdo_request_err(
         ec_slave_config_t *, uint16_t, uint8_t, size_t);