Debian Codegraph @

src/win32termios.h

raw symbols SCIP
1 /*-------------------------------------------------------------------------
2 | RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface.
3 | RXTX is a native interface to serial ports in java.
4 | Copyright 1997-2008 by Trent Jarvi [email protected] and others who
5 | actually wrote it. See individual source files for more information.
6 |
7 | A copy of the LGPL v 2.1 may be found at
8 | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is
9 | here for your convenience.
10 |
11 | This library is free software; you can redistribute it and/or
12 | modify it under the terms of the GNU Lesser General Public
13 | License as published by the Free Software Foundation; either
14 | version 2.1 of the License, or (at your option) any later version.
15 |
16 | This library is distributed in the hope that it will be useful,
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 | Lesser General Public License for more details.
20 |
21 | An executable that contains no derivative of any portion of RXTX, but
22 | is designed to work with RXTX by being dynamically linked with it,
23 | is considered a "work that uses the Library" subject to the terms and
24 | conditions of the GNU Lesser General Public License.
25 |
26 | The following has been added to the RXTX License to remove
27 | any confusion about linking to RXTX. We want to allow in part what
28 | section 5, paragraph 2 of the LGPL does not permit in the special
29 | case of linking over a controlled interface. The intent is to add a
30 | Java Specification Request or standards body defined interface in the
31 | future as another exception but one is not currently available.
32 |
33 | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface
34 |
35 | As a special exception, the copyright holders of RXTX give you
36 | permission to link RXTX with independent modules that communicate with
37 | RXTX solely through the Sun Microsytems CommAPI interface version 2,
38 | regardless of the license terms of these independent modules, and to copy
39 | and distribute the resulting combined work under terms of your choice,
40 | provided that every copy of the combined work is accompanied by a complete
41 | copy of the source code of RXTX (the version of RXTX used to produce the
42 | combined work), being distributed under the terms of the GNU Lesser General
43 | Public License plus this exception. An independent module is a
44 | module which is not derived from or based on RXTX.
45 |
46 | Note that people who make modified versions of RXTX are not obligated
47 | to grant this special exception for their modified versions; it is
48 | their choice whether to do so. The GNU Lesser General Public License
49 | gives permission to release a modified version without this exception; this
50 | exception also makes it possible to release a modified version which
51 | carries forward this exception.
52 |
53 | You should have received a copy of the GNU Lesser General Public
54 | License along with this library; if not, write to the Free
55 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
56 | All trademarks belong to their respective owners.
57 --------------------------------------------------------------------------*/
58 #ifndef _WIN32S_H_
59 #define _WIN32S_H_
60 #include <windows.h>
61 #include <sys/types.h>
62 #include <io.h>
63 #ifdef TRACE
64 #define ENTER(x) report("entering "x" \n");
65 #define LEAVE(x) report("leaving "x" \n");
66 #else
67 #define ENTER(x)
68 #define LEAVE(x)
69 #endif /* TRACE */
70 #define YACK() \
71 { \
72 char *allocTextBuf, message[80]; \
73 unsigned long nChars; \
74 unsigned int errorCode = GetLastError(); \
75 nChars = FormatMessage ( \
76 FORMAT_MESSAGE_ALLOCATE_BUFFER | \
77 FORMAT_MESSAGE_FROM_SYSTEM, \
78 NULL, \
79 errorCode, \
80 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), \
81 (LPSTR)&allocTextBuf, \
82 16, \
83 NULL ); \
84 sprintf( message, "Error 0x%x at %s(%d): %s\n", errorCode, __FILE__, __LINE__, allocTextBuf); \
85 report_error( message ); \
86 LocalFree(allocTextBuf); \
87 Sleep(1); \
88 }
89
90 typedef unsigned char cc_t;
91 typedef unsigned int speed_t;
92 typedef unsigned int tcflag_t;
93
94 /* structs are from linux includes or linux man pages to match
95 interfaces.
96 */
97
98 struct timespec
99 {
100 time_t tv_sec;
101 long tv_nsec;
102 };
103
104 #define NCCS 32
105 struct termios
106 {
107 tcflag_t c_iflag; /* input mode flags */
108 tcflag_t c_oflag; /* output mode flags */
109 tcflag_t c_cflag; /* control mode flags */
110 tcflag_t c_lflag; /* local mode flags */
111 cc_t c_cc[NCCS]; /* control characters */
112 cc_t c_line; /* line discipline (== c_cc[33]) */
113 speed_t c_ispeed; /* input speed */
114 speed_t c_ospeed; /* output speed */
115 };
116
117 /* for TIOCGSERIAL and TIOCSSERIAL of interest are baud_base and
118 * custom_divisor
119 * --- NOTE: This is not used. Win32 sets custom speeds on the
120 * kernel side.
121 */
122 struct serial_struct {
123 /*
124 Mainly we are after baud_base/custom_diviser to match
125 the ioctl() in SerialImp.c
126 */
127 int custom_divisor; /* use to set unsupported speeds */
128 int baud_base; /* use to set unsupported speeds */
129
130 unsigned short close_delay, closing_wait, iomem_reg_shift;
131 int type, line, irq, flags, xmit_fifo_size, hub6;
132 unsigned int port, port_high;
133 char io_type;
134 unsigned char *iomem_base;
135 };
136 struct serial_icounter_struct {
137 int cts; /* clear to send count */
138 int dsr; /* data set ready count */
139 int rng; /* ring count */
140 int dcd; /* carrier detect count */
141 int rx; /* recieved byte count */
142 int tx; /* transmitted byte count */
143 int frame; /* frame error count */
144 int overrun; /* hardware overrun error count */
145 int parity; /* parity error count */
146 int brk; /* break count */
147 int buf_overrun; /* buffer overrun count */
148 int reserved[9]; /* unused */
149 };
150
151 int serial_test( char * );
152 int serial_open(const char *File, int flags, ... );
153 int serial_close(int fd);
154 int serial_read(int fd, void *b, int size);
155 int serial_write(int fd, char *Str, int length);
156 /*
157 * lcc winsock.h conflicts
158 */
159 #ifndef __LCC__
160 int serial_select(int, struct fd_set *, struct fd_set *, struct fd_set *, struct timeval *);
161 #define select serial_select
162 #endif
163
164 #define OPEN serial_open
165 #define CLOSE serial_close
166 #define READ serial_read
167 #define WRITE serial_write
168
169 void termios_interrupt_event_loop( int , int );
170 void termios_setflags( int , int[] );
171 struct termios_list *find_port( int );
172 /* void usleep(unsigned long usec); */
173 int fcntl(int fd, int command, ...);
174 const char *get_dos_port(const char *);
175 void set_errno(int);
176 char *sterror(int);
177 int B_to_CBR(int);
178 int CBR_to_B(int);
179 int termios_to_bytesize(int);
180 int bytesize_to_termios(int);
181 int tcgetattr(int Fd, struct termios *s_termios);
182 int tcsetattr(int Fd, int when, struct termios *);
183 int serial_close(int );
184 speed_t cfgetospeed(struct termios *s_termios);
185 speed_t cfgetispeed(struct termios *s_termios);
186 int cfsetspeed(struct termios *, speed_t speed);
187 int cfsetospeed(struct termios *, speed_t speed);
188 int cfsetispeed ( struct termios *, speed_t speed);
189 int tcflush ( int , int );
190 int tcgetpgrp ( int );
191 int tcsetpgrp ( int , int );
192 int tcdrain ( int );
193 int tcflow ( int , int );
194 int tcsendbreak ( int , int );
195 int ioctl(int fd, int request, ... );
196 /*
197 int fstat(int fd, ... );
198 */
199 void cfmakeraw(struct termios *s_termios);
200 int termiosGetParityErrorChar( int );
201 void termiosSetParityError( int, char );
202
203 #define O_NOCTTY 0400 /* not for fcntl */
204 #define O_NONBLOCK 00004
205 #define O_NDELAY O_NONBLOCK
206 #define O_SYNC 040000
207 #define O_FSYNC O_SYNC
208 #define O_ASYNC 020000 /* fcntl, for BSD compatibility */
209
210 #define F_DUPFD 0 /* dup */
211 #define F_GETFD 1 /* get f_flags */
212 #define F_SETFD 2 /* set f_flags */
213 #define F_GETFL 3 /* more flags (cloexec) */
214 #define F_SETFL 4
215 #define F_GETLK 7
216 #define F_SETLK 8
217 #define F_SETLKW 9
218
219 #define F_SETOWN 5 /* for sockets. */
220 #define F_GETOWN 6 /* for sockets. */
221
222 /* for F_[GET|SET]FL */
223 #define FD_CLOEXEC 1 /* actually anything with low bit set goes */
224
225 /* for posix fcntl() and lockf() */
226 #define F_RDLCK 1
227 #define F_WRLCK 2
228 #define F_UNLCK 8
229
230 /* for old implementation of bsd flock () */
231 #define F_EXLCK 16 /* or 3 */
232 #define F_SHLCK 32 /* or 4 */
233
234 /* operations for bsd flock(), also used by the kernel implementation */
235 #define LOCK_SH 1 /* shared lock */
236 #define LOCK_EX 2 /* exclusive lock */
237 #define LOCK_NB 4 /* or'd with one of the above to prevent
238 blocking */
239 #define LOCK_UN 8 /* remove lock */
240
241 /* c_cc characters */
242 #define VINTR 0
243 #define VQUIT 1
244 #define VERASE 2
245 #define VKILL 3
246 #define VEOF 4
247 #define VTIME 5
248 #define VMIN 6
249 #define VSWTC 7
250 #define VSTART 8
251 #define VSTOP 9
252 #define VSUSP 10
253 #define VEOL 11
254 #define VREPRINT 12
255 #define VDISCARD 13
256 #define VWERASE 14
257 #define VLNEXT 15
258 #define VEOL2 16
259
260 /* c_iflag bits */
261 #define IGNBRK 0000001
262 #define BRKINT 0000002
263 #define IGNPAR 0000004
264 #define PARMRK 0000010
265 #define INPCK 0000020
266 #define ISTRIP 0000040
267 #define INLCR 0000100
268 #define IGNCR 0000200
269 #define ICRNL 0000400
270 #define IXON 0002000
271 #define IXANY 0004000
272 #define IXOFF 0010000
273 #define IMAXBEL 0020000
274 #define CRTS_IFLOW 0040000
275 #define CCTS_OFLOW 0100000
276 #define CIGNORE 0400000
277 #define CRTSCTS 020000000000 /* flow control */
278 #define HARDWARE_FLOW_CONTROL CRTSCTS
279 #define CRTSXOFF 010000000000
280 /* c_oflag bits */
281 #define OPOST 0000001
282 #define ONLCR 0000002
283 #define OLCUC 0000004
284
285 #define OCRNL 0000010
286 #define ONOCR 0000020
287 #define ONLRET 0000040
288
289 #define OFILL 00000100
290 #define OFDEL 00000200
291 #define NLDLY 00001400
292 #define NL0 00000000
293 #define NL1 00000400
294 #define NL2 00001000
295 #define NL3 00001400
296 #define TABDLY 00006000
297 #define TAB0 00000000
298 #define TAB1 00002000
299 #define TAB2 00004000
300 #define TAB3 00006000
301 #define CRDLY 00030000
302 #define CR0 00000000
303 #define CR1 00010000
304 #define CR2 00020000
305 #define CR3 00030000
306 #define FFDLY 00040000
307 #define FF0 00000000
308 #define FF1 00040000
309 #define BSDLY 00100000
310 #define BS0 00000000
311 #define BS1 00100000
312 #define VTDLY 00200000
313 #define VT0 00000000
314 #define VT1 00200000
315 #define XTABS 01000000 /* Hmm.. Linux/i386 considers this part of TABDLY.. */
316
317 /* c_cflag bit meaning */
318 #define CBAUD 0030017
319 #define B0 0000000 /* hang up */
320 #define B50 0000001
321 #define B75 0000002
322 #define B110 0000003
323 #define B134 0000004
324 #define B150 0000005
325 #define B200 0000006
326 #define B300 0000007
327 #define B600 0000010
328 #define B1200 0000011
329 #define B1800 0000012
330 #define B2400 0000013
331 #define B4800 0000014
332 #define B9600 0000015
333 #define B19200 0000016
334 #define B38400 0000017
335 #define B57600 0010001
336 #define B115200 0010002
337 #define B230400 0010003
338 #define B460800 0010004
339 #define B500000 0010005
340 #define B576000 0010006
341 #define B921600 0010007
342 #define B1000000 0010010
343 #define B1152000 0010011
344 #define B1500000 0010012
345 #define B2000000 0010013
346 #define B2500000 0010014
347 #define B3000000 0010015
348 #define B3500000 0010016
349 #define B4000000 0010017
350
351 /*
352 glue for unsupported linux speeds see also SerialImp.h
353 custom baud rates around 8192-9000 will not work because
354 of these.
355 */
356
357 #define B14400 0020001
358 #define B28800 0020002
359 #define B128000 0020003
360 #define B256000 0020004
361
362 #define EXTA B19200
363 #define EXTB B38400
364 #define CSIZE 0000060
365 #define CS5 0000000
366 #define CS6 0000020
367 #define CS7 0000040
368 #define CS8 0000060
369 #define CSTOPB 0000100
370 #define CREAD 0000200
371 #define PARENB 0000400
372 #define PARODD 0001000
373 #define HUPCL 0002000
374 #define CLOCAL 0004000
375 # define CBAUDEX 0010000
376 # define CIBAUD 002003600000 /* input baud rate (not used) */
377 # define CRTSCTS 020000000000 /* flow control */
378
379 /* c_l flag */
380 #define ISIG 0000001
381 #define ICANON 0000002
382 #define XCASE 0000004
383 #define ECHO 0000010
384 #define ECHOE 0000020
385 #define ECHOK 0000040
386 #define ECHONL 0000100
387 #define NOFLSH 0000200
388 #define TOSTOP 0000400
389 #define ECHOCTL 0001000
390 #define ECHOPRT 0002000
391 #define ECHOKE 0004000
392 #define FLUSHO 0010000
393 #define PENDIN 0040000
394 #define IEXTEN 0100000
395
396 /* glue for unsupported windows speeds */
397
398 #define CBR_28800 28800
399 #define CBR_128000 128000
400 #define CBR_230400 230400
401 #define CBR_256000 256000
402 #define CBR_460800 460800
403 #define CBR_500000 500000
404 #define CBR_576000 576000
405 #define CBR_921600 921600
406 #define CBR_1000000 1000000
407 #define CBR_1152000 1152000
408 #define CBR_1500000 1500000
409 #define CBR_2000000 2000000
410 #define CBR_2500000 2500000
411 #define CBR_3000000 3000000
412 #define CBR_3500000 3500000
413 #define CBR_4000000 4000000
414
415
416 /* Values for the ACTION argument to `tcflow'. */
417 #define TCOOFF 0
418 #define TCOON 1
419 #define TCIOFF 2
420 #define TCION 3
421
422 /* Values for the QUEUE_SELECTOR argument to `tcflush'. */
423 #define TCIFLUSH 0
424 #define TCOFLUSH 1
425 #define TCIOFLUSH 2
426
427 /* Values for the OPTIONAL_ACTIONS argument to `tcsetattr'. */
428 #define TCSANOW 0
429 #define TCSADRAIN 1
430 #define TCSAFLUSH 2
431
432 /* ioctls */
433 #define TIOCSERGETLSR 0x5459
434
435 #endif /*_WIN32S_H_*/
436
437 /* unused ioctls */
438 #define TCSBRK 0x5409
439 #define TIOCOUTQ 0x5411
440 #define TIOCMGET 0x5415
441 #define TIOCMBIS 0x5416
442 #define TIOCMBIC 0x5417
443 #define TIOCMSET 0x5418
444 #define TIOCGSOFTCAR 0x5419
445 #define TIOCSSOFTCAR 0x541a
446 #define TIOCSER_TEMP 0x01
447 /*
448 #define FIONREAD 0x541b
449 TIOC[GS]SERIAL is not used on win32. It was dropped after we could not
450 find a way to get/set buad_base and divisor directly.
451 #define TIOCGSERIAL 0x541e
452 #define TIOCSSERIAL 0x541f
453 */
454 #define TCSBRKP 0x5425
455 #define TIOCSERCONFIG 0x5453
456 #define TIOCSERGWILD 0x5454
457 #define TIOCSERSWILD 0x5455
458 #define TIOCSERGSTRUCT 0x5458
459 #define TIOCSERGETMULTI 0x545a
460 #define TIOCSERSETMULTI 0x545b
461 #define TIOCMIWAIT 0x545c
462 /* this would require being able to get the number of overruns ... */
463 /*
464 FIXME
465 frame and parity errors caused crashes in testing BlackBox
466 */
467 #define TIOCGICOUNT 0x545d
468
469 /* ioctl errors */
470 #define ENOIOCTLCMD 515
471 #define EBADFD 77
472 /* modem lines */
473 #define TIOCM_LE 0x001
474 #define TIOCM_DTR 0x002
475 #define TIOCM_RTS 0x004
476 #define TIOCM_ST 0x008
477 #define TIOCM_SR 0x010
478 #define TIOCM_CTS 0x020
479 #define TIOCM_CAR 0x040
480 #define TIOCM_RNG 0x080
481 #define TIOCM_DSR 0x100
482 #define TIOCM_CD TIOCM_CAR
483 #define TIOCM_RI TIOCM_RNG
484
485
486 #define CMSPAR 010000000000 /* mark or space parity */