staticlong ppb_to_scaled_ppm(int ppb)
{ /* * The 'freq' field in the 'struct timex' is in parts per * million, but with a 16 bit binary fractional field. * Instead of calculating either one of * * scaled_ppm = (ppb / 1000) << 16 [1] * scaled_ppm = (ppb << 16) / 1000 [2] * * we simply use double precision math, in order to avoid the * truncation in [1] and the possible overflow in [2].
*/ return (long) (ppb * 65.536);
}
staticvoid usage(char *progname)
{
fprintf(stderr, "usage: %s [options]\n" " -c query the ptp clock's capabilities\n" " -d name device to open\n" " -e val read 'val' external time stamp events\n" " -E val enable rising (1), falling (2), or both (3) edges\n" " -f val adjust the ptp clock frequency by 'val' ppb\n" " -F chan Enable single channel mask and keep device open for debugfs verification.\n" " -g get the ptp clock time\n" " -h prints this message\n" " -i val index for event/trigger\n" " -k val measure the time offset between system and phc clock\n" " for 'val' times (Maximum 25)\n" " -l list the current pin configuration\n" " -L pin,val configure pin index 'pin' with function 'val'\n" " the channel index is taken from the '-i' option\n" " 'val' specifies the auxiliary function:\n" " 0 - none\n" " 1 - external time stamp\n" " 2 - periodic output\n" " -n val shift the ptp clock time by 'val' nanoseconds\n" " -o val phase offset (in nanoseconds) to be provided to the PHC servo\n" " -p val enable output with a period of 'val' nanoseconds\n" " -H val set output phase to 'val' nanoseconds (requires -p)\n" " -w val set output pulse width to 'val' nanoseconds (requires -p)\n" " -P val enable or disable (val=1|0) the system clock PPS\n" " -r open the ptp clock in readonly mode\n" " -s set the ptp clock time from the system time\n" " -S set the system time from the ptp clock time\n" " -t val shift the ptp clock time by 'val' seconds\n" " -T val set the ptp clock time to 'val' seconds\n" " -x val get an extended ptp clock time with the desired number of samples (up to %d)\n" " -X get a ptp clock cross timestamp\n" " -y val pre/post tstamp timebase to use {realtime|monotonic|monotonic-raw}\n" " -z test combinations of rising/falling external time stamp flags\n",
progname, PTP_MAX_SAMPLES);
}
char *device = DEVICE;
clockid_t clkid; int adjfreq = 0x7fffffff; int adjtime = 0; int adjns = 0; int adjphase = 0; int capabilities = 0; int extts = 0; int edge = 0; int flagtest = 0; int gettime = 0; int index = 0; int list_pins = 0; int pct_offset = 0; int getextended = 0; int getcross = 0; int n_samples = 0; int pin_index = -1, pin_func; int pps = -1; int seconds = 0; int readonly = 0; int settime = 0; int channel = -1;
clockid_t ext_clockid = CLOCK_REALTIME;
if (pps != -1) { int enable = pps ? 1 : 0; if (ioctl(fd, PTP_ENABLE_PPS, enable)) {
perror("PTP_ENABLE_PPS");
} else {
puts("pps for system time request okay");
}
}
if (pct_offset) { if (n_samples <= 0 || n_samples > 25) {
puts("n_samples should be between 1 and 25");
usage(progname); return -1;
}
if (ioctl(fd, PTP_SYS_OFFSET_EXTENDED, soe)) {
perror("PTP_SYS_OFFSET_EXTENDED");
} else {
printf("extended timestamp request returned %d samples\n",
getextended);
for (i = 0; i < getextended; i++) { switch (ext_clockid) { case CLOCK_REALTIME:
printf("sample #%2d: real time before: %lld.%09u\n",
i, soe->ts[i][0].sec,
soe->ts[i][0].nsec); break; case CLOCK_MONOTONIC:
printf("sample #%2d: monotonic time before: %lld.%09u\n",
i, soe->ts[i][0].sec,
soe->ts[i][0].nsec); break; case CLOCK_MONOTONIC_RAW:
printf("sample #%2d: monotonic-raw time before: %lld.%09u\n",
i, soe->ts[i][0].sec,
soe->ts[i][0].nsec); break; default: break;
}
printf(" phc time: %lld.%09u\n",
soe->ts[i][1].sec, soe->ts[i][1].nsec); switch (ext_clockid) { case CLOCK_REALTIME:
printf(" real time after: %lld.%09u\n",
soe->ts[i][2].sec,
soe->ts[i][2].nsec); break; case CLOCK_MONOTONIC:
printf(" monotonic time after: %lld.%09u\n",
soe->ts[i][2].sec,
soe->ts[i][2].nsec); break; case CLOCK_MONOTONIC_RAW:
printf(" monotonic-raw time after: %lld.%09u\n",
soe->ts[i][2].sec,
soe->ts[i][2].nsec); break; default: break;
}
}
}
free(soe);
}
if (getcross) {
xts = calloc(1, sizeof(*xts)); if (!xts) {
perror("calloc"); return -1;
}
if (ioctl(fd, PTP_SYS_OFFSET_PRECISE, xts)) {
perror("PTP_SYS_OFFSET_PRECISE");
} else {
puts("system and phc crosstimestamping request okay");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.