From: Rodolfo Giometti Signed-off-by: Rodolfo Giometti Signed-off-by: Andrew Morton --- Documentation/pps/Makefile | 2 - Documentation/pps/ppsctl.c | 62 +++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff -puN Documentation/pps/Makefile~pps-example-program-to-enable-pps-support-on-serial-ports Documentation/pps/Makefile --- a/Documentation/pps/Makefile~pps-example-program-to-enable-pps-support-on-serial-ports +++ a/Documentation/pps/Makefile @@ -1,4 +1,4 @@ -TARGETS = ppstest +TARGETS = ppstest ppsctl CFLAGS += -Wall -O2 -D_GNU_SOURCE CFLAGS += -I . diff -puN /dev/null Documentation/pps/ppsctl.c --- /dev/null +++ a/Documentation/pps/ppsctl.c @@ -0,0 +1,62 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void usage(char *name) +{ + fprintf(stderr, "usage: %s [enable|disable]\n", name); + + exit(EXIT_FAILURE); +} + +int main(int argc, char *argv[]) +{ + int fd; + int ret; + struct serial_struct ss; + + if (argc < 2) + usage(argv[0]); + + fd = open(argv[1], O_RDWR); + if (fd < 0) { + perror("open"); + exit(EXIT_FAILURE); + } + + ret = ioctl(fd, TIOCGSERIAL, &ss); + if (ret < 0) { + perror("ioctl(TIOCGSERIAL)"); + exit(EXIT_FAILURE); + } + + if (argc < 3) { /* just read PPS status */ + printf("PPS is %sabled\n", + ss.flags & ASYNC_HARDPPS_CD ? "en" : "dis"); + exit(EXIT_SUCCESS); + } + + if (argv[2][0] == 'e' || argv[2][0] == '1') + ss.flags |= ASYNC_HARDPPS_CD; + else if (argv[2][0] == 'd' || argv[2][0] == '0') + ss.flags &= ~ASYNC_HARDPPS_CD; + else { + fprintf(stderr, "invalid state argument \"%s\"\n", argv[2]); + exit(EXIT_FAILURE); + } + + ret = ioctl(fd, TIOCSSERIAL, &ss); + if (ret < 0) { + perror("ioctl(TIOCSSERIAL)"); + exit(EXIT_FAILURE); + } + + return 0; +} _