Clear DC assignment after going to INIT.
authorFlorian Pose <fp@igh-essen.com>
Mon, 20 Apr 2009 11:53:17 +0000
changeset 1406 8686c5b3d14b
parent 1405 2b5b6ccc00a0
child 1407 e3974f72d31e
Clear DC assignment after going to INIT.
documentation/ethercat_doc.tex
documentation/graphs/fsm_slave_conf.dot
master/fsm_slave_config.c
--- a/documentation/ethercat_doc.tex	Mon Apr 20 10:28:09 2009 +0000
+++ b/documentation/ethercat_doc.tex	Mon Apr 20 11:53:17 2009 +0000
@@ -1557,7 +1557,7 @@
 
 \begin{figure}[htbp]
   \centering
-  \includegraphics[height=.9\textheight]{graphs/fsm_slave_conf}
+  \includegraphics[height=\textheight]{graphs/fsm_slave_conf}
   \caption{Transition diagram of the slave configuration state
     machine}
   \label{fig:fsm-slaveconf}
--- a/documentation/graphs/fsm_slave_conf.dot	Mon Apr 20 10:28:09 2009 +0000
+++ b/documentation/graphs/fsm_slave_conf.dot	Mon Apr 20 11:53:17 2009 +0000
@@ -11,9 +11,9 @@
     enter_init -> init [weight=10]
 
     reconfigure [shape=point, label=""]
-    reconfigure -> init [fontname="Helvetica", label="Config\ndetached"]
+    reconfigure -> enter_init [fontname="Helvetica", label="Config\ndetached"]
 
-    init [fontname="Helvetica"]
+    init [fontname="Helvetica", style="bold"]
     init -> enter_clear_sync [fontname="Helvetica", label="No FMMUs"]
     init -> clear_fmmus [weight=10]
 
@@ -21,11 +21,18 @@
     clear_fmmus -> enter_clear_sync [weight=10]
 
     enter_clear_sync [shape=point, label=""]
-    enter_clear_sync -> enter_mbox_sync [fontname="Helvetica", label="No SMs"]
+    enter_clear_sync -> enter_clear_dc_assign [fontname="Helvetica", label="No SMs"]
     enter_clear_sync -> clear_sync [weight=10]
 
     clear_sync [fontname="Helvetica"]
-    clear_sync -> enter_mbox_sync [weight=10]
+    clear_sync -> enter_clear_dc_assign [weight=10]
+
+    enter_clear_dc_assign [shape=point, label=""]
+    enter_clear_dc_assign -> enter_mbox_sync [fontname="Helvetica", label="No DC\nsupport"]
+    enter_clear_dc_assign -> clear_dc_assign [weight=10]
+
+    clear_dc_assign [fontname="Helvetica"]
+    clear_dc_assign -> enter_mbox_sync [weight=10]
 
     enter_mbox_sync [shape=point, label=""]
     enter_mbox_sync -> end [fontname="Helvetica", label="INIT\nrequested"]
@@ -38,7 +45,7 @@
     enter_boot_preop [shape=point, label=""]
     enter_boot_preop -> boot_preop [weight=10]
 
-    boot_preop [fontname="Helvetica"]
+    boot_preop [fontname="Helvetica", style="bold"]
     boot_preop -> end [fontname="Helvetica", label="PREOP\nor BOOT\nrequested"]
     boot_preop -> enter_safeop [fontname="Helvetica", label="No slave\nconfig attached"]
     boot_preop -> enter_sdo_conf [weight=10]
@@ -96,12 +103,12 @@
     enter_safeop [shape=point,label=""]
     enter_safeop -> safeop [weight=10]
 
-    safeop [fontname="Helvetica"]
+    safeop [fontname="Helvetica", style="bold"]
     safeop -> end [fontname="Helvetica", label="SAFEOP\nrequested"]
     safeop -> op [weight=10]
 
-    op [fontname="Helvetica"]
-    op -> end// [weight=10]
+    op [fontname="Helvetica", style="bold"]
+    op -> end
 
     end [fontname="Helvetica"]
 }
--- a/master/fsm_slave_config.c	Mon Apr 20 10:28:09 2009 +0000
+++ b/master/fsm_slave_config.c	Mon Apr 20 11:53:17 2009 +0000
@@ -46,6 +46,7 @@
 void ec_fsm_slave_config_state_init(ec_fsm_slave_config_t *);
 void ec_fsm_slave_config_state_clear_fmmus(ec_fsm_slave_config_t *);
 void ec_fsm_slave_config_state_clear_sync(ec_fsm_slave_config_t *);
+void ec_fsm_slave_config_state_clear_dc_assign(ec_fsm_slave_config_t *);
 void ec_fsm_slave_config_state_mbox_sync(ec_fsm_slave_config_t *);
 void ec_fsm_slave_config_state_boot_preop(ec_fsm_slave_config_t *);
 void ec_fsm_slave_config_state_sdo_conf(ec_fsm_slave_config_t *);
@@ -62,6 +63,7 @@
 
 void ec_fsm_slave_config_enter_init(ec_fsm_slave_config_t *);
 void ec_fsm_slave_config_enter_clear_sync(ec_fsm_slave_config_t *);
+void ec_fsm_slave_config_enter_clear_dc_assign(ec_fsm_slave_config_t *);
 void ec_fsm_slave_config_enter_mbox_sync(ec_fsm_slave_config_t *);
 void ec_fsm_slave_config_enter_boot_preop(ec_fsm_slave_config_t *);
 void ec_fsm_slave_config_enter_sdo_conf(ec_fsm_slave_config_t *);
@@ -286,7 +288,7 @@
 
     if (!slave->sii.sync_count) { // FIXME use base_sync_count?
         // no sync managers
-        ec_fsm_slave_config_enter_mbox_sync(fsm);
+        ec_fsm_slave_config_enter_clear_dc_assign(fsm);
         return;
     }
 
@@ -332,6 +334,64 @@
         return;
     }
 
+    ec_fsm_slave_config_enter_clear_dc_assign(fsm);
+}
+
+/*****************************************************************************/
+
+/** Clear the DC assignment.
+ */
+void ec_fsm_slave_config_enter_clear_dc_assign(
+        ec_fsm_slave_config_t *fsm /**< slave state machine */
+        )
+{
+    ec_slave_t *slave = fsm->slave;
+    ec_datagram_t *datagram = fsm->datagram;
+
+    if (!slave->base_dc_supported) {
+        ec_fsm_slave_config_enter_mbox_sync(fsm);
+        return;
+    }
+
+    if (slave->master->debug_level)
+        EC_DBG("Clearing DC assignment of slave %u...\n",
+                slave->ring_position);
+
+    ec_datagram_fpwr(datagram, slave->station_address, 0x0980, 2);
+    ec_datagram_zero(datagram);
+    fsm->retries = EC_FSM_RETRIES;
+    fsm->state = ec_fsm_slave_config_state_clear_dc_assign;
+}
+
+/*****************************************************************************/
+
+/** Slave configuration state: CLEAR DC ASSIGN.
+ */
+void ec_fsm_slave_config_state_clear_dc_assign(
+        ec_fsm_slave_config_t *fsm /**< slave state machine */
+        )
+{
+    ec_datagram_t *datagram = fsm->datagram;
+
+    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
+        return;
+
+    if (datagram->state != EC_DATAGRAM_RECEIVED) {
+        fsm->state = ec_fsm_slave_config_state_error;
+        EC_ERR("Failed receive DC assignment clearing datagram"
+                " for slave %u.\n", fsm->slave->ring_position);
+        return;
+    }
+
+    if (datagram->working_counter != 1) {
+        fsm->slave->error_flag = 1;
+        fsm->state = ec_fsm_slave_config_state_error;
+        EC_ERR("Failed to clear DC assignment of slave %u: ",
+               fsm->slave->ring_position);
+        ec_datagram_print_wc_error(datagram);
+        return;
+    }
+
     ec_fsm_slave_config_enter_mbox_sync(fsm);
 }