Skip to content

[WIP] Remove EtherCAT DC related code except config parsing#141

Closed
Copilot wants to merge 1 commit intodc-rewritefrom
copilot/remove-ethercat-dc-code
Closed

[WIP] Remove EtherCAT DC related code except config parsing#141
Copilot wants to merge 1 commit intodc-rewritefrom
copilot/remove-ethercat-dc-code

Conversation

Copy link
Contributor

Copilot AI commented Mar 5, 2026

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.

Original prompt

Objective

Remove all EtherCAT DC (Distributed Clock) related code from the codebase, except for the refClockSyncCycles config parsing in lcec_conf.c (and its corresponding field in the LCEC_CONF_MASTER_T struct in conf.h/lcec_conf.h).

This is on the dc-rewrite branch. The branch has a reorganized source structure compared to master (e.g. conf.h instead of lcec_conf.h, pal/pal.h, etc).

What to KEEP

  1. refClockSyncCycles field in LCEC_CONF_MASTER_T struct (in conf.h or lcec_conf.h)
  2. refClockSyncCycles XML attribute parsing in lcec_conf.c / parseMasterAttrs (the code that parses refClockSyncCycles from XML config)
  3. sync_ref_cycles field in lcec_master_t struct (in src/lcec.h) - keep the field itself as it stores the parsed value
  4. master->sync_ref_cycles = master_conf->refClockSyncCycles; assignment in lcec_main.c - keep this line that copies the config value

What to REMOVE

In src/lcec.h:

  1. lcec_slave_dc_t struct - the entire typedef struct with assignActivate, sync0Cycle, sync0Shift, sync1Cycle, sync1Shift fields
  2. lcec_slave_dc_t *dc_conf; field from lcec_slave_t struct
  3. DC-related fields in lcec_master_t within #ifdef RTAPI_TASK_PLL_SUPPORT block:
    • uint64_t dc_ref;
    • uint32_t app_time_last;
    • int dc_time_valid_last;
  4. sync_ref_cnt field from lcec_master_t
  5. PLL-related fields in lcec_master_data_t within #ifdef RTAPI_TASK_PLL_SUPPORT block:
    • hal_s32_t *pll_err;
    • hal_s32_t *pll_out;
    • hal_u32_t pll_step;
    • hal_u32_t pll_max_err;
    • hal_u32_t *pll_reset_cnt;

In src/lcec_main.c:

  1. Slave DC configuration - Remove ecrt_slave_config_dc() call and the surrounding code/log messages that configure DC for slaves using slave->dc_conf
  2. All sync_ref_cnt / sync_ref_cycles usage in the write function - the block that calls ecrt_master_sync_reference_clock() with the ref counter
  3. All #ifdef RTAPI_TASK_PLL_SUPPORT blocks dealing with DC sync:
    • The PLL reference time acquisition (rtapi_task_pll_get_reference())
    • The DC-aware application time calculation (master->dc_ref += period; app_time = ...)
    • The DC reference clock time retrieval (ecrt_master_reference_clock_time())
    • The BANG-BANG PLL controller code
    • rtapi_task_pll_set_correction() calls
    • master->dc_time_valid_last usage
    • master->app_time_last usage
  4. ecrt_master_sync_slave_clocks() call
  5. ecrt_master_sync_reference_clock() call
  6. DC-related initialization code - the block that initializes dc_time_valid_last, dc_ref, handles sync_ref_cycles sign for app_time_base adjustment
  7. PLL HAL pin exports - any code that creates HAL pins for pll_err, pll_out, pll_step, pll_max_err, pll_reset_cnt
  8. Simplify the application time computation to just: app_time = master->app_time_base + rtapi_get_time(); (remove all the conditional #ifdef variants)

In config files (conf.h / lcec_conf.h):

  1. LCEC_CONF_DC_T struct - the entire typedef struct with DC configuration fields
  2. lcecConfTypeDc enum value (if present in LCEC_CONF_TYPE_T)

In lcec_conf.c:

  1. parseDcConfAttrs function or equivalent DC config parsing function
  2. DC XML element handling - the XML parser state/transition that handles <dcConf> elements
  3. Any DC-related output buffer writes for LCEC_CONF_DC_T

In lcec_main.c config processing:

  1. case lcecConfTypeDc: block that processes DC configuration from shared memory and allocates/assigns slave->dc_conf

Important Notes

  • The application time computation should be simplified. Remove all the #ifdef RTAPI_TASK_PLL_SUPPORT conditional branches and just use the simple computation: app_time = master->app_time_base + rtapi_get_time();
  • Similarly, app_time_base initialization should be simplified to just: master->app_time_base -= rtapi_get_time(); without any conditional branches
  • ecrt_master_application_time() should still be called with the simplified app_time
  • ecrt_domain_queue(), ecrt_master_send() and the mutex handling should remain
  • The write function structure (processing slaves, sending process data) should remain intact
  • Keep master->app_time_period as it may be used elsewhere
  • Make sure no dangling references remain to removed types/fields

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot stopped work on behalf of sittner due to an error March 5, 2026 16:55
@sittner sittner closed this Mar 6, 2026
@sittner sittner deleted the copilot/remove-ethercat-dc-code branch March 7, 2026 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants