Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762863AbYBRX0y (ORCPT ); Mon, 18 Feb 2008 18:26:54 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756024AbYBRX0O (ORCPT ); Mon, 18 Feb 2008 18:26:14 -0500 Received: from 81-174-11-161.static.ngi.it ([81.174.11.161]:41609 "EHLO mail.enneenne.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755341AbYBRX0K (ORCPT ); Mon, 18 Feb 2008 18:26:10 -0500 From: Rodolfo Giometti To: linux-kernel@vger.kernel.org Cc: Andrew Morton , David Woodhouse , Dave Jones , Sam Ravnborg , Greg KH , Rodolfo Giometti Date: Tue, 19 Feb 2008 00:28:38 +0100 Message-Id: <120337732021-git-send-email-giometti@linux.it> X-Mailer: git-send-email 1.5.2.5 In-Reply-To: <12033773203297-git-send-email-giometti@linux.it> References: <1203377319975-git-send-email-giometti@linux.it> <1203377319560-git-send-email-giometti@linux.it> <1203377320720-git-send-email-giometti@linux.it> <12033773201179-git-send-email-giometti@linux.it> <12033773201912-git-send-email-giometti@linux.it> <12033773203297-git-send-email-giometti@linux.it> X-SA-Exim-Connect-IP: 192.168.32.1 X-SA-Exim-Mail-From: giometti@enneenne.com Subject: [PATCH] PPS: example program to enable PPS support on serial ports. X-SA-Exim-Version: 4.2.1 (built Tue, 09 Jan 2007 17:23:22 +0000) X-SA-Exim-Scanned: Yes (on mail.enneenne.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2221 Lines: 93 Signed-off-by: Rodolfo Giometti --- 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 +#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; +} -- 1.5.2.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/