From 5b8fa684ae632bf128e2798aa9ac140e9e4c81f0 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Sat, 12 Nov 2011 18:18:44 +0100 Subject: [PATCH] phc: Add a method to query the maximum adjustment. Signed-off-by: Richard Cochran --- phc.c | 17 +++++++++++++++++ phc.h | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/phc.c b/phc.c index d733cb2..16a61ef 100644 --- a/phc.c +++ b/phc.c @@ -16,11 +16,15 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include +#include #include #include #include #include +#include + #include "phc.h" clockid_t phc_open(char *phc) @@ -37,3 +41,16 @@ void phc_close(clockid_t clkid) close(CLOCKID_TO_FD(clkid)); } + +int phc_max_adj(clockid_t clkid) +{ + int fd = CLOCKID_TO_FD(clkid); + struct ptp_clock_caps caps; + + if (ioctl(fd, PTP_CLOCK_GETCAPS, &caps)) { + perror("PTP_CLOCK_GETCAPS"); + return 0; + } + + return caps.max_adj; +} diff --git a/phc.h b/phc.h index 8ea9e05..5eb775d 100644 --- a/phc.h +++ b/phc.h @@ -37,4 +37,13 @@ clockid_t phc_open(char *phc); */ void phc_close(clockid_t clkid); +/** + * Query the maximum frequency adjustment of a PTP hardware clock device. + * + * @param clkid A clock ID obtained using phc_open(). + * + * @return The clock's maximum frequency adjustment in parts per billion. + */ +int phc_max_adj(clockid_t clkid); + #endif