Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758367AbYCFMFz (ORCPT ); Thu, 6 Mar 2008 07:05:55 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752064AbYCFMFo (ORCPT ); Thu, 6 Mar 2008 07:05:44 -0500 Received: from 81-174-11-161.static.ngi.it ([81.174.11.161]:51391 "EHLO mail.enneenne.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751981AbYCFMFn (ORCPT ); Thu, 6 Mar 2008 07:05:43 -0500 From: Rodolfo Giometti To: linux-kernel@vger.kernel.org Cc: Andrew Morton , David Woodhouse , Dave Jones , Sam Ravnborg , Greg KH , Randy Dunlap , Rodolfo Giometti Date: Thu, 6 Mar 2008 13:09:05 +0100 Message-Id: <12048053472718-git-send-email-giometti@linux.it> X-Mailer: git-send-email 1.5.2.5 In-Reply-To: <12048053472063-git-send-email-giometti@linux.it> References: <12048053463198-git-send-email-giometti@linux.it> <12048053473401-git-send-email-giometti@linux.it> <12048053471754-git-send-email-giometti@linux.it> <12048053471177-git-send-email-giometti@linux.it> <12048053473741-git-send-email-giometti@linux.it> <12048053472063-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 6/7] 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/