* avr.c (avr_write_byte_default): Improve polling algorithm to speed up

programming of byte oriented parallel programmers.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@380 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
troth 2003-11-19 18:11:59 +00:00
parent a461b38c4a
commit a8b0ee3820
2 changed files with 45 additions and 20 deletions

View File

@ -1,11 +1,16 @@
2003/11/14 Brian S. Dean <bsd@bsdhome.com> 2003-11-19 Theodore A. Roth <troth@openavr.org>
[Contributed by Jan-Hinnerk Reichert <jan-hinnerk_reichert@hamburg.de>]
* avr.c (avr_write_byte_default): Improve polling algorithm to speed up
programming of byte oriented parallel programmers.
2003-11-14 Brian S. Dean <bsd@bsdhome.com>
[Contributed by Erik Christiansen <erik@dd.nec.com.au>]
* avrdude.conf.in: * avrdude.conf.in:
Add ATmega64 part. Add ATmega64 part.
Contributed by Erik Christiansen <erik@dd.nec.com.au> 2003-11-08 Joerg Wunsch <j@uriah.heep.sax.de>
2003/11/08 Joerg Wunsch <j@uriah.heep.sax.de>
* avrdude.conf.in: * avrdude.conf.in:
Add "fuse" and "lock" definitions for the AT90S8535. Actually, Add "fuse" and "lock" definitions for the AT90S8535. Actually,

36
avr.c
View File

@ -25,6 +25,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <sys/time.h>
#include <time.h>
#include "avr.h" #include "avr.h"
@ -521,11 +523,14 @@ int avr_write_byte_default(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
unsigned char r; unsigned char r;
int ready; int ready;
int tries; int tries;
unsigned long start_time;
unsigned long prog_time;
unsigned char b; unsigned char b;
unsigned short caddr; unsigned short caddr;
OPCODE * writeop; OPCODE * writeop;
int rc; int rc;
int readok=0; int readok=0;
struct timeval tv;
if (!mem->paged) { if (!mem->paged) {
/* /*
@ -615,13 +620,6 @@ int avr_write_byte_default(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
tries = 0; tries = 0;
ready = 0; ready = 0;
while (!ready) { while (!ready) {
usleep(mem->min_write_delay);
rc = avr_read_byte(pgm, p, mem, addr, &r);
if (rc != 0) {
pgm->pgm_led(pgm, OFF);
pgm->err_led(pgm, ON);
return -4;
}
if ((data == mem->readback[0]) || if ((data == mem->readback[0]) ||
(data == mem->readback[1])) { (data == mem->readback[1])) {
@ -639,6 +637,29 @@ int avr_write_byte_default(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
return -5; return -5;
} }
} }
else {
gettimeofday (&tv, NULL);
start_time = (tv.tv_sec * 1000000) + tv.tv_usec;
do {
/*
* Do polling, but timeout after max_write_delay.
*/
rc = avr_read_byte(pgm, p, mem, addr, &r);
if (rc != 0) {
pgm->pgm_led(pgm, OFF);
pgm->err_led(pgm, ON);
return -4;
}
gettimeofday (&tv, NULL);
prog_time = (tv.tv_sec * 1000000) + tv.tv_usec;
} while ((r != data) &&
((prog_time-start_time) < mem->max_write_delay));
}
/*
* At this point we either have a valid readback or the
* max_write_delay is expired.
*/
if (r == data) { if (r == data) {
ready = 1; ready = 1;
@ -651,7 +672,6 @@ int avr_write_byte_default(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
* memory bits but not all. We only actually power-off the * memory bits but not all. We only actually power-off the
* device if the data read back does not match what we wrote. * device if the data read back does not match what we wrote.
*/ */
usleep(mem->max_write_delay); /* maximum write delay */
pgm->pgm_led(pgm, OFF); pgm->pgm_led(pgm, OFF);
fprintf(stderr, fprintf(stderr,
"%s: this device must be powered off and back on to continue\n", "%s: this device must be powered off and back on to continue\n",