master/fsm_slave_config.c
changeset 2663 b101637f503c
parent 2635 42b62867574d
equal deleted inserted replaced
2660:161c675135f0 2663:b101637f503c
  1363     ec_master_t *master = slave->master;
  1363     ec_master_t *master = slave->master;
  1364     ec_slave_config_t *config = slave->config;
  1364     ec_slave_config_t *config = slave->config;
  1365     uint32_t abs_sync_diff;
  1365     uint32_t abs_sync_diff;
  1366     unsigned long diff_ms;
  1366     unsigned long diff_ms;
  1367     ec_sync_signal_t *sync0 = &config->dc_sync[0];
  1367     ec_sync_signal_t *sync0 = &config->dc_sync[0];
       
  1368     ec_sync_signal_t *sync1 = &config->dc_sync[1];
  1368     u64 start_time;
  1369     u64 start_time;
  1369 
  1370 
  1370     if (!config) { // config removed in the meantime
  1371     if (!config) { // config removed in the meantime
  1371         ec_fsm_slave_config_reconfigure(fsm);
  1372         ec_fsm_slave_config_reconfigure(fsm);
  1372         return;
  1373         return;
  1422 
  1423 
  1423     if (sync0->cycle_time) {
  1424     if (sync0->cycle_time) {
  1424         // find correct phase
  1425         // find correct phase
  1425         if (master->has_app_time) {
  1426         if (master->has_app_time) {
  1426             u64 diff, start;
  1427             u64 diff, start;
  1427             u32 remainder;
  1428             u32 remainder, cycle;
  1428 
  1429 
  1429             diff = start_time - master->app_start_time;
  1430             diff = start_time - master->app_start_time;
  1430             remainder = do_div(diff, sync0->cycle_time);
  1431             cycle = sync0->cycle_time + sync1->cycle_time;
  1431 
  1432             remainder = do_div(diff, cycle);
  1432             start = start_time +
  1433 
  1433                 sync0->cycle_time - remainder + sync0->shift_time;
  1434             start = start_time + cycle - remainder + sync0->shift_time;
  1434 
  1435 
  1435             EC_SLAVE_DBG(slave, 1, "app_start_time=%llu\n",
  1436             EC_SLAVE_DBG(slave, 1, "app_start_time=%llu\n",
  1436                     master->app_start_time);
  1437                     master->app_start_time);
  1437             EC_SLAVE_DBG(slave, 1, "      app_time=%llu\n", master->app_time);
  1438             EC_SLAVE_DBG(slave, 1, "      app_time=%llu\n", master->app_time);
  1438             EC_SLAVE_DBG(slave, 1, "    start_time=%llu\n", start_time);
  1439             EC_SLAVE_DBG(slave, 1, "    start_time=%llu\n", start_time);
  1439             EC_SLAVE_DBG(slave, 1, "    cycle_time=%u\n", sync0->cycle_time);
  1440             EC_SLAVE_DBG(slave, 1, "         cycle=%u\n", cycle);
  1440             EC_SLAVE_DBG(slave, 1, "    shift_time=%i\n", sync0->shift_time);
  1441             EC_SLAVE_DBG(slave, 1, "    shift_time=%i\n", sync0->shift_time);
  1441             EC_SLAVE_DBG(slave, 1, "     remainder=%u\n", remainder);
  1442             EC_SLAVE_DBG(slave, 1, "     remainder=%u\n", remainder);
  1442             EC_SLAVE_DBG(slave, 1, "         start=%llu\n", start);
  1443             EC_SLAVE_DBG(slave, 1, "         start=%llu\n", start);
  1443             start_time = start;
  1444             start_time = start;
  1444         } else {
  1445         } else {