From b76fa0fbcdb9245052358e8fbfcd3f1cdc850dad Mon Sep 17 00:00:00 2001 From: "Theodore A. Roth" Date: Fri, 5 Sep 2003 16:40:55 +0000 Subject: [PATCH] * avr.c (avr_read_byte): If pgm->read_byte method fails, retry with avr_read_byte_default. * avr.c (avr_write_byte): If pgm->write_byte method fails, retry with avr_write_byte_default. * avr910.c (avr910_cmd): Implement using universal command. git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@364 81a1dc3b-b13d-400b-aceb-764788c761c2 --- ChangeLog | 9 +++++++++ avr.c | 26 ++++++++++++++++++-------- avr910.c | 20 ++++++++++++++++---- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 58f893e1..31c12878 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2003-09-05 Theodore A. Roth +[Contributed by Jan-Hinnerk Reichert ] + + * avr.c (avr_read_byte): If pgm->read_byte method fails, retry with + avr_read_byte_default. + * avr.c (avr_write_byte): If pgm->write_byte method fails, retry with + avr_write_byte_default. + * avr910.c (avr910_cmd): Implement using universal command. + 2003-09-04 Theodore A. Roth * Makefile.am: Change AM_CPPFLAGS to avrdude_CPPFLAGS. diff --git a/avr.c b/avr.c index 7da25bec..819195ed 100644 --- a/avr.c +++ b/avr.c @@ -343,12 +343,17 @@ int avr_read_byte_default(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, int avr_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, unsigned long addr, unsigned char * value) { + int rc; + if (pgm->read_byte) { - return pgm->read_byte(pgm, p, mem, addr, value); - } - else { - return avr_read_byte_default(pgm, p, mem, addr, value); + rc = pgm->read_byte(pgm, p, mem, addr, value); + if (rc == 0) { + return rc; + } + /* read_byte() method failed, try again with default. */ } + + return avr_read_byte_default(pgm, p, mem, addr, value); } @@ -699,12 +704,17 @@ int avr_write_byte_default(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, int avr_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem, unsigned long addr, unsigned char data) { + int rc; + if (pgm->write_byte) { - return pgm->write_byte(pgm, p, mem, addr, data); - } - else { - return avr_write_byte_default(pgm, p, mem, addr, data); + rc = pgm->write_byte(pgm, p, mem, addr, data); + if (rc == 0) { + return rc; + } + /* write_byte() method failed, try again with default. */ } + + return avr_write_byte_default(pgm, p, mem, addr, data); } diff --git a/avr910.c b/avr910.c index 069c50cb..dd5638f0 100644 --- a/avr910.c +++ b/avr910.c @@ -324,13 +324,25 @@ static void avr910_enable(PROGRAMMER * pgm) static int avr910_cmd(PROGRAMMER * pgm, unsigned char cmd[4], unsigned char res[4]) { - int i; + unsigned char buf[5]; no_show_func_info(); - for (i=0; i<4; i++) { - fprintf(stderr, "cmd[%d] = 0x%02x\n", i, cmd[i]); - } + /* FIXME: Insert version check here */ + + buf[0] = '.'; /* New Universal Command */ + buf[1] = cmd[0]; + buf[2] = cmd[1]; + buf[3] = cmd[2]; + buf[4] = cmd[3]; + + avr910_send (pgm, buf, 5); + avr910_recv (pgm, buf, 2); + + res[0] = 0x00; /* Dummy value */ + res[1] = cmd[0]; + res[2] = cmd[1]; + res[3] = buf[0]; return 0; }