1 /* Serial interface for local (hardwired) serial ports on Un*x like systems
2 Copyright 1992, 1993 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 #include <sys/types.h>
26 #if !defined (HAVE_TERMIOS) && !defined (HAVE_TERMIO) && !defined (HAVE_SGTTY)
35 #include <sys/termio.h>
41 /* Open up a real live device for serial I/O */
44 hardwire_open(scb
, name
)
48 scb
->fd
= open (name
, O_RDWR
);
60 struct termios termios
;
62 if (tcgetattr(scb
->fd
, &termios
))
64 fprintf(stderr
, "tcgetattr failed: %s\n", safe_strerror(errno
));
70 termios
.c_cflag
&= ~(CSIZE
|PARENB
);
71 termios
.c_cflag
|= CS8
;
72 termios
.c_cc
[VMIN
] = 0;
73 termios
.c_cc
[VTIME
] = 0;
75 if (tcsetattr(scb
->fd
, TCSANOW
, &termios
))
77 fprintf(stderr
, "tcsetattr failed: %s\n", safe_strerror(errno
));
84 if (ioctl (scb
->fd
, TCGETA
, &termio
))
86 fprintf(stderr
, "TCGETA failed: %s\n", safe_strerror(errno
));
92 termio
.c_cflag
&= ~(CSIZE
|PARENB
);
93 termio
.c_cflag
|= CS8
;
94 termio
.c_cc
[VMIN
] = 0;
95 termio
.c_cc
[VTIME
] = 0;
97 if (ioctl (scb
->fd
, TCSETA
, &termio
))
99 fprintf(stderr
, "TCSETA failed: %s\n", safe_strerror(errno
));
104 struct sgttyb sgttyb
;
106 if (ioctl (scb
->fd
, TIOCGETP
, &sgttyb
))
107 fprintf(stderr
, "TIOCGETP failed: %s\n", safe_strerror(errno
));
109 sgttyb
.sg_flags
|= RAW
| ANYP
;
110 sgttyb
.sg_flags
&= ~(CBREAK
| ECHO
);
112 if (ioctl (scb
->fd
, TIOCSETP
, &sgttyb
))
113 fprintf(stderr
, "TIOCSETP failed: %s\n", safe_strerror(errno
));
117 /* Read a character with user-specified timeout. TIMEOUT is number of seconds
118 to wait, or -1 to wait forever. Use timeout of 0 to effect a poll. Returns
119 char if successful. Returns -2 if timeout expired, EOF if line dropped
120 dead, or -3 for any other error (see errno in that case). */
123 hardwire_readchar(scb
, timeout
)
131 if (scb
->bufcnt
-- > 0)
139 FD_SET(scb
->fd
, &readfds
);
142 numfds
= select(scb
->fd
+1, &readfds
, 0, 0, &tv
);
144 numfds
= select(scb
->fd
+1, &readfds
, 0, 0, 0);
148 return -2; /* Timeout */
150 return -3; /* Got an error from select */
152 scb
->bufcnt
= read(scb
->fd
, scb
->buf
, BUFSIZ
);
154 if (scb
->bufcnt
<= 0)
155 if (scb
->bufcnt
== 0)
156 return EOF
; /* 0 chars means end of file */
158 return -3; /* Got an error from read */
161 scb
->bufp
= scb
->buf
;
173 /* Translate baud rates from integers to damn B_codes. Unix should
174 have outgrown this crap years ago, but even POSIX wouldn't buck it. */
207 for (i
= 0; baudtab
[i
].rate
!= -1; i
++)
208 if (rate
== baudtab
[i
].rate
)
209 return baudtab
[i
].code
;
215 hardwire_setbaudrate(scb
, rate
)
220 struct termios termios
;
222 if (tcgetattr (scb
->fd
, &termios
))
223 error("hardwire_setbaudrate: tcgetattr failed: %s\n", safe_strerror(errno
));
225 cfsetospeed (&termios
, rate_to_code (rate
));
226 cfsetispeed (&termios
, rate_to_code (rate
));
228 if (tcsetattr (scb
->fd
, TCSANOW
, &termios
))
229 error ("hardwire_setbaudrate: tcsetattr failed: %s\n", safe_strerror(errno
));
235 struct termio termio
;
237 if (ioctl (scb
->fd
, TCGETA
, &termio
))
239 fprintf(stderr
, "TCGETA failed: %s\n", safe_strerror(errno
));
246 termio
.c_cflag
&= ~(CBAUD
| CIBAUD
);
247 termio
.c_cflag
|= rate_to_code (rate
);
249 if (ioctl (scb
->fd
, TCSETA
, &termio
))
251 fprintf(stderr
, "TCSETA failed: %s\n", safe_strerror(errno
));
256 struct sgttyb sgttyb
;
258 if (ioctl (scb
->fd
, TIOCGETP
, &sgttyb
))
259 fprintf (stderr
, "TIOCGETP failed: %s\n", safe_strerror (errno
));
261 sgttyb
.sg_ispeed
= rate_to_code (rate
);
262 sgttyb
.sg_ospeed
= rate_to_code (rate
);
264 if (ioctl (scb
->fd
, TIOCSETP
, &sgttyb
))
265 fprintf (stderr
, "TIOCSETP failed: %s\n", safe_strerror (errno
));
270 hardwire_write(scb
, str
, len
)
279 cc
= write(scb
->fd
, str
, len
);
290 hardwire_restore(scb
)
308 static struct serial_ops hardwire_ops
=
321 _initialize_ser_hardwire ()
323 serial_add_interface (&hardwire_ops
);
This page took 0.067094 seconds and 5 git commands to generate.