Skip to content

Commit

Permalink
feat: Add ec_send_distributed_clocks_sync_with_rtc to enable a custom…
Browse files Browse the repository at this point in the history
… rtc clock source
  • Loading branch information
marcfir committed Oct 8, 2024
1 parent fba7b24 commit 245d708
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
11 changes: 11 additions & 0 deletions include/libethercat/ec.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,17 @@ int ec_send_process_data(ec_t *pec);
*/
int ec_send_distributed_clocks_sync(ec_t *pec);

//! \brief Send distributed clock sync datagram
/*!
* \param pec Pointer to ethercat master structure,
* which you got from \link ec_open \endlink.
* \param act_rtc_time Current real-time clock value. If 0, the time of
* osal_timer_gettime_nsec() will be used. Otherwise
* the supplied time is used.
* \return 0 on success
*/
int ec_send_distributed_clocks_sync_with_rtc(ec_t *pec, osal_uint64_t act_rtc_time);

//! \brief Send broadcast read to ec state.
/*!
* \param[in] pec Pointer to ethercat master structure,
Expand Down
32 changes: 29 additions & 3 deletions src/ec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1828,10 +1828,13 @@ static void cb_distributed_clocks(struct ec *pec, pool_entry_t *p_entry, ec_data

//! send distributed clock sync datagram
/*!
* \param pec ethercat master pointer
* \param pec ethercat master pointer
* \param act_rtc_time Current real-time clock value. If 0, the time of
* osal_timer_gettime_nsec() will be used. Otherwise
* the supplied time is used.
* \return 0 on success
*/
int ec_send_distributed_clocks_sync(ec_t *pec) {
int ec_send_distributed_clocks_sync_intern(ec_t *pec, osal_uint64_t act_rtc_time) {
assert(pec != NULL);

int ret = EC_OK;
Expand Down Expand Up @@ -1879,7 +1882,9 @@ int ec_send_distributed_clocks_sync(ec_t *pec) {
p_dg->adr = ((osal_uint32_t)EC_REG_DCSYSTIME << 16u) | pec->dc.master_address;
}

osal_uint64_t act_rtc_time = osal_timer_gettime_nsec();
if (act_rtc_time == 0){
act_rtc_time = osal_timer_gettime_nsec();
}

if (pec->dc.mode == dc_mode_ref_clock) {
if (pec->main_cycle_interval > 0) {
Expand All @@ -1905,6 +1910,27 @@ int ec_send_distributed_clocks_sync(ec_t *pec) {
return ret;
}

//! send distributed clock sync datagram
/*!
* \param pec ethercat master pointer
* \return 0 on success
*/
int ec_send_distributed_clocks_sync(ec_t *pec) {
return ec_send_distributed_clocks_sync_intern(pec,0);
}

//! send distributed clock sync datagram
/*!
* \param pec ethercat master pointer
* \param act_rtc_time Current real-time clock value. If 0, the time of
* osal_timer_gettime_nsec() will be used. Otherwise
* the supplied time is used.
* \return 0 on success
*/
int ec_send_distributed_clocks_sync_with_rtc(ec_t *pec, osal_uint64_t act_rtc_time) {
return ec_send_distributed_clocks_sync_intern(pec,act_rtc_time);
}

//! local callack for syncronous read/write
static void cb_brd_ec_state(struct ec *pec, pool_entry_t *p_entry, ec_datagram_t *p_dg) {
assert(pec != NULL);
Expand Down

0 comments on commit 245d708

Please sign in to comment.