[PATCH 6/7] PPS: example program to enable PPS support on serial ports.
From: Rodolfo Giometti
Date: Thu Apr 10 2008 - 14:24:53 EST
Signed-off-by: Rodolfo Giometti <giometti@xxxxxxxx>
---
Documentation/pps/Makefile | 2 +-
Documentation/pps/ppsctl.c | 62 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 63 insertions(+), 1 deletions(-)
create mode 100644 Documentation/pps/ppsctl.c
diff --git a/Documentation/pps/Makefile b/Documentation/pps/Makefile
index af4f9b4..8ef4f47 100644
--- a/Documentation/pps/Makefile
+++ b/Documentation/pps/Makefile
@@ -1,4 +1,4 @@
-TARGETS = ppstest
+TARGETS = ppstest ppsctl
CFLAGS += -Wall -O2 -D_GNU_SOURCE
CFLAGS += -I .
diff --git a/Documentation/pps/ppsctl.c b/Documentation/pps/ppsctl.c
new file mode 100644
index 0000000..83fd08a
--- /dev/null
+++ b/Documentation/pps/ppsctl.c
@@ -0,0 +1,62 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <linux/serial.h>
+
+void usage(char *name)
+{
+ fprintf(stderr, "usage: %s <ttyS> [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;
+}
--
1.5.4.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/