Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable custom rtc clock source #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

marcfir
Copy link
Contributor

@marcfir marcfir commented Sep 13, 2024

Solves #23

The question for me is whether the following line also needs to be adapted to the custom CLOCK_SOURCE.

pec->dc.rtc_sto = osal_timer_gettime_nsec();

The packet latency in

libethercat/src/dc.c

Lines 100 to 108 in 9108db1

osal_uint64_t start = osal_timer_gettime_nsec();
hw_tx(pec->phw);
// wait for completion
osal_timer_t to;
osal_timer_init(&to, 100000000);
int local_ret = osal_binary_semaphore_timedwait(&p_idx->waiter, &to);
if (local_ret == OSAL_OK) {
duration = osal_timer_gettime_nsec() - start;

also uses osal_timer_gettime_nsec(). In libosal for POSIX, CLOCK_REALTIME is currently used, which I think is not optimal, because it can be changed by NTP (see here). So, at least for Linux CLOCK_MONOTONIC is better.

For measuring packet latency it doesn't matter which time reference is used, but for DC sync it is important if you want to synchronize the master rtc to an external clock, e.g. via PTP. In this case, you would prefer CLOCK_TAI.

@robert-burger
Copy link
Owner

Hi Marc,

i know that CLOCK_REALTIME is affected by NTP (i think our realtime system do not use NTP) so switching to a different clock source is a good option here.

But despite modifying/hacking this into libethercat wouldn't it be better to make it configurable in libosal to support CLOCK_MONOTIC(_RAW) and CLOCK_TAI? Then we do not need to take care about where a different clock source might be used here.

Cheers
Robert

@marcfir
Copy link
Contributor Author

marcfir commented Sep 17, 2024

Hi Robert,
Making the libosal configurable sounds good. I can make a suggestion.
Just a question about the ec_send_distributed_clocks. When using SO_TXTIME, you use the send() call before the actual send time to queue the frames in the ethernet adapter with a txtime. The adapter will then send the frames at the specified time. So I think ec_send_distributed_clocks should use the specified txtime, right?

@marcfir marcfir force-pushed the feat/custom_dc_rtc branch from 93511a9 to 245d708 Compare October 8, 2024 20:27
@robert-burger
Copy link
Owner

is this still necessary although we changed clock source in libosal?

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