Implement a way of tracking how many erase-rewrite cycles a part has

undergone.  This utilizes the last two bytes of EEPROM to maintain a
counter that is incremented each time the part is erased.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@138 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
Brian S. Dean
2002-08-01 01:00:03 +00:00
parent 5b12f02975
commit 4d2df35736
5 changed files with 152 additions and 11 deletions

52
main.c
View File

@@ -115,7 +115,7 @@ char ** modules[N_MODULES] = {
&term_version
};
char * version = "2.0.3";
char * version = "2.1.0";
char * main_version = "$Id$";
@@ -486,6 +486,10 @@ int main(int argc, char * argv [])
char * pinconfig; /* programmer id */
char * partdesc; /* part id */
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],'/');
if (progname)
@@ -515,6 +519,8 @@ int main(int argc, char * argv [])
pgm = NULL;
pinconfig = "avrprog"; /* compiled-in default */
verbose = 0;
do_cycles = 0;
set_cycles = -1;
strcpy(configfile, CONFIG_DIR);
i = strlen(configfile);
@@ -561,7 +567,7 @@ int main(int argc, char * argv [])
/*
* process command line arguments
*/
while ((ch = getopt(argc,argv,"?c:C:eE:f:Fi:m:no:p:P:tv")) != -1) {
while ((ch = getopt(argc,argv,"?c:C:eE:f:Fi:m:no:p:P:tvyY:")) != -1) {
switch (ch) {
case 'c': /* pin configuration */
@@ -671,6 +677,19 @@ int main(int argc, char * argv [])
verbose++;
break;
case 'y':
do_cycles = 1;
break;
case 'Y':
set_cycles = strtol(optarg, &e, 0);
if ((e == optarg) || (*e != 0)) {
fprintf(stderr, "%s: invalid cycle count '%s'\n",
progname, optarg);
exit(1);
}
break;
case '?': /* help */
usage();
exit(0);
@@ -834,6 +853,17 @@ 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
@@ -852,7 +882,7 @@ int main(int argc, char * argv [])
fprintf(stderr,
"%s: WARNING: signature data not defined for device \"%s\"\n",
progname, p->desc);
}
}
if (sig != NULL) {
int ff;
@@ -880,19 +910,29 @@ int main(int argc, char * argv [])
}
}
fprintf(stderr, "\n");
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);
}
if (!terminal && ((inputf==NULL) && (outputf==NULL))) {
/*
* Check here to see if any other operations were selected and