From d972a9e5577217de0fbdaa84edbc6918641d3628 Mon Sep 17 00:00:00 2001 From: marcfir Date: Tue, 3 Sep 2024 13:12:42 +0000 Subject: [PATCH] feat: Support the configuration of slaves to use only dc sync1 --- include/libethercat/slave.h | 2 +- src/slave.c | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/libethercat/slave.h b/include/libethercat/slave.h index 2750236..f18a0ad 100644 --- a/include/libethercat/slave.h +++ b/include/libethercat/slave.h @@ -527,7 +527,7 @@ void ec_slave_add_init_cmd(ec_t *pec, osal_uint16_t slave, ec_init_cmd_t *cmd); * the physical order of the ethercat slaves * (usually the n'th slave attached). * \param[in] use_dc Whether to en-/disable dc on slave. - * \param[in] type DC type, 0 = sync0, 1 = sync01. + * \param[in] type DC type, 0 = sync0, 1 = sync01, 2 = sync1. * \param[in] cycle_time_0 Cycle time of sync 0 [ns]. * \param[in] cycle_time_1 Cycle time of sync 1 [ns]. * \param[in] cycle_shift Cycle shift time [ns]. diff --git a/src/slave.c b/src/slave.c index a70a966..b69b95a 100644 --- a/src/slave.c +++ b/src/slave.c @@ -1051,8 +1051,16 @@ int ec_slave_state_transition(ec_t *pec, osal_uint16_t slave, ec_state_t state) if (slv->dc.cycle_time_0 == 0u) { slv->dc.cycle_time_0 = pec->main_cycle_interval; } + if (slv->dc.type == 2) { + ec_log(10, get_transition_string(transition), + "slave %2d: configuring dc sync 1, " + "cycle_times %d/%d, cycle_shift %d\n", + slave, slv->dc.cycle_time_0, + slv->dc.cycle_time_1, slv->dc.cycle_shift); - if (slv->dc.type == 1) { + ec_dc_sync(pec, slave, 5, slv->dc.cycle_time_0, + slv->dc.cycle_time_1, slv->dc.cycle_shift); + } else if (slv->dc.type == 1) { if (slv->dc.cycle_time_1 == 0u) { slv->dc.cycle_time_1 = pec->main_cycle_interval; }