* remote.c (remote_open): Use SERIAL_OPEN instead of serial_open.
(putpkt, getpkt): Use new return codes for SERIAL_READCHAR. * ser-go32.c: Return -1 on most failures, 0 on most successes, and use new return codes for go32_readchar(). * ser-unix.c: Ditto. Also, move error handling up to caller for SERIAL_SETBAUDRATE(). * serial.c (serial_open): Internal call, not SERIAL_OPEN to get to specific routine. (serial_close): New routine to wrap around device close routine. serial.h: Clean & document return values more clearly.
This commit is contained in:
parent
6a42d18472
commit
4febd10272
5 changed files with 65 additions and 39 deletions
|
@ -1,3 +1,16 @@
|
||||||
|
Fri Apr 9 15:01:12 1993 Stu Grossman (grossman@cygnus.com)
|
||||||
|
|
||||||
|
* remote.c (remote_open): Use SERIAL_OPEN instead of serial_open.
|
||||||
|
(putpkt, getpkt): Use new return codes for SERIAL_READCHAR.
|
||||||
|
* ser-go32.c: Return -1 on most failures, 0 on most successes,
|
||||||
|
and use new return codes for go32_readchar().
|
||||||
|
* ser-unix.c: Ditto. Also, move error handling up to caller for
|
||||||
|
SERIAL_SETBAUDRATE().
|
||||||
|
* serial.c (serial_open): Internal call, not SERIAL_OPEN to get
|
||||||
|
to specific routine.
|
||||||
|
(serial_close): New routine to wrap around device close routine.
|
||||||
|
serial.h: Clean & document return values more clearly.
|
||||||
|
|
||||||
Fri Apr 9 10:20:55 1993 Jim Kingdon (kingdon@cygnus.com)
|
Fri Apr 9 10:20:55 1993 Jim Kingdon (kingdon@cygnus.com)
|
||||||
|
|
||||||
* rs6000-pinsn.c (print_operand): Deal with no operand instructions.
|
* rs6000-pinsn.c (print_operand): Deal with no operand instructions.
|
||||||
|
|
|
@ -222,7 +222,7 @@ go32_open (scb, name)
|
||||||
if (strncasecmp (name, "com", 3) != 0)
|
if (strncasecmp (name, "com", 3) != 0)
|
||||||
{
|
{
|
||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
return 1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
port = name[3] - '0';
|
port = name[3] - '0';
|
||||||
|
@ -230,12 +230,12 @@ go32_open (scb, name)
|
||||||
if ((port != 1) && (port != 2))
|
if ((port != 1) && (port != 2))
|
||||||
{
|
{
|
||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
return 1;
|
return -11;
|
||||||
}
|
}
|
||||||
|
|
||||||
scb->fd = dos_async_init(port);
|
scb->fd = dos_async_init(port);
|
||||||
if (!scb->fd)
|
if (!scb->fd)
|
||||||
return 1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -257,7 +257,7 @@ go32_readchar (scb, timeout)
|
||||||
if (dosasync_read(scb->fd, &buf, 1, timeout))
|
if (dosasync_read(scb->fd, &buf, 1, timeout))
|
||||||
return buf;
|
return buf;
|
||||||
else
|
else
|
||||||
return -2; /* Timeout, I guess */
|
return SERIAL_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -275,6 +275,8 @@ go32_write (scb, str, len)
|
||||||
int len;
|
int len;
|
||||||
{
|
{
|
||||||
dosasync_write(scb->fd, str, len);
|
dosasync_write(scb->fd, str, len);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -47,7 +47,7 @@ hardwire_open(scb, name)
|
||||||
{
|
{
|
||||||
scb->fd = open (name, O_RDWR);
|
scb->fd = open (name, O_RDWR);
|
||||||
if (scb->fd < 0)
|
if (scb->fd < 0)
|
||||||
return errno;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -145,17 +145,17 @@ hardwire_readchar(scb, timeout)
|
||||||
|
|
||||||
if (numfds <= 0)
|
if (numfds <= 0)
|
||||||
if (numfds == 0)
|
if (numfds == 0)
|
||||||
return -2; /* Timeout */
|
return SERIAL_TIMEOUT;
|
||||||
else
|
else
|
||||||
return -3; /* Got an error from select */
|
return SERIAL_ERROR; /* Got an error from select */
|
||||||
|
|
||||||
scb->bufcnt = read(scb->fd, scb->buf, BUFSIZ);
|
scb->bufcnt = read(scb->fd, scb->buf, BUFSIZ);
|
||||||
|
|
||||||
if (scb->bufcnt <= 0)
|
if (scb->bufcnt <= 0)
|
||||||
if (scb->bufcnt == 0)
|
if (scb->bufcnt == 0)
|
||||||
return EOF; /* 0 chars means end of file */
|
return SERIAL_EOF; /* 0 chars means end of file */
|
||||||
else
|
else
|
||||||
return -3; /* Got an error from read */
|
return SERIAL_ERROR; /* Got an error from read */
|
||||||
|
|
||||||
scb->bufcnt--;
|
scb->bufcnt--;
|
||||||
scb->bufp = scb->buf;
|
scb->bufp = scb->buf;
|
||||||
|
@ -220,24 +220,20 @@ hardwire_setbaudrate(scb, rate)
|
||||||
struct termios termios;
|
struct termios termios;
|
||||||
|
|
||||||
if (tcgetattr (scb->fd, &termios))
|
if (tcgetattr (scb->fd, &termios))
|
||||||
error("hardwire_setbaudrate: tcgetattr failed: %s\n", safe_strerror(errno));
|
return -1;
|
||||||
|
|
||||||
cfsetospeed (&termios, rate_to_code (rate));
|
cfsetospeed (&termios, rate_to_code (rate));
|
||||||
cfsetispeed (&termios, rate_to_code (rate));
|
cfsetispeed (&termios, rate_to_code (rate));
|
||||||
|
|
||||||
if (tcsetattr (scb->fd, TCSANOW, &termios))
|
if (tcsetattr (scb->fd, TCSANOW, &termios))
|
||||||
error ("hardwire_setbaudrate: tcsetattr failed: %s\n", safe_strerror(errno));
|
return -1;
|
||||||
|
|
||||||
return 1;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_TERMIO
|
#ifdef HAVE_TERMIO
|
||||||
struct termio termio;
|
struct termio termio;
|
||||||
|
|
||||||
if (ioctl (scb->fd, TCGETA, &termio))
|
if (ioctl (scb->fd, TCGETA, &termio))
|
||||||
{
|
return -1;
|
||||||
fprintf(stderr, "TCGETA failed: %s\n", safe_strerror(errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef CIBAUD
|
#ifndef CIBAUD
|
||||||
#define CIBAUD CBAUD
|
#define CIBAUD CBAUD
|
||||||
|
@ -247,23 +243,22 @@ hardwire_setbaudrate(scb, rate)
|
||||||
termio.c_cflag |= rate_to_code (rate);
|
termio.c_cflag |= rate_to_code (rate);
|
||||||
|
|
||||||
if (ioctl (scb->fd, TCSETA, &termio))
|
if (ioctl (scb->fd, TCSETA, &termio))
|
||||||
{
|
return -1;
|
||||||
fprintf(stderr, "TCSETA failed: %s\n", safe_strerror(errno));
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_SGTTY
|
#ifdef HAVE_SGTTY
|
||||||
struct sgttyb sgttyb;
|
struct sgttyb sgttyb;
|
||||||
|
|
||||||
if (ioctl (scb->fd, TIOCGETP, &sgttyb))
|
if (ioctl (scb->fd, TIOCGETP, &sgttyb))
|
||||||
fprintf (stderr, "TIOCGETP failed: %s\n", safe_strerror (errno));
|
return -1;
|
||||||
|
|
||||||
sgttyb.sg_ispeed = rate_to_code (rate);
|
sgttyb.sg_ispeed = rate_to_code (rate);
|
||||||
sgttyb.sg_ospeed = rate_to_code (rate);
|
sgttyb.sg_ospeed = rate_to_code (rate);
|
||||||
|
|
||||||
if (ioctl (scb->fd, TIOCSETP, &sgttyb))
|
if (ioctl (scb->fd, TIOCSETP, &sgttyb))
|
||||||
fprintf (stderr, "TIOCSETP failed: %s\n", safe_strerror (errno));
|
return -1;
|
||||||
#endif
|
#endif
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -299,8 +294,6 @@ hardwire_close(scb)
|
||||||
if (scb->fd < 0)
|
if (scb->fd < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SERIAL_RESTORE(scb);
|
|
||||||
|
|
||||||
close(scb->fd);
|
close(scb->fd);
|
||||||
scb->fd = -1;
|
scb->fd = -1;
|
||||||
}
|
}
|
||||||
|
|
11
gdb/serial.c
11
gdb/serial.c
|
@ -64,7 +64,7 @@ serial_open(name)
|
||||||
scb->bufcnt = 0;
|
scb->bufcnt = 0;
|
||||||
scb->bufp = scb->buf;
|
scb->bufp = scb->buf;
|
||||||
|
|
||||||
if (SERIAL_OPEN (scb, name))
|
if (scb->ops->open(scb, name))
|
||||||
{
|
{
|
||||||
free (scb);
|
free (scb);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -73,6 +73,15 @@ serial_open(name)
|
||||||
return scb;
|
return scb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
serial_close(scb)
|
||||||
|
serial_t scb;
|
||||||
|
{
|
||||||
|
scb->ops->close(scb);
|
||||||
|
|
||||||
|
free(scb);
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* Connect the user directly to the remote system. This command acts just like
|
/* Connect the user directly to the remote system. This command acts just like
|
||||||
the 'cu' or 'tip' command. Use <CR>~. or <CR>~^D to break out. */
|
the 'cu' or 'tip' command. Use <CR>~. or <CR>~^D to break out. */
|
||||||
|
|
39
gdb/serial.h
39
gdb/serial.h
|
@ -49,38 +49,47 @@ struct serial_ops {
|
||||||
|
|
||||||
void serial_add_interface PARAMS ((struct serial_ops *optable));
|
void serial_add_interface PARAMS ((struct serial_ops *optable));
|
||||||
|
|
||||||
/* Try to open the serial device "name", returns a serial_t if ok, NULL if not.
|
|
||||||
*/
|
|
||||||
|
|
||||||
serial_t serial_open PARAMS ((const char *name));
|
serial_t serial_open PARAMS ((const char *name));
|
||||||
|
|
||||||
/* Internal open routine for specific I/O interface */
|
/* For most routines, if a failure is indicated, then errno should be
|
||||||
|
examined. */
|
||||||
|
|
||||||
#define SERIAL_OPEN(SERIAL_T, NAME) (SERIAL_T)->ops->open((SERIAL_T), NAME)
|
/* Try to open NAME. Returns a new serial_t on success, NULL on failure.
|
||||||
|
*/
|
||||||
|
|
||||||
/* Turn the port into raw mode. */
|
#define SERIAL_OPEN(NAME) serial_open(NAME)
|
||||||
|
|
||||||
|
/* Turn the port into raw mode. */
|
||||||
|
|
||||||
#define SERIAL_RAW(SERIAL_T) (SERIAL_T)->ops->go_raw((SERIAL_T))
|
#define SERIAL_RAW(SERIAL_T) (SERIAL_T)->ops->go_raw((SERIAL_T))
|
||||||
|
|
||||||
/* Read one char from the serial device with <TO>-second timeout.
|
/* Read one char from the serial device with TIMEOUT seconds timeout.
|
||||||
Returns char if ok, else EOF, -2 for timeout, -3 for anything else */
|
Returns char if ok, else one of the following codes. Note that all
|
||||||
|
error codes are guaranteed to be < 0. */
|
||||||
|
|
||||||
|
#define SERIAL_ERROR -1 /* General error, see errno for details */
|
||||||
|
#define SERIAL_TIMEOUT -2
|
||||||
|
#define SERIAL_EOF -3
|
||||||
|
|
||||||
#define SERIAL_READCHAR(SERIAL_T, TIMEOUT) ((SERIAL_T)->ops->readchar((SERIAL_T), TIMEOUT))
|
#define SERIAL_READCHAR(SERIAL_T, TIMEOUT) ((SERIAL_T)->ops->readchar((SERIAL_T), TIMEOUT))
|
||||||
|
|
||||||
/* Set the baudrate to the decimal value supplied. Return 1 on failure,
|
/* Set the baudrate to the decimal value supplied. Returns 0 for success,
|
||||||
0 otherwise. */
|
-1 for failure. */
|
||||||
|
|
||||||
#define SERIAL_SETBAUDRATE(SERIAL_T, RATE) ((SERIAL_T)->ops->setbaudrate((SERIAL_T), RATE))
|
#define SERIAL_SETBAUDRATE(SERIAL_T, RATE) ((SERIAL_T)->ops->setbaudrate((SERIAL_T), RATE))
|
||||||
|
|
||||||
/* Write some chars to the device, returns 0 for failure. See errno for
|
/* Write LEN chars from STRING to the port SERIAL_T. Returns 0 for success,
|
||||||
details. */
|
-1 for failure. */
|
||||||
|
|
||||||
#define SERIAL_WRITE(SERIAL_T, STRING, LEN) ((SERIAL_T)->ops->write((SERIAL_T), STRING, LEN))
|
#define SERIAL_WRITE(SERIAL_T, STRING, LEN) ((SERIAL_T)->ops->write((SERIAL_T), STRING, LEN))
|
||||||
|
|
||||||
/* Close the serial port */
|
/* Push out all buffers, close the device and destroy SERIAL_T. */
|
||||||
|
|
||||||
#define SERIAL_CLOSE(SERIAL_T) (SERIAL_T)->ops->close((SERIAL_T))
|
void serial_close PARAMS ((serial_t));
|
||||||
|
|
||||||
/* Restore the serial port to the state saved in oldstate */
|
#define SERIAL_CLOSE(SERIAL_T) serial_close(SERIAL_T)
|
||||||
|
|
||||||
|
/* Restore the serial port to the state saved in oldstate. XXX - currently
|
||||||
|
unused! */
|
||||||
|
|
||||||
#define SERIAL_RESTORE(SERIAL_T) (SERIAL_T)->ops->restore((SERIAL_T))
|
#define SERIAL_RESTORE(SERIAL_T) (SERIAL_T)->ops->restore((SERIAL_T))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue