termios.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2017/08/30 Bernard The first version
  9. * 2021/12/10 linzhenxing put tty system
  10. */
  11. #ifndef __TERMIOS_H__
  12. #define __TERMIOS_H__
  13. #include <sys/types.h>
  14. #include <sys/ioctl.h>
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. typedef unsigned char cc_t;
  19. typedef unsigned int speed_t;
  20. typedef unsigned int tcflag_t;
  21. #define NCCS 32
  22. struct termios {
  23. tcflag_t c_iflag;
  24. tcflag_t c_oflag;
  25. tcflag_t c_cflag;
  26. tcflag_t c_lflag;
  27. cc_t c_line;
  28. cc_t c_cc[NCCS];
  29. speed_t __c_ispeed;
  30. speed_t __c_ospeed;
  31. };
  32. #ifndef NCC
  33. #define NCC 8
  34. struct termio
  35. {
  36. unsigned short c_iflag; /* input mode flags */
  37. unsigned short c_oflag; /* output mode flags */
  38. unsigned short c_cflag; /* control mode flags */
  39. unsigned short c_lflag; /* local mode flags */
  40. unsigned char c_line; /* line discipline */
  41. unsigned char c_cc[NCC]; /* control characters */
  42. };
  43. #endif
  44. /* c_cc characters */
  45. #define VINTR 0
  46. #define VQUIT 1
  47. #define VERASE 2
  48. #define VKILL 3
  49. #define VEOF 4
  50. #define VTIME 5
  51. #define VMIN 6
  52. #define VSWTC 7
  53. #define VSTART 8
  54. #define VSTOP 9
  55. #define VSUSP 10
  56. #define VEOL 11
  57. #define VREPRINT 12
  58. #define VDISCARD 13
  59. #define VWERASE 14
  60. #define VLNEXT 15
  61. #define VEOL2 16
  62. /* c_iflag bits */
  63. #define IGNBRK 0000001
  64. #define BRKINT 0000002
  65. #define IGNPAR 0000004
  66. #define PARMRK 0000010
  67. #define INPCK 0000020
  68. #define ISTRIP 0000040
  69. #define INLCR 0000100
  70. #define IGNCR 0000200
  71. #define ICRNL 0000400
  72. #define IUCLC 0001000
  73. #define IXON 0002000
  74. #define IXANY 0004000
  75. #define IXOFF 0010000
  76. #define IMAXBEL 0020000
  77. #define IUTF8 0040000
  78. /* c_oflag bits */
  79. #define OPOST 0000001
  80. #define OLCUC 0000002
  81. #define ONLCR 0000004
  82. #define OCRNL 0000010
  83. #define ONOCR 0000020
  84. #define ONLRET 0000040
  85. #define OFILL 00000100
  86. #define OFDEL 00000200
  87. #define NLDLY 00001400
  88. #define NL0 00000000
  89. #define NL1 00000400
  90. #define NL2 00001000
  91. #define NL3 00001400
  92. #define TABDLY 00006000
  93. #define TAB0 00000000
  94. #define TAB1 00002000
  95. #define TAB2 00004000
  96. #define TAB3 00006000
  97. #define CRDLY 00030000
  98. #define KCR0 00000000
  99. #define KCR1 00010000
  100. #define KCR2 00020000
  101. #define KCR3 00030000
  102. #define FFDLY 00040000
  103. #define FF0 00000000
  104. #define FF1 00040000
  105. #define BSDLY 00100000
  106. #define BS0 00000000
  107. #define BS1 00100000
  108. #define VTDLY 00200000
  109. #define VT0 00000000
  110. #define VT1 00200000
  111. #define XTABS 01000000
  112. #define B0 0000000
  113. #define B50 0000001
  114. #define B75 0000002
  115. #define B110 0000003
  116. #define B134 0000004
  117. #define B150 0000005
  118. #define B200 0000006
  119. #define B300 0000007
  120. #define B600 0000010
  121. #define B1200 0000011
  122. #define B1800 0000012
  123. #define B2400 0000013
  124. #define B4800 0000014
  125. #define B9600 0000015
  126. #define B19200 0000016
  127. #define B38400 0000017
  128. #define B57600 0010001
  129. #define B115200 0010002
  130. #define B230400 0010003
  131. #define B460800 0010004
  132. #define B500000 0010005
  133. #define B576000 0010006
  134. #define B921600 0010007
  135. #define B1000000 0010010
  136. #define B1152000 0010011
  137. #define B1500000 0010012
  138. #define B2000000 0010013
  139. #define B2500000 0010014
  140. #define B3000000 0010015
  141. #define B3500000 0010016
  142. #define B4000000 0010017
  143. #define CSIZE 0000060
  144. #define CS5 0000000
  145. #define CS6 0000020
  146. #define CS7 0000040
  147. #define CS8 0000060
  148. #define CSTOPB 0000100
  149. #define CREAD 0000200
  150. #define PARENB 0000400
  151. #define PARODD 0001000
  152. #define HUPCL 0002000
  153. #define CLOCAL 0004000
  154. /* c_lflag bits */
  155. #define ISIG 0000001
  156. #define ICANON 0000002
  157. #define XCASE 0000004
  158. #define ECHO 0000010
  159. #define ECHOE 0000020
  160. #define ECHOK 0000040
  161. #define ECHONL 0000100
  162. #define NOFLSH 0000200
  163. #define TOSTOP 0000400
  164. #define ECHOCTL 0001000
  165. #define ECHOPRT 0002000
  166. #define ECHOKE 0004000
  167. #define FLUSHO 0010000
  168. #define PENDIN 0040000
  169. #define IEXTEN 0100000
  170. #define EXTPROC 0200000
  171. #define TCOOFF 0
  172. #define TCOON 1
  173. #define TCIOFF 2
  174. #define TCION 3
  175. #define TCIFLUSH 0
  176. #define TCOFLUSH 1
  177. #define TCIOFLUSH 2
  178. #define TCSANOW 0
  179. #define TCSADRAIN 1
  180. #define TCSAFLUSH 2
  181. #define EXTA 0000016
  182. #define EXTB 0000017
  183. #define CBAUD 0010017
  184. #define CBAUDEX 0010000
  185. #define CIBAUD 002003600000
  186. #define CMSPAR 010000000000
  187. #define CRTSCTS 020000000000
  188. #define XCASE 0000004
  189. #define ECHOCTL 0001000
  190. #define ECHOPRT 0002000
  191. #define ECHOKE 0004000
  192. #define FLUSHO 0010000
  193. #define PENDIN 0040000
  194. #define EXTPROC 0200000
  195. /* intr=^C quit=^| erase=del kill=^U
  196. eof=^D vtime=\0 vmin=\1 sxtc=\0
  197. start=^Q stop=^S susp=^Z eol=\0
  198. reprint=^R discard=^U werase=^W lnext=^V
  199. eol2=\0
  200. */
  201. #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
  202. speed_t cfgetospeed (const struct termios *);
  203. speed_t cfgetispeed (const struct termios *);
  204. int cfsetospeed (struct termios *, speed_t);
  205. int cfsetispeed (struct termios *, speed_t);
  206. int tcgetattr (int, struct termios *);
  207. int tcsetattr (int, int, const struct termios *);
  208. int tcsendbreak (int, int);
  209. int tcdrain (int);
  210. int tcflush (int, int);
  211. int tcflow (int, int);
  212. pid_t tcgetsid (int);
  213. void cfmakeraw(struct termios *);
  214. int cfsetspeed(struct termios *, speed_t);
  215. #ifdef __cplusplus
  216. }
  217. #endif
  218. #endif