use app_start_time for initial DC offset calculation because app_time might be overwritten while calculating the offsets.
authorMartin Troxler <ch1010277@ch10pc446>
Mon, 22 Nov 2010 08:50:34 +0100
changeset 1999 5f1269a71588
parent 1998 0330fdcbdd1f
child 2000 c76c01572f00
use app_start_time for initial DC offset calculation because app_time might be overwritten while calculating the offsets.
master/fsm_master.c
master/master.c
--- a/master/fsm_master.c	Tue Nov 16 15:32:27 2010 +0100
+++ b/master/fsm_master.c	Mon Nov 22 08:50:34 2010 +0100
@@ -907,13 +907,13 @@
 	system_time32 -= correction32;
 	old_offset32 = (u32) old_offset;
 
-    time_diff = (u32) slave->master->app_time - system_time32;
+    time_diff = (u32) slave->master->app_start_time - system_time32;
 
     EC_SLAVE_DBG(slave, 1, "DC system time offset calculation:"
             " system_time=%u (corrected with %u),"
-            " app_time=%llu, diff=%i\n",
+            " app_start_time=%llu, diff=%i\n",
 			system_time32, correction32,
-            slave->master->app_time, time_diff);
+            slave->master->app_start_time, time_diff);
 
     if (EC_ABS(time_diff) > EC_SYSTEM_TIME_TOLERANCE_NS) {
         new_offset = time_diff + old_offset32;
@@ -944,13 +944,13 @@
 	// correct read system time by elapsed time between read operation
 	// and app_time set time
 	system_time -= correction;
-	time_diff = fsm->slave->master->app_time - system_time;
+    time_diff = fsm->slave->master->app_start_time - system_time;
 
     EC_SLAVE_DBG(slave, 1, "DC system time offset calculation:"
             " system_time=%llu (corrected with %llu),"
-            " app_time=%llu, diff=%lli\n",
+            " app_start_time=%llu, diff=%lli\n",
             system_time, correction,
-            slave->master->app_time, time_diff);
+            slave->master->app_start_time, time_diff);
 
     if (EC_ABS(time_diff) > EC_SYSTEM_TIME_TOLERANCE_NS) {
         new_offset = time_diff + old_offset;
--- a/master/master.c	Tue Nov 16 15:32:27 2010 +0100
+++ b/master/master.c	Mon Nov 22 08:50:34 2010 +0100
@@ -2375,14 +2375,14 @@
 void ecrt_master_application_time(ec_master_t *master, uint64_t app_time)
 {
     master->app_time = app_time;
-#ifdef EC_HAVE_CYCLES
-    master->dc_cycles_app_time = get_cycles();
-#endif
-    master->dc_jiffies_app_time = jiffies;
 
     if (unlikely(!master->has_app_time)) {
 		EC_MASTER_DBG(master, 1, "set application start time = %llu\n",app_time);
 		master->app_start_time = app_time;
+#ifdef EC_HAVE_CYCLES
+    master->dc_cycles_app_time = get_cycles();
+#endif
+    master->dc_jiffies_app_time = jiffies;
         master->has_app_time = 1;
     }
 }