serial.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. typedef struct Serial Serial;
  10. typedef struct Serialops Serialops;
  11. typedef struct Serialport Serialport;
  12. struct Serialops {
  13. int (*seteps)(Serialport*);
  14. int (*init)(Serialport*);
  15. int (*getparam)(Serialport*);
  16. int (*setparam)(Serialport*);
  17. int (*clearpipes)(Serialport*);
  18. int (*reset)(Serial*, Serialport*);
  19. int (*sendlines)(Serialport*);
  20. int (*modemctl)(Serialport*, int);
  21. int (*setbreak)(Serialport*, int);
  22. int (*readstatus)(Serialport*);
  23. int (*wait4data)(Serialport*, u8 *, int);
  24. int (*wait4write)(Serialport*, u8 *, int);
  25. };
  26. enum {
  27. DataBufSz = 8*1024,
  28. Maxifc = 16,
  29. };
  30. struct Serialport {
  31. char name[32];
  32. Serial *s; /* device we belong to */
  33. int isjtag;
  34. Dev *epintr; /* may not exist */
  35. Dev *epin;
  36. Dev *epout;
  37. Usbfs fs;
  38. u8 ctlstate;
  39. /* serial parameters */
  40. u32 baud;
  41. int stop;
  42. int mctl;
  43. int parity;
  44. int bits;
  45. int fifo;
  46. int limit;
  47. int rts;
  48. int cts;
  49. int dsr;
  50. int dcd;
  51. int dtr;
  52. int rlsd;
  53. i64 timer;
  54. int blocked; /* for sw flow ctl. BUG: not implemented yet */
  55. int nbreakerr;
  56. int ring;
  57. int nframeerr;
  58. int nparityerr;
  59. int novererr;
  60. int enabled;
  61. int interfc; /* interfc on the device for ftdi */
  62. Channel *w4data;
  63. Channel *gotdata;
  64. Channel *readc; /* to uncouple reads, only used in ftdi... */
  65. int ndata;
  66. u8 data[DataBufSz];
  67. };
  68. struct Serial {
  69. QLock QLock;
  70. Dev *dev; /* usb device*/
  71. int type; /* serial model subtype */
  72. int recover; /* # of non-fatal recovery tries */
  73. Serialops Serialops;
  74. int hasepintr;
  75. int jtag; /* index of jtag interface, -1 none */
  76. int nifcs; /* # of serial interfaces, including JTAG */
  77. Serialport p[Maxifc];
  78. int maxrtrans;
  79. int maxwtrans;
  80. int maxread;
  81. int maxwrite;
  82. int inhdrsz;
  83. int outhdrsz;
  84. int baudbase; /* for special baud base settings, see ftdi */
  85. };
  86. enum {
  87. /* soft flow control chars */
  88. CTLS = 023,
  89. CTLQ = 021,
  90. CtlDTR = 1,
  91. CtlRTS = 2,
  92. };
  93. /*
  94. * !hget http://lxr.linux.no/source/drivers/usb/serial/pl2303.h|htmlfmt
  95. * !hget http://lxr.linux.no/source/drivers/usb/serial/pl2303.c|htmlfmt
  96. */
  97. int serialmain(Dev *d, int argc, char *argv[]);
  98. typedef struct Cinfo Cinfo;
  99. struct Cinfo {
  100. int vid; /* usb vendor id */
  101. int did; /* usb device/product id */
  102. int cid; /* controller id assigned by us */
  103. };
  104. extern Cinfo plinfo[];
  105. extern Cinfo uconsinfo[];
  106. extern int serialdebug;
  107. #define dsprint if(serialdebug)fprint
  108. int serialrecover(Serial *ser, Serialport *p, Dev *ep, char *err);
  109. int serialreset(Serial *ser);
  110. char *serdumpst(Serialport *p, char *buf, int bufsz);