1 /* Remote serial interface for OS's with termios
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
32 DEFUN_VOID(serial_default_name
)
38 DEFUN_VOID(serial_raw
)
40 /* Now happens inside of serial_open */
43 static struct termios otermios
;
47 DEFUN_VOID(serial_normal
)
49 fcntl(desc
, oflags
, 0);
51 if (tcsetattr(desc
, TCSANOW
, &otermios
))
53 printf("tcgetattr failed: errno=%d\n", errno
);
58 DEFUN(serial_open
,(name
),
61 struct termios termios
;
63 desc
= open (name
, O_RDWR
);
65 perror("Open failed: ");
67 oflags
= fcntl(desc
, F_GETFL
, 0);
69 fcntl(desc
, F_SETFL
, oflags
|FNDELAY
);
71 if (tcgetattr(desc
, &termios
)) {
72 printf("tcgetattr failed: errno=%d\n", errno
);
80 termios
.c_cc
[VMIN
] = 0;
81 termios
.c_cc
[VTIME
] = 0;
83 if (tcsetattr(desc
, TCSANOW
, &termios
)) {
84 printf("tcgetattr failed: errno=%d\n", errno
);
91 DEFUN(serial_timedreadchar
,(timeout
, ok
),
101 FD_SET(desc
, &readfds
);
106 val
= select(desc
+1, &readfds
, 0, 0, &tv
);
108 if (val
> 0 && FD_ISSET(desc
, &readfds
))
110 val
= read (desc
, &buf
, 1);
124 /* Translate baud rates from integers to damn B_codes. Unix should
125 have outgrown this crap years ago, but even POSIX wouldn't buck it. */
134 static struct {int rate
, damn_b
;} baudtab
[] = {
152 for (i
= 0; baudtab
[i
].rate
!= -1; i
++)
154 if (rate
== baudtab
[i
].rate
)
163 DEFUN(serial_setbaudrate
,(rate
),int rate
)
165 struct termios termios
;
167 if (tcgetattr(desc
, &termios
)) {
168 printf("tcgetattr failed: errno=%d\n", errno
);
171 cfsetospeed(&termios
, baudtab
[damn_b(rate
)].damn_b
);
172 cfsetispeed(&termios
, baudtab
[damn_b(rate
)].damn_b
);
174 if (tcsetattr(desc
, TCSANOW
, &termios
)) {
175 printf("tcgetattr failed: errno=%d\n", errno
);
182 DEFUN(serial_nextbaudrate
,(rate
),
186 lookup
= damn_b(rate
);
188 return baudtab
[0].rate
;
190 if (baudtab
[lookup
].rate
== -1)
191 return baudtab
[0].rate
;
192 return baudtab
[lookup
].rate
;
196 DEFUN(serial_write
,(str
, len
),
200 return (write (desc
, str
, len
));
205 DEFUN_VOID(serial_close
)
207 return (close(desc
));
This page took 0.034808 seconds and 4 git commands to generate.