Fixed possible bug in EoE code: Only restart EoE process, when it was running
authorFlorian Pose <fp@igh-essen.com>
Tue, 27 Apr 2010 13:40:44 +0200
changeset 1914 da7adbde2625
parent 1913 cbef34ba142b
child 1915 54e4b49b163c
child 1980 a89e2bedf004
Fixed possible bug in EoE code: Only restart EoE process, when it was running
before (not while scanning).
master/master.c
--- a/master/master.c	Tue Apr 27 10:37:32 2010 +0200
+++ b/master/master.c	Tue Apr 27 13:40:44 2010 +0200
@@ -1941,6 +1941,9 @@
     uint32_t domain_offset;
     ec_domain_t *domain;
     int ret;
+#ifdef EC_EOE
+    int eoe_was_running;
+#endif
 
     if (master->debug_level)
         EC_DBG("ecrt_master_activate(master = 0x%p)\n", master);
@@ -1972,10 +1975,12 @@
     up(&master->master_sem);
 
     // restart EoE process and master thread with new locking
+
+    ec_master_thread_stop(master);
 #ifdef EC_EOE
+    eoe_was_running = master->eoe_thread != NULL;
     ec_master_eoe_stop(master);
 #endif
-    ec_master_thread_stop(master);
 
     if (master->debug_level)
         EC_DBG("FSM datagram is %p.\n", &master->fsm_datagram);
@@ -1987,15 +1992,17 @@
     master->receive_cb = master->app_receive_cb;
     master->cb_data = master->app_cb_data;
     
+#ifdef EC_EOE
+    if (eoe_was_running) {
+        ec_master_eoe_start(master);
+    }
+#endif
     ret = ec_master_thread_start(master, ec_master_operation_thread,
                 "EtherCAT-OP");
     if (ret < 0) {
         EC_ERR("Failed to start master thread!\n");
         return ret;
     }
-#ifdef EC_EOE
-    ec_master_eoe_start(master);
-#endif
 
     master->allow_config = 1; // request the current configuration
     master->allow_scan = 1; // allow re-scanning on topology change
@@ -2010,6 +2017,7 @@
     ec_slave_t *slave;
 #ifdef EC_EOE
     ec_eoe_t *eoe;
+    int eoe_was_running;
 #endif
 
     if (master->debug_level)
@@ -2020,10 +2028,11 @@
         return;
     }
 
+    ec_master_thread_stop(master);
 #ifdef EC_EOE
+    eoe_was_running = master->eoe_thread != NULL;
     ec_master_eoe_stop(master);
 #endif
-    ec_master_thread_stop(master);
     
     master->send_cb = ec_master_internal_send_cb;
     master->receive_cb = ec_master_internal_receive_cb;
@@ -2059,12 +2068,14 @@
     master->app_start_time = 0ULL;
     master->has_start_time = 0;
 
+#ifdef EC_EOE
+    if (eoe_was_running) {
+        ec_master_eoe_start(master);
+    }
+#endif
     if (ec_master_thread_start(master, ec_master_idle_thread,
                 "EtherCAT-IDLE"))
         EC_WARN("Failed to restart master thread!\n");
-#ifdef EC_EOE
-    ec_master_eoe_start(master);
-#endif
 
     master->allow_scan = 1;
     master->allow_config = 1;