Add PHC methods for querying and configuring the pin functionality.

In anticipation of support for external time stamping in PHC devices, this
patch adds wrapper functions around the pin functionality.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2019-12-22 10:45:56 -08:00
parent 9850ce0e51
commit 43d49a21d0
2 changed files with 42 additions and 2 deletions

23
phc.c
View File

@ -16,7 +16,9 @@
* with this program; if not, write to the Free Software Foundation, Inc., * with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <linux/ptp_clock.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
@ -24,8 +26,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <linux/ptp_clock.h>
#include "phc.h" #include "phc.h"
/* /*
@ -100,6 +100,25 @@ int phc_max_adj(clockid_t clkid)
return max; return max;
} }
int phc_number_pins(clockid_t clkid)
{
struct ptp_clock_caps caps;
if (phc_get_caps(clkid, &caps)) {
return 0;
}
return caps.n_pins;
}
int phc_pin_setfunc(clockid_t clkid, struct ptp_pin_desc *desc)
{
int err = ioctl(CLOCKID_TO_FD(clkid), PTP_PIN_SETFUNC2, desc);
if (err) {
fprintf(stderr, PTP_PIN_SETFUNC_FAILED "\n");
}
return err;
}
int phc_has_pps(clockid_t clkid) int phc_has_pps(clockid_t clkid)
{ {
struct ptp_clock_caps caps; struct ptp_clock_caps caps;

21
phc.h
View File

@ -46,6 +46,27 @@ void phc_close(clockid_t clkid);
*/ */
int phc_max_adj(clockid_t clkid); int phc_max_adj(clockid_t clkid);
/**
* Queries the number of programmable pins of a PTP hardware clock device.
*
* @param clkid A clock ID obtained using phc_open().
*
* @return The number of pins supported by the clock.
*/
int phc_number_pins(clockid_t clkid);
/**
* Configures a pin of a PTP hardware clock device.
*
* @param clkid A clock ID obtained using phc_open().
*
* @param desc Pointer to a pin descriptor with the 'index', 'func',
* and 'chan' fields set.
*
* @return Zero on success, non-zero otherwise.
*/
int phc_pin_setfunc(clockid_t clkid, struct ptp_pin_desc *desc);
/** /**
* Checks whether the given PTP hardware clock device supports PPS output. * Checks whether the given PTP hardware clock device supports PPS output.
* *