Improved DC sync at startup: Abort iterating though slaves and first correct
authorFlorian Pose <fp@igh-essen.com>
Tue, 09 Aug 2011 22:10:45 +0200
changeset 2098 0ce254664c81
parent 2097 6392734fb198
child 2101 01b30593e942
Improved DC sync at startup: Abort iterating though slaves and first correct
system time offsets, then begin configuring at slave 0.
documentation/graphs/fsm_master.dot
master/fsm_master.c
--- a/documentation/graphs/fsm_master.dot	Tue Aug 09 01:33:22 2011 +0200
+++ b/documentation/graphs/fsm_master.dot	Tue Aug 09 22:10:45 2011 +0200
@@ -1,5 +1,5 @@
 
-/* $Id: fsm_master.dot,v df2b21f15939 2010/05/02 06:03:05 fp $ */
+/* $Id$ */
 
 digraph master {
     size="7,9"
@@ -37,6 +37,7 @@
     action_configure [shape=point,label=""]
     action_configure -> configure_slave [weight=10]
     action_configure -> action_next_slave_state
+    action_configure -> write_system_times
 
     read_state -> acknowledge [weight=10]
     read_state -> action_configure
--- a/master/fsm_master.c	Tue Aug 09 01:33:22 2011 +0200
+++ b/master/fsm_master.c	Tue Aug 09 22:10:45 2011 +0200
@@ -567,6 +567,17 @@
     ec_master_t *master = fsm->master;
     ec_slave_t *slave = fsm->slave;
 
+    if (master->config_changed) {
+        // abort iterating through slaves,
+        // first compensate DC system time offsets,
+        // then begin configuring at slave 0
+        EC_MASTER_DBG(master, 1, "Configuration changed"
+                " (aborting state check).\n");
+
+        fsm->slave = master->slaves; // begin with first slave
+        ec_fsm_master_enter_write_system_times(fsm);
+    }
+
     // Does the slave have to be configured?
     if ((slave->current_state != slave->requested_state
                 || slave->force_config) && !slave->error_flag) {
@@ -853,6 +864,7 @@
     EC_MASTER_DBG(master, 1, "Writing system time offsets...\n");
 
     if (master->has_app_time) {
+
         while (fsm->slave < master->slaves + master->slave_count) {
             if (!fsm->slave->base_dc_supported
                     || !fsm->slave->has_dc_system_time) {
@@ -869,8 +881,14 @@
             fsm->state = ec_fsm_master_state_dc_read_offset;
             return;
         }
+
     } else {
-        EC_MASTER_DBG(master, 1, "No app_time received up to now.\n");
+        if (master->active) {
+            EC_MASTER_ERR(master, "No app_time received up to now,"
+                    " but master already active).\n");
+        } else {
+            EC_MASTER_DBG(master, 1, "No app_time received up to now.\n");
+        }
     }
 
     ec_master_request_op(master);