diff --git a/master/fsm_master.c b/master/fsm_master.c index e0b41971..a60b4dc9 100644 --- a/master/fsm_master.c +++ b/master/fsm_master.c @@ -907,13 +907,13 @@ u64 ec_fsm_master_dc_offset32( 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 @@ u64 ec_fsm_master_dc_offset64( // 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; diff --git a/master/master.c b/master/master.c index e1983c08..16cf7a70 100644 --- a/master/master.c +++ b/master/master.c @@ -2375,14 +2375,14 @@ void ecrt_master_configured_slaves_state(const ec_master_t *master, ec_master_st 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; } }