phc: Add a method to query the maximum adjustment.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2011-11-12 18:18:44 +01:00
parent 150897669e
commit 5b8fa684ae
2 changed files with 26 additions and 0 deletions

17
phc.c
View File

@ -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)
@ -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
phc.h
View File

@ -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