You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.3KB

  1. /*
  2. * ppsldics.c -- setup PPS line discipline for RS232
  3. *
  4. * Copyright (C) 2005-2007 Rodolfo Giometti <giometti@linux.it>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. */
  16. #include <stdio.h>
  17. #include <unistd.h>
  18. #include <stdlib.h>
  19. #include <errno.h>
  20. #include <sys/ioctl.h>
  21. #include <sys/types.h>
  22. #include <sys/stat.h>
  23. #include <fcntl.h>
  24. #include <string.h>
  25. #include <linux/tty.h>
  26. void usage(char *name)
  27. {
  28. fprintf(stderr, "usage: %s <ttyS>\n", name);
  29. exit(EXIT_FAILURE);
  30. }
  31. int main(int argc, char *argv[])
  32. {
  33. int fd;
  34. int ldisc = N_PPS;
  35. int ret;
  36. if (argc < 2)
  37. usage(argv[0]);
  38. fd = open(argv[1], O_RDWR);
  39. if (fd < 0) {
  40. perror("open");
  41. exit(EXIT_FAILURE);
  42. }
  43. ret = ioctl(fd, TIOCSETD, &ldisc);
  44. if (ret < 0) {
  45. perror("ioctl(TIOCSETD)");
  46. exit(EXIT_FAILURE);
  47. }
  48. pause();
  49. return 0;
  50. }