Add support for the 8515. Make the addition for other devices easier.

git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@14 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
bsd 2000-12-20 02:26:31 +00:00
parent 2dca69dc00
commit c030e39b3d
2 changed files with 79 additions and 10 deletions

View File

@ -8,7 +8,7 @@ DEST = ${HOME}/bin/0.${ARCH}
all : ${TARGET} all : ${TARGET}
CFLAGS = -Wall --pedantic CFLAGS = -Wall --pedantic -g
${TARGET} : avrprog.c ${TARGET} : avrprog.c
${CC} ${CFLAGS} -o ${TARGET} avrprog.c ${CC} ${CFLAGS} -o ${TARGET} avrprog.c

View File

@ -41,10 +41,12 @@
* Pin 4 -> PB5(MOSI) Instruction input * Pin 4 -> PB5(MOSI) Instruction input
* Pin 5 -> /RESET * Pin 5 -> /RESET
* Pin 10 <- PB6(MISO) Data out * Pin 10 <- PB6(MISO) Data out
* Pin 18 <- GND
* *
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
@ -93,6 +95,21 @@ typedef enum {
} AVRMEM; } AVRMEM;
struct avrpart {
char * partdesc;
char * optiontag;
int flash_size;
int eeprom_size;
};
struct avrpart parts[] = {
{ "AT90S8515", "8515", 8192, 512 },
{ "AT90S2313", "2313", 2048, 128 }
};
/* /*
* variable declarations required for getopt() * variable declarations required for getopt()
*/ */
@ -303,7 +320,7 @@ unsigned char avr_read_byte ( int fd, AVRMEM memtype, unsigned short addr )
break; break;
case AVR_EEPROM: case AVR_EEPROM:
cmd[0] = 0xa0; cmd[0] = 0xa0;
addr &= 0x7f; /* addr &= 0x7f; */
break; break;
default: default:
fprintf(stderr, "%s: avr_read_byte(); internal error: invalid memtype=%d\n", fprintf(stderr, "%s: avr_read_byte(); internal error: invalid memtype=%d\n",
@ -644,6 +661,7 @@ void usage ( void )
" -r : erase the flash and eeprom (required before programming)\n" " -r : erase the flash and eeprom (required before programming)\n"
" -e : select eeprom for reading or writing\n" " -e : select eeprom for reading or writing\n"
" -f : select flash for reading or writing\n" " -f : select flash for reading or writing\n"
" -p Part : 8515 or 2313\n"
" -u InputFile : write data from this file\n" " -u InputFile : write data from this file\n"
" -o OutputFile : write data to this file\n" " -o OutputFile : write data to this file\n"
"\n", "\n",
@ -659,7 +677,7 @@ int main ( int argc, char * argv [] )
int fd; int fd;
int rc, exitrc; int rc, exitrc;
int i; int i;
unsigned char buf[2048]; unsigned char * buf;
unsigned char sig[4]; unsigned char sig[4];
int ch; int ch;
int iofd; int iofd;
@ -668,6 +686,7 @@ int main ( int argc, char * argv [] )
char * outputf; char * outputf;
char * inputf; char * inputf;
char * p1, * p2; char * p1, * p2;
struct avrpart * p;
iofd = -1; iofd = -1;
outputf = NULL; outputf = NULL;
@ -677,6 +696,7 @@ int main ( int argc, char * argv [] )
flash = 0; flash = 0;
erase = 0; erase = 0;
dosig = 0; dosig = 0;
p = NULL;
progname = rindex(argv[0],'/'); progname = rindex(argv[0],'/');
if (progname) if (progname)
@ -706,7 +726,7 @@ int main ( int argc, char * argv [] )
fprintf(stderr, " Revision " ); fprintf(stderr, " Revision " );
for (i=0; i<p2-p1; i++) for (i=0; i<p2-p1; i++)
fprintf(stderr, "%c", p1[i]); fprintf(stderr, "%c", p1[i]);
fprintf(stderr, "\n"); fprintf(stderr, "\n\n");
/* /*
* check for no arguments * check for no arguments
@ -720,7 +740,7 @@ int main ( int argc, char * argv [] )
/* /*
* process command line arguments * process command line arguments
*/ */
while ((ch = getopt(argc,argv,"?efo:rsu:")) != -1) { while ((ch = getopt(argc,argv,"?efo:p:rsu:")) != -1) {
switch (ch) { switch (ch) {
case 'e': /* select eeprom memory */ case 'e': /* select eeprom memory */
if (flash) { if (flash) {
@ -762,6 +782,25 @@ int main ( int argc, char * argv [] )
} }
} }
break; break;
case 'p' : /* specify AVR part */
p = NULL;
for (i=0; i<sizeof(parts)/sizeof(parts[0]); i++) {
if (strcmp(parts[i].optiontag, optarg)==0) {
p = &parts[i];
break;
}
}
if (p == NULL) {
fprintf(stderr, "%s: AVR Part \"%s\" not found. Valid parts are:\n\n",
progname, optarg );
for (i=0; i<sizeof(parts)/sizeof(parts[0]); i++) {
fprintf(stderr, " \"%s\" = %s\n",
parts[i].optiontag, parts[i].partdesc);
}
fprintf(stderr, "\n");
return 1;
}
break;
case 'u': /* specify input (upload) file */ case 'u': /* specify input (upload) file */
if (outputf) { if (outputf) {
fprintf(stderr,"%s: -o and -u are incompatible\n", progname); fprintf(stderr,"%s: -o and -u are incompatible\n", progname);
@ -789,6 +828,37 @@ int main ( int argc, char * argv [] )
} }
if (p == NULL) {
fprintf(stderr,
"%s: No AVR part has been specified, use \"-p Part\"\n\n"
" Valid Parts are:\n\n",
progname );
for (i=0; i<sizeof(parts)/sizeof(parts[0]); i++) {
fprintf(stderr, " \"%s\" = %s\n",
parts[i].optiontag, parts[i].partdesc);
}
fprintf(stderr,"\n");
return 1;
}
fprintf(stderr, "%s: Using AVR Part %s: flash=%d, eeprom=%d\n",
progname, p->partdesc, p->flash_size, p->eeprom_size);
fprintf(stderr, "\n");
if (p->flash_size >= p->eeprom_size)
size = p->flash_size;
else
size = p->eeprom_size;
buf = (unsigned char *) malloc(size);
if (buf == NULL) {
fprintf(stderr,
"%s: out of memory allocating %d bytes for on-chip memory buffer\n",
progname, size);
return 1;
}
/* /*
* open the parallel port * open the parallel port
*/ */
@ -799,7 +869,6 @@ int main ( int argc, char * argv [] )
return 1; return 1;
} }
exitrc = 0; exitrc = 0;
@ -875,7 +944,7 @@ int main ( int argc, char * argv [] )
* read out the specified device memory and write it to a file * read out the specified device memory and write it to a file
*/ */
if (flash) { if (flash) {
size = 2048; size = p->flash_size;
fprintf ( stderr, "%s: reading flash memory:\n", progname ); fprintf ( stderr, "%s: reading flash memory:\n", progname );
rc = avr_read ( fd, AVR_FLASH, 0, size/2, buf, size ); rc = avr_read ( fd, AVR_FLASH, 0, size/2, buf, size );
if (rc) { if (rc) {
@ -886,7 +955,7 @@ int main ( int argc, char * argv [] )
} }
} }
else if (eeprom) { else if (eeprom) {
size = 128; size = p->eeprom_size;
fprintf ( stderr, "%s: reading eeprom memory:\n", progname ); fprintf ( stderr, "%s: reading eeprom memory:\n", progname );
rc = avr_read ( fd, AVR_EEPROM, 0, size, buf, size ); rc = avr_read ( fd, AVR_EEPROM, 0, size, buf, size );
if (rc) { if (rc) {
@ -918,10 +987,10 @@ int main ( int argc, char * argv [] )
* write the selected device memory using data from a file * write the selected device memory using data from a file
*/ */
if (flash) { if (flash) {
size = 2048; size = p->flash_size;
} }
else if (eeprom) { else if (eeprom) {
size = 128; size = p->eeprom_size;
} }
/* /*