Move erase-rewrite cycle increment to within the chip erase routine so

that it is tracked no matter where the erase was initiated: command
line mode or interactive mode, without code duplicaiton.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@141 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
bsd 2002-08-01 02:06:48 +00:00
parent 0ccee37dc2
commit 11d711787c
3 changed files with 72 additions and 27 deletions

27
avr.c
View File

@ -41,7 +41,6 @@
#include "pindefs.h"
#include "ppi.h"
#define DEBUG 0
extern char * progname;
@ -51,6 +50,8 @@ extern PROGRAMMER * pgm;
char * avr_version = "$Id$";
extern int do_cycles;
AVRPART * avr_new_part(void)
{
@ -821,6 +822,7 @@ int avr_chip_erase(int fd, AVRPART * p)
{
unsigned char cmd[4];
unsigned char res[4];
int cycles;
if (p->op[AVR_OP_CHIP_ERASE] == NULL) {
fprintf(stderr, "chip erase instruction not defined for part \"%s\"\n",
@ -828,6 +830,19 @@ int avr_chip_erase(int fd, AVRPART * p)
return -1;
}
cycles = avr_get_cycle_count(fd, p);
/*
* only print out the current cycle count if we aren't going to
* display it below
*/
if (!do_cycles && ((cycles != -1) && (cycles != 0x00ffff))) {
fprintf(stderr,
"%s: current erase-rewrite cycle count is %d%s\n",
progname, cycles,
do_cycles ? "" : " (if being tracked)");
}
LED_ON(fd, pgm->pinno[PIN_LED_PGM]);
memset(cmd, 0, sizeof(cmd));
@ -839,6 +854,16 @@ int avr_chip_erase(int fd, AVRPART * p)
LED_OFF(fd, pgm->pinno[PIN_LED_PGM]);
if (do_cycles && (cycles != -1)) {
if (cycles == 0x00ffff) {
cycles = 0;
}
cycles++;
fprintf(stderr, "%s: erase-rewrite cycle count is now %d\n",
progname, cycles);
avr_put_cycle_count(fd, p, cycles);
}
return 0;
}

View File

@ -304,7 +304,7 @@ flag is specified to generate a chip erase, the previous counter will
be saved before the chip erase, it is then incremented, and written
back after the erase cycle completes. Presumably, the device would
only be erased just before being programmed, and thus, this can be
utilized to give an indication of how may erase-rewrite cycles the
utilized to give an indication of how many erase-rewrite cycles the
part has undergone. Since the FLASH memory can only endure a finite
number of erase-rewrite cycles, one can use this option to track when
a part is nearing the limit. The typical limit for Atmel AVR FLASH is

70
main.c
View File

@ -128,6 +128,11 @@ PROGRAMMER * pgm = NULL;
PROGRAMMER compiled_in_pgm;
/*
* global options
*/
int do_cycles; /* track erase-rewrite cycles */
/*
* usage message
@ -488,7 +493,6 @@ int main(int argc, char * argv [])
char configfile[PATH_MAX]; /* pin configuration file */
int cycles; /* erase-rewrite cycles */
int set_cycles; /* value to set the erase-rewrite cycles to */
int do_cycles; /* track erase-rewrite cycles */
char * e;
progname = rindex(argv[0],'/');
@ -688,6 +692,7 @@ int main(int argc, char * argv [])
progname, optarg);
exit(1);
}
do_cycles = 1;
break;
case '?': /* help */
@ -853,17 +858,6 @@ int main(int argc, char * argv [])
"%s: AVR device initialized and ready to accept instructions\n",
progname);
/*
* see if the cycle count in the last two bytes of eeprom seems
* reasonable
*/
cycles = avr_get_cycle_count(fd, p);
if ((cycles != -1) && (cycles != 0x00ffff)) {
fprintf(stderr,
"%s: current erase-rewrite cycle count is %d (if being tracked)\n",
progname, cycles);
}
/*
* Let's read the signature bytes to make sure there is at least a
* chip on the other end that is responding correctly. A check
@ -910,28 +904,54 @@ int main(int argc, char * argv [])
}
}
if (set_cycles != -1) {
cycles = avr_get_cycle_count(fd, p);
if (cycles != -1) {
/*
* only attempt to update the cycle counter if we can actually
* read the old value
*/
cycles = set_cycles;
fprintf(stderr, "%s: setting erase-rewrite cycle count to %d\n",
progname, cycles);
rc = avr_put_cycle_count(fd, p, cycles);
if (rc < 0) {
fprintf(stderr,
"%s: WARNING: failed to update the erase-rewrite cycle "
"counter\n",
progname);
}
}
}
if (erase) {
/*
* erase the chip's flash and eeprom memories, this is required
* before the chip can accept new programming
*/
fprintf(stderr, "%s: erasing chip\n", progname);
avr_chip_erase(fd,p);
if (do_cycles && (cycles != -1)) {
if (cycles == 0x00ffff) {
cycles = 0;
}
cycles++;
if (set_cycles != -1) {
cycles = set_cycles;
}
fprintf(stderr, "%s: erase-rewrite cycle count is now %d\n",
progname, cycles);
avr_put_cycle_count(fd, p, cycles);
}
fprintf(stderr, "%s: done.\n", progname);
}
else if (set_cycles == -1) {
/*
* The erase routine displays this same information, so don't
* repeat it if an erase was done. Also, don't display this if we
* set the cycle count (due to -Y).
*
* see if the cycle count in the last two bytes of eeprom seems
* reasonable
*/
cycles = avr_get_cycle_count(fd, p);
if ((cycles != -1) && (cycles != 0x00ffff)) {
fprintf(stderr,
"%s: current erase-rewrite cycle count is %d%s\n",
progname, cycles,
do_cycles ? "" : " (if being tracked)");
}
}
if (!terminal && ((inputf==NULL) && (outputf==NULL))) {
/*