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