From 43d49a21d0e44991bac8d0e4c2b56aa21252efdf Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Sun, 22 Dec 2019 10:45:56 -0800 Subject: [PATCH] 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 --- phc.c | 23 +++++++++++++++++++++-- phc.h | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) 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. *