diff --git a/phc.c b/phc.c index a90d13e..14132db 100644 --- a/phc.c +++ b/phc.c @@ -16,7 +16,9 @@ * 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 @@ -24,8 +26,6 @@ #include #include -#include - #include "phc.h" /* @@ -100,6 +100,25 @@ int phc_max_adj(clockid_t clkid) 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) { struct ptp_clock_caps caps; diff --git a/phc.h b/phc.h index c0c5996..4dbc374 100644 --- a/phc.h +++ b/phc.h @@ -46,6 +46,27 @@ void phc_close(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. *