2003-07-29 Theodore A. Roth
* ChangeLog:
* avr.c:
* avr.h:
* avr910.c:
* main.c:
* stk500.c:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/avrdude/avrdude/ChangeLog,v
retrieving revision 1.38
diff -u -r1.38 ChangeLog
--- ChangeLog 24 Jul 2003 21:26:28 -0000 1.38
+++ ChangeLog 29 Jul 2003 22:02:46 -0000
@@ -1,11 +1,19 @@
+2003-07-29 Theodore A. Roth
+
+ * avr.c:
+ * avr.h:
+ * main.c:
+ * stk500.c:
+ New progress reporting implementation.
+
2003-07-24 Joerg Wunsch
- * avrdude.1
- * doc/avrdude.texi
- * pgm.c
- * pgm.h
- * stk500.c
- * stk500_private.h
+ * avrdude.1:
+ * doc/avrdude.texi:
+ * pgm.c:
+ * pgm.h:
+ * stk500.c:
+ * stk500_private.h:
* term.c: Add support for displaying and setting the various
operational parameters of the STK500 (Vtarget, Varef, clock).
Index: avr.c
===================================================================
RCS file: /cvsroot/avrdude/avrdude/avr.c,v
retrieving revision 1.56
diff -u -r1.56 avr.c
--- avr.c 22 May 2003 02:33:17 -0000 1.56
+++ avr.c 29 Jul 2003 22:02:48 -0000
@@ -394,7 +394,6 @@
unsigned char * buf;
AVRMEM * mem;
int rc;
- int printed;
mem = avr_locate_mem(p, memtype);
if (mem == NULL) {
@@ -443,8 +442,6 @@
}
}
- printed = 0;
-
for (i=0; idesc, "flash") == 0)
@@ -738,7 +726,6 @@
unsigned char data;
int werror;
AVRMEM * m;
- int printed;
m = avr_locate_mem(p, memtype);
if (m == NULL) {
@@ -749,7 +736,6 @@
pgm->err_led(pgm, OFF);
- printed = 0;
werror = 0;
wsize = m->size;
@@ -782,12 +768,8 @@
for (i=0; ibuf[i];
- if (verbose) {
- if ((i % 16 == 0)||(i == (wsize-1))) {
- fprintf(stderr, "\r \r%6lu", i);
- printed = 1;
- }
- }
+ report_progress(i, wsize, NULL);
+
rc = avr_write_byte(pgm, p, m, i, data);
if (rc) {
fprintf(stderr, " ***failed; ");
@@ -825,10 +807,6 @@
pgm->err_led(pgm, ON);
}
}
-
- if (printed)
- fprintf(stderr, "\n");
-
return i;
}
@@ -841,6 +819,7 @@
{
int rc;
+ report_progress (0,1,"Reading");
rc = avr_read(pgm, p, "signature", 0, 0);
if (rc < 0) {
fprintf(stderr,
@@ -848,6 +827,7 @@
progname, p->desc, rc);
return -1;
}
+ report_progress (1,1,NULL);
return 0;
}
Index: avr.h
===================================================================
RCS file: /cvsroot/avrdude/avrdude/avr.h,v
retrieving revision 1.26
diff -u -r1.26 avr.h
--- avr.h 22 May 2003 02:33:17 -0000 1.26
+++ avr.h 29 Jul 2003 22:02:48 -0000
@@ -86,4 +86,6 @@
int avr_mem_hiaddr(AVRMEM * mem);
+extern void report_progress (int completed, int total, char *hdr);
+
#endif
Index: avr910.c
===================================================================
RCS file: /cvsroot/avrdude/avrdude/avr910.c,v
retrieving revision 1.8
diff -u -r1.8 avr910.c
--- avr910.c 14 May 2003 05:14:32 -0000 1.8
+++ avr910.c 29 Jul 2003 22:02:48 -0000
@@ -535,6 +535,8 @@
page_addr = addr;
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
@@ -571,6 +573,8 @@
if (has_auto_incr_addr != 'Y') {
avr910_set_addr(pgm, addr);
}
+
+ report_progress (addr, max_addr, NULL);
}
return addr;
@@ -635,6 +639,8 @@
if (has_auto_incr_addr != 'Y') {
avr910_set_addr(pgm, addr);
}
+
+ report_progress (addr, max_addr, NULL);
}
return addr * rd_size;
Index: main.c
===================================================================
RCS file: /cvsroot/avrdude/avrdude/main.c,v
retrieving revision 1.76
diff -u -r1.76 main.c
--- main.c 7 May 2003 22:13:46 -0000 1.76
+++ main.c 29 Jul 2003 22:02:51 -0000
@@ -92,6 +92,7 @@
" -t Enter terminal mode.\n"
" -E [,] List programmer exit specifications.\n"
" -v Verbose output. -v -v for more.\n"
+ " -q Quell progress output.\n"
" -? Display this usage.\n"
"\navrdude project: \n"
,progname);
@@ -253,7 +254,104 @@
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>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
@@ -297,6 +395,7 @@
int set_cycles; /* value to set the erase-rewrite cycles to */
char * e; /* for strtol() error checking */
char * homedir;
+ int quell_progress;
progname = rindex(argv[0],'/');
if (progname)
@@ -323,6 +422,7 @@
filefmt = FMT_AUTO;
nowrite = 0;
verify = 1; /* on by default */
+ quell_progress = 0;
ppisetbits = 0;
ppiclrbits = 0;
exitspecs = NULL;
@@ -375,7 +475,7 @@
/*
* 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) {
case 'c': /* programmer id */
@@ -424,6 +524,10 @@
partdesc = optarg;
break;
+ case 'q' : /* Quell progress output */
+ quell_progress = 1;
+ break;
+
case 'e': /* perform a chip erase */
erase = 1;
break;
@@ -524,6 +628,13 @@
}
+ if (quell_progress == 0) {
+ if (isatty (STDERR_FILENO))
+ update_progress = update_progress_tty;
+ else
+ update_progress = update_progress_no_tty;
+ }
+
if (verbose) {
/*
* Print out an identifying string so folks can tell what version
@@ -877,6 +988,7 @@
*/
fprintf(stderr, "%s: reading %s memory:\n",
progname, memtype);
+ report_progress(0,1,"Reading");
rc = avr_read(pgm, p, memtype, 0, 1);
if (rc < 0) {
fprintf(stderr, "%s: failed to read all of %s memory, rc=%d\n",
@@ -884,6 +996,7 @@
exitrc = 1;
goto main_exit;
}
+ report_progress(1,1,NULL);
size = rc;
fprintf(stderr, "%s: writing output file \"%s\"\n",
@@ -918,7 +1031,9 @@
progname, memtype, size);
if (!nowrite) {
+ report_progress(0,1,"Writing");
rc = avr_write(pgm, p, memtype, size, 1);
+ report_progress(1,1,NULL);
}
else {
/*
@@ -953,6 +1068,7 @@
progname, memtype, inputf);
fprintf(stderr, "%s: reading on-chip %s data:\n",
progname, memtype);
+ report_progress (0,1,"Reading");
rc = avr_read(pgm, v, memtype, vsize, 1);
if (rc < 0) {
fprintf(stderr, "%s: failed to read all of %s memory, rc=%d\n",
@@ -961,6 +1077,7 @@
exitrc = 1;
goto main_exit;
}
+ report_progress (1,1,NULL);
fprintf(stderr, "%s: verifying ...\n", progname);
rc = avr_verify(p, v, memtype, vsize);
Index: stk500.c
===================================================================
RCS file: /cvsroot/avrdude/avrdude/stk500.c,v
retrieving revision 1.33
diff -u -r1.33 stk500.c
--- stk500.c 24 Jul 2003 21:26:28 -0000 1.33
+++ stk500.c 29 Jul 2003 22:03:00 -0000
@@ -741,9 +741,7 @@
#endif
for (addr = 0; addr < n; addr += page_size) {
- if (verbose) {
- fprintf(stderr, "\r \r%6u", addr);
- }
+ report_progress (addr, n_bytes, NULL);
tries = 0;
retry:
tries++;
@@ -787,10 +785,6 @@
return -5;
}
}
- if (verbose) {
- fprintf(stderr, "\r \r%6u", addr-1);
- fprintf(stderr, "\n");
- }
return n;
}
@@ -835,9 +829,7 @@
}
for (addr = 0; addr < n; addr += page_size) {
- if (verbose) {
- fprintf(stderr, "\r \r%6u", addr);
- }
+ report_progress (addr, n_bytes, NULL);
tries = 0;
retry:
tries++;
@@ -877,10 +869,6 @@
progname, Resp_STK_INSYNC, buf[0]);
return -5;
}
- }
- if (verbose) {
- fprintf(stderr, "\r \r%6u", addr-1);
- fprintf(stderr, "\n");
}
return n;