* avr.h:
* avr910.c:
* main.c:
* stk500.c:
New progress reporting implementation.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@337 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
Theodore A. Roth 2003-07-29 22:08:21 +00:00
parent 4e704ad695
commit 71536a7097
6 changed files with 148 additions and 46 deletions

View File

@ -1,11 +1,20 @@
2003-07-29 Theodore A. Roth <troth@openavr.org>
* avr.c:
* avr.h:
* avr910.c:
* main.c:
* stk500.c:
New progress reporting implementation.
2003-07-24 Joerg Wunsch <j@uriah.heep.sax.de> 2003-07-24 Joerg Wunsch <j@uriah.heep.sax.de>
* avrdude.1 * avrdude.1:
* doc/avrdude.texi * doc/avrdude.texi:
* pgm.c * pgm.c:
* pgm.h * pgm.h:
* stk500.c * stk500.c:
* stk500_private.h * stk500_private.h:
* term.c: Add support for displaying and setting the various * term.c: Add support for displaying and setting the various
operational parameters of the STK500 (Vtarget, Varef, clock). operational parameters of the STK500 (Vtarget, Varef, clock).

30
avr.c
View File

@ -394,7 +394,6 @@ int avr_read(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size,
unsigned char * buf; unsigned char * buf;
AVRMEM * mem; AVRMEM * mem;
int rc; int rc;
int printed;
mem = avr_locate_mem(p, memtype); mem = avr_locate_mem(p, memtype);
if (mem == NULL) { if (mem == NULL) {
@ -443,8 +442,6 @@ int avr_read(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size,
} }
} }
printed = 0;
for (i=0; i<size; i++) { for (i=0; i<size; i++) {
rc = avr_read_byte(pgm, p, mem, i, &rbyte); rc = avr_read_byte(pgm, p, mem, i, &rbyte);
if (rc != 0) { if (rc != 0) {
@ -456,16 +453,7 @@ int avr_read(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size,
return -2; return -2;
} }
buf[i] = rbyte; buf[i] = rbyte;
if (verbose) { report_progress(i, size, NULL);
if ((i % 16 == 0)||(i == (size-1))) {
printed = 1;
fprintf(stderr, "\r \r%6lu", i);
}
}
}
if (printed) {
fprintf(stderr, "\n");
} }
if (strcasecmp(mem->desc, "flash") == 0) if (strcasecmp(mem->desc, "flash") == 0)
@ -738,7 +726,6 @@ int avr_write(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size,
unsigned char data; unsigned char data;
int werror; int werror;
AVRMEM * m; AVRMEM * m;
int printed;
m = avr_locate_mem(p, memtype); m = avr_locate_mem(p, memtype);
if (m == NULL) { if (m == NULL) {
@ -749,7 +736,6 @@ int avr_write(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size,
pgm->err_led(pgm, OFF); pgm->err_led(pgm, OFF);
printed = 0;
werror = 0; werror = 0;
wsize = m->size; wsize = m->size;
@ -782,12 +768,8 @@ int avr_write(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size,
for (i=0; i<wsize; i++) { for (i=0; i<wsize; i++) {
data = m->buf[i]; data = m->buf[i];
if (verbose) { report_progress(i, wsize, NULL);
if ((i % 16 == 0)||(i == (wsize-1))) {
fprintf(stderr, "\r \r%6lu", i);
printed = 1;
}
}
rc = avr_write_byte(pgm, p, m, i, data); rc = avr_write_byte(pgm, p, m, i, data);
if (rc) { if (rc) {
fprintf(stderr, " ***failed; "); fprintf(stderr, " ***failed; ");
@ -825,10 +807,6 @@ int avr_write(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size,
pgm->err_led(pgm, ON); pgm->err_led(pgm, ON);
} }
} }
if (printed)
fprintf(stderr, "\n");
return i; return i;
} }
@ -841,6 +819,7 @@ int avr_signature(PROGRAMMER * pgm, AVRPART * p)
{ {
int rc; int rc;
report_progress (0,1,"Reading");
rc = avr_read(pgm, p, "signature", 0, 0); rc = avr_read(pgm, p, "signature", 0, 0);
if (rc < 0) { if (rc < 0) {
fprintf(stderr, fprintf(stderr,
@ -848,6 +827,7 @@ int avr_signature(PROGRAMMER * pgm, AVRPART * p)
progname, p->desc, rc); progname, p->desc, rc);
return -1; return -1;
} }
report_progress (1,1,NULL);
return 0; return 0;
} }

2
avr.h
View File

@ -86,4 +86,6 @@ int avr_put_cycle_count(PROGRAMMER * pgm, AVRPART * p, int cycles);;
int avr_mem_hiaddr(AVRMEM * mem); int avr_mem_hiaddr(AVRMEM * mem);
extern void report_progress (int completed, int total, char *hdr);
#endif #endif

View File

@ -535,6 +535,8 @@ static int avr910_paged_write_flash(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
page_addr = addr; page_addr = addr;
page_bytes = page_size; page_bytes = page_size;
} }
report_progress (addr, max_addr, NULL);
} }
/* If we didn't send the page wr cmd after the last byte written in the /* If we didn't send the page wr cmd after the last byte written in the
@ -571,6 +573,8 @@ static int avr910_paged_write_eeprom(PROGRAMMER * pgm, AVRPART * p,
if (has_auto_incr_addr != 'Y') { if (has_auto_incr_addr != 'Y') {
avr910_set_addr(pgm, addr); avr910_set_addr(pgm, addr);
} }
report_progress (addr, max_addr, NULL);
} }
return addr; return addr;
@ -635,6 +639,8 @@ static int avr910_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
if (has_auto_incr_addr != 'Y') { if (has_auto_incr_addr != 'Y') {
avr910_set_addr(pgm, addr); avr910_set_addr(pgm, addr);
} }
report_progress (addr, max_addr, NULL);
} }
return addr * rd_size; return addr * rd_size;

119
main.c
View File

@ -92,6 +92,7 @@ void usage(void)
" -t Enter terminal mode.\n" " -t Enter terminal mode.\n"
" -E <exitspec>[,<exitspec>] List programmer exit specifications.\n" " -E <exitspec>[,<exitspec>] List programmer exit specifications.\n"
" -v Verbose output. -v -v for more.\n" " -v Verbose output. -v -v for more.\n"
" -q Quell progress output.\n"
" -? Display this usage.\n" " -? Display this usage.\n"
"\navrdude project: <URL:http://savannah.nongnu.org/projects/avrdude>\n" "\navrdude project: <URL:http://savannah.nongnu.org/projects/avrdude>\n"
,progname); ,progname);
@ -253,7 +254,104 @@ void list_programmers(FILE * f, char * prefix, LISTID programmers)
return; return;
} }
typedef void (*FP_UpdateProgress)(int percent, char *hdr);
static FP_UpdateProgress update_progress;
/* Report the progress of a read or write operation from/to the device.
The first call of report_progress() should look like this (for a write op):
report_progress (0, 1, "Writing");
Then hdr should be passed NULL on subsequent calls while the operation is
progressing. Once the operation is complete, a final call should be made as
such to ensure proper termination of the progress report:
report_progress (1, 1, NULL);
It would be nice if we could reduce the usage to one and only one call for
each of start, during and end cases. As things stand now, that is not
possible and makes maintenance a bit more work. */
void report_progress (int completed, int total, char *hdr)
{
static int last = 0;
int percent = (completed * 100) / total;
if (update_progress == NULL)
return;
if (hdr) {
last = 0;
update_progress (percent, hdr);
}
if (percent > 100)
percent = 100;
if (percent > last) {
last = percent;
update_progress (percent, hdr);
}
if (percent == 100)
last = 0; /* Get ready for next time. */
}
static void update_progress_tty (int percent, char *hdr)
{
static char hashes[51];
static char *header;
static last = 0;
int i;
hashes[50] = 0;
memset (hashes, ' ', 50);
for (i=0; i<percent; i+=2) {
hashes[i/2] = '#';
}
if (hdr) {
fprintf (stderr, "\n");
last = 0;
header = hdr;
}
if (last == 0) {
fprintf (stderr, "\r%s | %s | %d%%", header, hashes, percent);
}
if (percent == 100) {
last = 1;
fprintf (stderr, "\n\n");
}
}
static void update_progress_no_tty (int percent, char *hdr)
{
static int last = 0;
int cnt = (percent>>1)*2;
if (hdr) {
fprintf (stderr, "\n%s | ", hdr);
last = 0;
}
else {
while (cnt > last) {
fprintf (stderr, "#");
cnt -= 2;
}
}
if ((percent == 100) && (last != 0)) {
fprintf (stderr, " | 100%\n\n");
last = 0;
}
else
last = (percent>>1)*2; /* Make last a multiple of 2. */
}
/* /*
* main routine * main routine
@ -297,6 +395,7 @@ int main(int argc, char * argv [])
int set_cycles; /* value to set the erase-rewrite cycles to */ int set_cycles; /* value to set the erase-rewrite cycles to */
char * e; /* for strtol() error checking */ char * e; /* for strtol() error checking */
char * homedir; char * homedir;
int quell_progress;
progname = rindex(argv[0],'/'); progname = rindex(argv[0],'/');
if (progname) if (progname)
@ -323,6 +422,7 @@ int main(int argc, char * argv [])
filefmt = FMT_AUTO; filefmt = FMT_AUTO;
nowrite = 0; nowrite = 0;
verify = 1; /* on by default */ verify = 1; /* on by default */
quell_progress = 0;
ppisetbits = 0; ppisetbits = 0;
ppiclrbits = 0; ppiclrbits = 0;
exitspecs = NULL; exitspecs = NULL;
@ -375,7 +475,7 @@ int main(int argc, char * argv [])
/* /*
* process command line arguments * process command line arguments
*/ */
while ((ch = getopt(argc,argv,"?c:C:eE:f:Fi:I:m:no:p:P:tvVyY:")) != -1) { while ((ch = getopt(argc,argv,"?c:C:eE:f:Fi:I:m:no:p:P:qtvVyY:")) != -1) {
switch (ch) { switch (ch) {
case 'c': /* programmer id */ case 'c': /* programmer id */
@ -424,6 +524,10 @@ int main(int argc, char * argv [])
partdesc = optarg; partdesc = optarg;
break; break;
case 'q' : /* Quell progress output */
quell_progress = 1;
break;
case 'e': /* perform a chip erase */ case 'e': /* perform a chip erase */
erase = 1; erase = 1;
break; break;
@ -524,6 +628,13 @@ int main(int argc, char * argv [])
} }
if (quell_progress == 0) {
if (isatty (STDERR_FILENO))
update_progress = update_progress_tty;
else
update_progress = update_progress_no_tty;
}
if (verbose) { if (verbose) {
/* /*
* Print out an identifying string so folks can tell what version * Print out an identifying string so folks can tell what version
@ -877,6 +988,7 @@ int main(int argc, char * argv [])
*/ */
fprintf(stderr, "%s: reading %s memory:\n", fprintf(stderr, "%s: reading %s memory:\n",
progname, memtype); progname, memtype);
report_progress(0,1,"Reading");
rc = avr_read(pgm, p, memtype, 0, 1); rc = avr_read(pgm, p, memtype, 0, 1);
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: failed to read all of %s memory, rc=%d\n", fprintf(stderr, "%s: failed to read all of %s memory, rc=%d\n",
@ -884,6 +996,7 @@ int main(int argc, char * argv [])
exitrc = 1; exitrc = 1;
goto main_exit; goto main_exit;
} }
report_progress(1,1,NULL);
size = rc; size = rc;
fprintf(stderr, "%s: writing output file \"%s\"\n", fprintf(stderr, "%s: writing output file \"%s\"\n",
@ -918,7 +1031,9 @@ int main(int argc, char * argv [])
progname, memtype, size); progname, memtype, size);
if (!nowrite) { if (!nowrite) {
report_progress(0,1,"Writing");
rc = avr_write(pgm, p, memtype, size, 1); rc = avr_write(pgm, p, memtype, size, 1);
report_progress(1,1,NULL);
} }
else { else {
/* /*
@ -953,6 +1068,7 @@ int main(int argc, char * argv [])
progname, memtype, inputf); progname, memtype, inputf);
fprintf(stderr, "%s: reading on-chip %s data:\n", fprintf(stderr, "%s: reading on-chip %s data:\n",
progname, memtype); progname, memtype);
report_progress (0,1,"Reading");
rc = avr_read(pgm, v, memtype, vsize, 1); rc = avr_read(pgm, v, memtype, vsize, 1);
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: failed to read all of %s memory, rc=%d\n", fprintf(stderr, "%s: failed to read all of %s memory, rc=%d\n",
@ -961,6 +1077,7 @@ int main(int argc, char * argv [])
exitrc = 1; exitrc = 1;
goto main_exit; goto main_exit;
} }
report_progress (1,1,NULL);
fprintf(stderr, "%s: verifying ...\n", progname); fprintf(stderr, "%s: verifying ...\n", progname);
rc = avr_verify(p, v, memtype, vsize); rc = avr_verify(p, v, memtype, vsize);

View File

@ -741,9 +741,7 @@ static int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
#endif #endif
for (addr = 0; addr < n; addr += page_size) { for (addr = 0; addr < n; addr += page_size) {
if (verbose) { report_progress (addr, n_bytes, NULL);
fprintf(stderr, "\r \r%6u", addr);
}
tries = 0; tries = 0;
retry: retry:
tries++; tries++;
@ -787,10 +785,6 @@ static int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
return -5; return -5;
} }
} }
if (verbose) {
fprintf(stderr, "\r \r%6u", addr-1);
fprintf(stderr, "\n");
}
return n; return n;
} }
@ -835,9 +829,7 @@ static int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
} }
for (addr = 0; addr < n; addr += page_size) { for (addr = 0; addr < n; addr += page_size) {
if (verbose) { report_progress (addr, n_bytes, NULL);
fprintf(stderr, "\r \r%6u", addr);
}
tries = 0; tries = 0;
retry: retry:
tries++; tries++;
@ -878,10 +870,6 @@ static int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
return -5; return -5;
} }
} }
if (verbose) {
fprintf(stderr, "\r \r%6u", addr-1);
fprintf(stderr, "\n");
}
return n; return n;
} }