I am trying to adjust the frequency of a hardware clock device "dev/ptp0" in order to sync two clocks in Precision-Time-Protocol (PTP) Implementation, but the frequency doesn't seem to be adjusted synchronously as if some adjust calls are accumulated before being applied in the kernel and that is affecting my PI controller.
I want to confirm the system response to my frequency adjustments, so is there a way to get the current frequency of a clock in Linux?
I am using the following code to adjust/get frequency offsets but I want to get the actual frequency at the moment.
bool adjustFrequency(double adj)
{
struct timex tmx;
memset(&tmx, 0, sizeof(tmx));
tmx.modes = ADJ_FREQUENCY;
tmx.freq = (long)(round(adj * 65.536));
printf("setFrequency to %lld %f\n", tmx.freq, adj);
if(clock_adjtime(clockId, &tmx) < 0) {
printf("Could not adjust frequency offset of clock\n");
return FALSE;
}
return TRUE
}
double getFrequency(void)
{
struct timex tmx;
memset(&tmx, 0, sizeof(tmx));
if(clock_adjtime(clockId, &tmx) < 0) {
printf("Could not get frequency of clock\n");
return 0;
}
printf("getFrequency %lld %f\n",tmx.freq, (tmx.freq + 0.0) / 65.536 );
return( (tmx.freq + 0.0) / 65.536);
}