Submitted by Wim Lewis.

Improve error handling.

patch #4923: Better error reporting for serial-bitbang programmers


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@637 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
joerg_wunsch 2006-08-31 22:07:39 +00:00
parent 76e21b8509
commit 00b6640aa1
2 changed files with 52 additions and 11 deletions

View File

@ -1,3 +1,9 @@
2006-09-01 Joerg Wunsch <j@uriah.heep.sax.de>
Submitted by Wim Lewis.
* serbb_posix.c: Improve error handling.
patch #4923: Better error reporting for serial-bitbang programmers
2006-08-31 Joerg Wunsch <j@uriah.heep.sax.de> 2006-08-31 Joerg Wunsch <j@uriah.heep.sax.de>
* avrdude.conf.in: Introduce a "stk500v1" entry, so we * avrdude.conf.in: Introduce a "stk500v1" entry, so we

View File

@ -74,6 +74,7 @@ static char *serpins[DB9PINS + 1] =
static int serbb_setpin(PROGRAMMER * pgm, int pin, int value) static int serbb_setpin(PROGRAMMER * pgm, int pin, int value)
{ {
unsigned int ctl; unsigned int ctl;
int r;
if (pin & PIN_INVERSE) if (pin & PIN_INVERSE)
{ {
@ -91,17 +92,29 @@ static int serbb_setpin(PROGRAMMER * pgm, int pin, int value)
switch ( pin ) switch ( pin )
{ {
case 3: /* txd */ case 3: /* txd */
ioctl(pgm->fd, value ? TIOCSBRK : TIOCCBRK, 0); r = ioctl(pgm->fd, value ? TIOCSBRK : TIOCCBRK, 0);
if (r < 0) {
perror("ioctl(\"TIOCxBRK\")");
return -1;
}
return 0; return 0;
case 4: /* dtr */ case 4: /* dtr */
case 7: /* rts */ case 7: /* rts */
ioctl(pgm->fd, TIOCMGET, &ctl); r = ioctl(pgm->fd, TIOCMGET, &ctl);
if (r < 0) {
perror("ioctl(\"TIOCMGET\")");
return -1;
}
if ( value ) if ( value )
ctl |= serregbits[pin]; ctl |= serregbits[pin];
else else
ctl &= ~(serregbits[pin]); ctl &= ~(serregbits[pin]);
ioctl(pgm->fd, TIOCMSET, &ctl); r = ioctl(pgm->fd, TIOCMSET, &ctl);
if (r < 0) {
perror("ioctl(\"TIOCMSET\")");
return -1;
}
return 0; return 0;
default: /* impossible */ default: /* impossible */
@ -113,6 +126,7 @@ static int serbb_getpin(PROGRAMMER * pgm, int pin)
{ {
unsigned int ctl; unsigned int ctl;
unsigned char invert; unsigned char invert;
int r;
if (pin & PIN_INVERSE) if (pin & PIN_INVERSE)
{ {
@ -133,7 +147,11 @@ static int serbb_getpin(PROGRAMMER * pgm, int pin)
case 6: /* dsr */ case 6: /* dsr */
case 8: /* cts */ case 8: /* cts */
case 9: /* ri */ case 9: /* ri */
ioctl(pgm->fd, TIOCMGET, &ctl); r = ioctl(pgm->fd, TIOCMGET, &ctl);
if (r < 0) {
perror("ioctl(\"TIOCMGET\")");
return -1;
}
if ( !invert ) if ( !invert )
{ {
#ifdef DEBUG #ifdef DEBUG
@ -201,6 +219,7 @@ static int serbb_open(PROGRAMMER *pgm, char *port)
{ {
struct termios mode; struct termios mode;
int flags; int flags;
int r;
bitbang_check_prerequisites(pgm); bitbang_check_prerequisites(pgm);
@ -208,10 +227,17 @@ static int serbb_open(PROGRAMMER *pgm, char *port)
pgm->fd = open(port, O_RDWR | O_NOCTTY | O_NONBLOCK); pgm->fd = open(port, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (pgm->fd < 0) if (pgm->fd < 0) {
perror(port);
return(-1); return(-1);
}
tcgetattr(pgm->fd, &mode); r = tcgetattr(pgm->fd, &mode);
if (r < 0) {
fprintf(stderr, "%s: ", port);
perror("tcgetattr");
return(-1);
}
oldmode = mode; oldmode = mode;
mode.c_iflag = IGNBRK | IGNPAR; mode.c_iflag = IGNBRK | IGNPAR;
@ -220,19 +246,26 @@ static int serbb_open(PROGRAMMER *pgm, char *port)
mode.c_cc [VMIN] = 1; mode.c_cc [VMIN] = 1;
mode.c_cc [VTIME] = 0; mode.c_cc [VTIME] = 0;
tcsetattr(pgm->fd, TCSANOW, &mode); r = tcsetattr(pgm->fd, TCSANOW, &mode);
if (r < 0) {
fprintf(stderr, "%s: ", port);
perror("tcsetattr");
return(-1);
}
/* Clear O_NONBLOCK flag. */ /* Clear O_NONBLOCK flag. */
flags = fcntl(pgm->fd, F_GETFL, 0); flags = fcntl(pgm->fd, F_GETFL, 0);
if (flags == -1) if (flags == -1)
{ {
fprintf(stderr, "%s: Can not get flags\n", progname); fprintf(stderr, "%s: Can not get flags: %s\n",
progname, strerror(errno));
return(-1); return(-1);
} }
flags &= ~O_NONBLOCK; flags &= ~O_NONBLOCK;
if (fcntl(pgm->fd, F_SETFL, flags) == -1) if (fcntl(pgm->fd, F_SETFL, flags) == -1)
{ {
fprintf(stderr, "%s: Can not clear nonblock flag\n", progname); fprintf(stderr, "%s: Can not clear nonblock flag: %s\n",
progname, strerror(errno));
return(-1); return(-1);
} }
@ -241,9 +274,11 @@ static int serbb_open(PROGRAMMER *pgm, char *port)
static void serbb_close(PROGRAMMER *pgm) static void serbb_close(PROGRAMMER *pgm)
{ {
int r;
if (pgm->fd != -1) if (pgm->fd != -1)
{ {
tcsetattr(pgm->fd, TCSANOW, &oldmode); (void)tcsetattr(pgm->fd, TCSANOW, &oldmode);
pgm->setpin(pgm, pgm->pinno[PIN_AVR_RESET], 1); pgm->setpin(pgm, pgm->pinno[PIN_AVR_RESET], 1);
close(pgm->fd); close(pgm->fd);
} }