µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
termios.h
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ distribution.
3 * (https://github.com/micro-os-plus)
4 * Copyright (c) 2018 Liviu Ionescu.
5 *
6 * Copyright (c) 1988, 1989, 1993, 1994
7 * The Regents of the University of California. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)termios.h 8.3 (Berkeley) 3/28/94
34 * $FreeBSD$
35 */
36
37#ifndef POSIX_TERMIOS_H_
38#define POSIX_TERMIOS_H_
39
40// ----------------------------------------------------------------------------
41
42#include <unistd.h>
43
44#if defined(_POSIX_VERSION)
45
46#pragma GCC diagnostic push
47#if defined(__clang__)
48#pragma clang diagnostic ignored "-Wgnu-include-next"
49#endif
50#include_next <termios.h>
51#pragma GCC diagnostic pop
52
53#else
54
55// Avoid warnings for __BSD* definitions.
56#pragma GCC system_header
57
58#ifdef __cplusplus
59extern "C"
60{
61#endif
62
63// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/termios.h.html
64
65// ----------------------------------------------------------------------------
66
67// Special Control Characters
68
69// The following subscript names are for the array c_cc.
70#define VEOF 0 /* ICANON */
71#define VEOL 1 /* ICANON */
72#if __BSD_VISIBLE
73#define VEOL2 2 /* ICANON together with IEXTEN */
74#endif
75#define VERASE 3 /* ICANON */
76#if __BSD_VISIBLE
77#define VWERASE 4 /* ICANON together with IEXTEN */
78#endif
79#define VKILL 5 /* ICANON */
80#if __BSD_VISIBLE
81#define VREPRINT 6 /* ICANON together with IEXTEN */
82#define VERASE2 7 /* ICANON */
83#endif
84// 7 ex-spare 1
85#define VINTR 8 /* ISIG */
86#define VQUIT 9 /* ISIG */
87#define VSUSP 10 /* ISIG */
88#if __BSD_VISIBLE
89#define VDSUSP 11 /* ISIG together with IEXTEN */
90#endif
91#define VSTART 12 /* IXON, IXOFF */
92#define VSTOP 13 /* IXON, IXOFF */
93#if __BSD_VISIBLE
94#define VLNEXT 14 /* IEXTEN */
95#define VDISCARD 15 /* IEXTEN */
96#endif
97#define VMIN 16 /* !ICANON */
98#define VTIME 17 /* !ICANON */
99#if __BSD_VISIBLE
100#define VSTATUS 18 /* ICANON together with IEXTEN */
101// 19 spare 2
102#endif
103
104// [LNP] Added 2017-08-18
105#define VTIME_MS 19 /* !ICANON */
106// [LNP] End added
107
108#define NCCS 20
109
110#define _POSIX_VDISABLE 0xff
111
112// Input Modes
113
114// The c_iflag field describes the basic terminal input control:
115#define IGNBRK 0x00000001 /* ignore BREAK condition */
116#define BRKINT 0x00000002 /* map BREAK to SIGINTR */
117#define IGNPAR 0x00000004 /* ignore (discard) parity errors */
118#define PARMRK 0x00000008 /* mark parity and framing errors */
119#define INPCK 0x00000010 /* enable checking of parity errors */
120#define ISTRIP 0x00000020 /* strip 8th bit off chars */
121#define INLCR 0x00000040 /* map NL into CR */
122#define IGNCR 0x00000080 /* ignore CR */
123#define ICRNL 0x00000100 /* map CR to NL (ala CRMOD) */
124#define IXON 0x00000200 /* enable output flow control */
125#define IXOFF 0x00000400 /* enable input flow control */
126#define IXANY 0x00000800 /* any char will restart after stop */
127#if __BSD_VISIBLE
128#define IMAXBEL 0x00002000 /* ring bell on input queue full */
129#endif
130
131// Output Modes
132
133// The c_oflag field specifies the system treatment of output:
134#define OPOST 0x00000001 /* enable following output processing */
135#define ONLCR 0x00000002 /* map NL to CR-NL (ala CRMOD) */
136#define TABDLY 0x00000004 /* tab delay mask */
137#define TAB0 0x00000000 /* no tab delay and expansion */
138#define TAB3 0x00000004 /* expand tabs to spaces */
139#define ONOEOT 0x00000008 /* discard EOT's (^D) on output) */
140#define OCRNL 0x00000010 /* map CR to NL on output */
141#define ONOCR 0x00000020 /* no CR output at column 0 */
142#define ONLRET 0x00000040 /* NL performs CR function */
143
144// TODO: add
145// OFILL
146// NLDLY
147// CRDLY
148// TABDLY
149// BSDLY
150// VTDLY
151// FFDLY
152
153// Baud Rate Selection
154
155// The input and output baud rates are stored in the termios structure.
156// These are the valid values for objects of type speed_t. The following
157// values shall be defined, but not all baud rates need be supported by
158// the underlying hardware.
159#define B0 0
160#define B50 50
161#define B75 75
162#define B110 110
163#define B134 134
164#define B150 150
165#define B200 200
166#define B300 300
167#define B600 600
168#define B1200 1200
169#define B1800 1800
170#define B2400 2400
171#define B4800 4800
172#define B9600 9600
173#define B19200 19200
174#define B38400 38400
175#if __BSD_VISIBLE
176#define B7200 7200
177#define B14400 14400
178#define B28800 28800
179#define B57600 57600
180#define B76800 76800
181#define B115200 115200
182#define B230400 230400
183#define B460800 460800
184#define B921600 921600
185#define EXTA 19200
186#define EXTB 38400
187#endif
188
189// Control Modes
190
191// The c_cflag field describes the hardware control of the terminal;
192// not all values specified are required to be supported by the
193// underlying hardware.
194#if __BSD_VISIBLE
195#define CIGNORE 0x00000001 /* ignore control flags */
196#endif
197#define CSIZE 0x00000300 /* character size mask */
198#define CS5 0x00000000 /* 5 bits (pseudo) */
199#define CS6 0x00000100 /* 6 bits */
200#define CS7 0x00000200 /* 7 bits */
201#define CS8 0x00000300 /* 8 bits */
202#define CSTOPB 0x00000400 /* send 2 stop bits */
203#define CREAD 0x00000800 /* enable receiver */
204#define PARENB 0x00001000 /* parity enable */
205#define PARODD 0x00002000 /* odd parity, else even */
206#define HUPCL 0x00004000 /* hang up on last close */
207#define CLOCAL 0x00008000 /* ignore modem status lines */
208#if __BSD_VISIBLE
209#define CCTS_OFLOW 0x00010000 /* CTS flow control of output */
210#define CRTSCTS (CCTS_OFLOW | CRTS_IFLOW)
211#define CRTS_IFLOW 0x00020000 /* RTS flow control of input */
212#define CDTR_IFLOW 0x00040000 /* DTR flow control of input */
213#define CDSR_OFLOW 0x00080000 /* DSR flow control of output */
214#define CCAR_OFLOW 0x00100000 /* DCD flow control of output */
215#endif
216
217// Local Modes
218
219// The c_lflag field of the argument structure is used to control
220// various terminal functions.
221// Warning: some flags in this structure begin with the letter "I"
222// and look like they belong in the input flag.
223#if __BSD_VISIBLE
224#define ECHOKE 0x00000001 /* visual erase for line kill */
225#endif
226#define ECHOE 0x00000002 /* visually erase chars */
227#define ECHOK 0x00000004 /* echo NL after line kill */
228#define ECHO 0x00000008 /* enable echoing */
229#define ECHONL 0x00000010 /* echo NL even if ECHO is off */
230#if __BSD_VISIBLE
231#define ECHOPRT 0x00000020 /* visual erase mode for hardcopy */
232#define ECHOCTL 0x00000040 /* echo control chars as ^(Char) */
233#endif
234#define ISIG 0x00000080 /* enable signals INTR, QUIT, [D]SUSP */
235#define ICANON 0x00000100 /* canonicalize input lines */
236#if __BSD_VISIBLE
237#define ALTWERASE 0x00000200 /* use alternate WERASE algorithm */
238#endif
239#define IEXTEN 0x00000400 /* enable DISCARD and LNEXT */
240#define EXTPROC 0x00000800 /* external processing */
241#define TOSTOP 0x00400000 /* stop background jobs from output */
242#if __BSD_VISIBLE
243#define FLUSHO 0x00800000 /* output being flushed (state) */
244#define NOKERNINFO 0x02000000 /* no kernel output from VSTATUS */
245#define PENDIN 0x20000000 /* XXX retype pending input (state) */
246#endif
247#define NOFLSH 0x80000000 /* don't flush after interrupt */
248
249// Attribute Selection
250
251// The following symbolic constants are for use with tcsetattr().
252#define TCSANOW 0 /* make change immediate */
253#define TCSADRAIN 1 /* drain output, then change */
254#define TCSAFLUSH 2 /* drain output, flush input */
255#if __BSD_VISIBLE
256#define TCSASOFT 0x10 /* flag - don't alter h.w. state */
257#endif
258
259// Line Control
260
261// The following symbolic constants are for use with tcflush().
262#define TCIFLUSH 1
263#define TCOFLUSH 2
264#define TCIOFLUSH 3
265
266// The following symbolic constants are for use with tcflow().
267#define TCOOFF 1
268#define TCOON 2
269#define TCIOFF 3
270#define TCION 4
271
272// ----------------------------------------------------------------------------
273
274 typedef unsigned int tcflag_t; // Terminal modes.
275 typedef unsigned char cc_t; // terminal special characters.
276 typedef unsigned int speed_t; // Terminal baud rates.
277
278 struct termios
279 {
280 tcflag_t c_iflag; /* input modes */
281 tcflag_t c_oflag; /* output modes */
282 tcflag_t c_cflag; /* control modes */
283 tcflag_t c_lflag; /* local modes */
284 cc_t c_cc[NCCS]; /* control chars */
285
286 speed_t c_ispeed; /* input speed */
287 speed_t c_ospeed; /* output speed */
288 };
289
290// ----------------------------------------------------------------------------
291
292// Some functions are not yet implemented in µOS++.
293
294// speed_t cfgetispeed(const struct termios *);
295// speed_t cfgetospeed(const struct termios *);
296// int cfsetispeed(struct termios *, speed_t);
297// int cfsetospeed(struct termios *, speed_t);
298
299 int
300 tcdrain (int fildes);
301
302// int tcflow(int, int);
303
304 int
305 tcflush (int fildes, int queue_selector);
306
307 int
308 tcgetattr (int fildes, struct termios *termios_p);
309
310// pid_t tcgetsid(int);
311
312 int
313 tcsendbreak (int fildes, int duration);
314
315 int
316 tcsetattr (int fildes, int optional_actions, const struct termios *termios_p);
317
318// ----------------------------------------------------------------------------
319
320#ifdef __cplusplus
321}
322#endif
323
324#endif /* defined(_POSIX_VERSION) */
325
326#endif /* POSIX_TERMIOS_H_ */
speed_t c_ispeed
Definition termios.h:286
speed_t c_ospeed
Definition termios.h:287
tcflag_t c_cflag
Definition termios.h:282
tcflag_t c_iflag
Definition termios.h:280
tcflag_t c_lflag
Definition termios.h:283
cc_t c_cc[20]
Definition termios.h:284
tcflag_t c_oflag
Definition termios.h:281
unsigned char cc_t
Definition termios.h:275
int tcdrain(int fildes)
int tcsendbreak(int fildes, int duration)
unsigned int speed_t
Definition termios.h:276
#define NCCS
Definition termios.h:108
int tcsetattr(int fildes, int optional_actions, const struct termios *termios_p)
int tcgetattr(int fildes, struct termios *termios_p)
unsigned int tcflag_t
Definition termios.h:274
int tcflush(int fildes, int queue_selector)