1 /* Remote serial interface for OS's with termios, for GDB.
2 Copyright 1992 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. */
26 /* File descriptor used in termios routines to access serial line. */
29 /* Saved state about the terminal. */
30 static struct termios otermios
;
34 serial_default_name ()
42 /* Now happens inside of serial_open */
48 fcntl(desc
, oflags
, 0);
50 if (tcsetattr(desc
, TCSANOW
, &otermios
))
52 printf("tcgetattr failed: errno=%d\n", errno
);
60 struct termios termios
;
62 desc
= open (name
, O_RDWR
);
64 perror("Open failed: ");
66 oflags
= fcntl(desc
, F_GETFL
, 0);
68 fcntl(desc
, F_SETFL
, oflags
|FNDELAY
);
70 if (tcgetattr(desc
, &termios
)) {
71 printf("tcgetattr failed: errno=%d\n", errno
);
79 termios
.c_cc
[VMIN
] = 0;
80 termios
.c_cc
[VTIME
] = 0;
82 if (tcsetattr(desc
, TCSANOW
, &termios
)) {
83 printf("tcgetattr failed: errno=%d\n", errno
);
90 serial_timedreadchar (timeout
, ok
)
100 FD_SET(desc
, &readfds
);
105 val
= select(desc
+1, &readfds
, 0, 0, &tv
);
107 if (val
> 0 && FD_ISSET(desc
, &readfds
))
109 val
= read (desc
, &buf
, 1);
123 /* Translate baud rates from integers to damn B_codes. Unix should
124 have outgrown this crap years ago, but even POSIX wouldn't buck it. */
133 static struct {int rate
, damn_b
;} baudtab
[] = {
152 for (i
= 0; baudtab
[i
].rate
!= -1; i
++)
154 if (rate
== baudtab
[i
].rate
)
163 serial_setbaudrate (rate
)
166 struct termios termios
;
168 if (tcgetattr(desc
, &termios
)) {
169 printf("tcgetattr failed: errno=%d\n", errno
);
172 cfsetospeed(&termios
, baudtab
[damn_b(rate
)].damn_b
);
173 cfsetispeed(&termios
, baudtab
[damn_b(rate
)].damn_b
);
175 if (tcsetattr(desc
, TCSANOW
, &termios
)) {
176 printf("tcgetattr failed: errno=%d\n", errno
);
183 serial_nextbaudrate (rate
)
187 lookup
= damn_b(rate
);
189 return baudtab
[0].rate
;
191 if (baudtab
[lookup
].rate
== -1)
192 return baudtab
[0].rate
;
193 return baudtab
[lookup
].rate
;
197 serial_write (str
, len
)
201 return (write (desc
, str
, len
));
208 return (close(desc
));
This page took 0.03474 seconds and 5 git commands to generate.