Skip to content

Commit

Permalink
phc: Add a method to query the maximum adjustment.
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Cochran <[email protected]>
  • Loading branch information
richardcochran committed Nov 12, 2011
1 parent 1508976 commit 5b8fa68
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions phc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdio.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

#include <linux/ptp_clock.h>

#include "phc.h"

clockid_t phc_open(char *phc)
Expand All @@ -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;
}
9 changes: 9 additions & 0 deletions phc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5b8fa68

Please sign in to comment.