serial.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <thread.h>
  12. #include <usb/usb.h>
  13. #include <usb/usbfs.h>
  14. #include <usb/serial.h>
  15. #include <usb/ucons.h>
  16. #include <usb/prolific.h>
  17. #include <usb/ftdi.h>
  18. #include <usb/silabs.h>
  19. enum {
  20. Arglen = 80,
  21. };
  22. typedef struct Parg Parg;
  23. /* keep in sync with serial.c */
  24. static void
  25. usage(void)
  26. {
  27. fprint(2, "usage: %s [-dD] [-N nb] [-m mtpt] [-s srv] [dev...]\n", argv0);
  28. threadexitsall("usage");
  29. }
  30. static int
  31. matchserial(char *info, void*_)
  32. {
  33. if(uconsmatch(info) == 0 || plmatch(info) == 0 ||
  34. ftmatch(nil, info) == 0 || slmatch(info) == 0)
  35. return 0;
  36. return -1;
  37. }
  38. void
  39. threadmain(int argc, char **argv)
  40. {
  41. char *mnt, *srv, *as, *ae;
  42. char args[Arglen];
  43. mnt = "/dev";
  44. srv = nil;
  45. quotefmtinstall();
  46. ae = args + sizeof args;
  47. as = seprint(args, ae, "serial");
  48. ARGBEGIN{
  49. case 'D':
  50. usbfsdebug++;
  51. break;
  52. case 'd':
  53. usbdebug++;
  54. as = seprint(as, ae, " -d");
  55. break;
  56. case 'N':
  57. as = seprint(as, ae, " -N %s", EARGF(usage()));
  58. break;
  59. case 'm':
  60. mnt = EARGF(usage());
  61. break;
  62. case 's':
  63. srv = EARGF(usage());
  64. break;
  65. default:
  66. usage();
  67. break;
  68. }ARGEND;
  69. rfork(RFNOTEG);
  70. fmtinstall('U', Ufmt);
  71. threadsetgrp(threadid());
  72. usbfsinit(srv, mnt, &usbdirfs, MAFTER|MCREATE);
  73. startdevs(args, argv, argc, matchserial, nil, serialmain);
  74. threadexits(nil);
  75. }