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