diff --git a/avrdude/avrprog.c b/avrdude/avrprog.c index c5dc6e22..59a134db 100644 --- a/avrdude/avrprog.c +++ b/avrdude/avrprog.c @@ -55,7 +55,6 @@ #include #include #include -#include #define PARALLEL "/dev/ppi0" @@ -105,21 +104,11 @@ struct avrpart { struct avrpart parts[] = { { "AT90S8515", "8515", 8192, 512 }, - { "AT90S2313", "2313", 2048, 128 } + { "AT90S2313", "2313", 2048, 128 }, + { "AT90S1200", "1200", 1200, 64 } }; - -/* - * variable declarations required for getopt() - */ -char *optarg; -int optind; -int optopt; -int opterr; -int optreset; - - /* * set 'get' and 'set' appropriately for subsequent passage to ioctl() * to get/set the specified PPI registers. @@ -250,18 +239,24 @@ int ppi_pulse ( int fd, int reg, int bit ) */ int avr_txrx_bit ( int fd, int bit ) { - unsigned char d; int r; - ioctl(fd, PPIGDATA, &d); - + /* + * read the result bit (it is either valid from a previous clock + * pulse or it is ignored in the current context) + */ r = ppi_get(fd, PPISTATUS, AVR_DATA); + /* set the data input line as desired */ if (bit) ppi_set(fd, PPIDATA, AVR_INSTR); else ppi_clr(fd, PPIDATA, AVR_INSTR); + /* + * pulse the clock line, clocking in the MOSI data, and clocking out + * the next result bit + */ ppi_pulse(fd, PPIDATA, AVR_CLOCK); return r; @@ -586,7 +581,7 @@ void avr_powerdown ( int fd ) /* * initialize the AVR device and prepare it to accept commands */ -int avr_initialize ( int fd ) +int avr_initialize ( int fd, struct avrpart * p ) { int rc; int tries; @@ -600,24 +595,33 @@ int avr_initialize ( int fd ) usleep(20000); /* 20 ms */ /* - * enable programming mode, try up to 32 times in order to possibly - * get back into sync with the chip if we are out of sync. + * Enable programming mode. If we are programming an AT90S1200, we + * can only issue the command and hope it worked. If we are using + * one of the other chips, the chip will echo 0x53 when issuing the + * third byte of the command. In this case, try up to 32 times in + * order to possibly get back into sync with the chip if we are out + * of sync. */ - tries = 0; - do { - rc = avr_program_enable ( fd ); - if (rc == 0) - break; - ppi_pulse(fd, PPIDATA, AVR_CLOCK); - tries++; - } while (tries < 32); + if (strcmp(p->partdesc, "AT90S1200")==0) { + avr_program_enable ( fd ); + } + else { + tries = 0; + do { + rc = avr_program_enable ( fd ); + if (rc == 0) + break; + ppi_pulse(fd, PPIDATA, AVR_CLOCK); + tries++; + } while (tries < 32); - /* - * can't sync with the device, maybe it's not attached? - */ - if (tries == 32) { - fprintf ( stderr, "%s: AVR device not responding\n", progname ); - return -1; + /* + * can't sync with the device, maybe it's not attached? + */ + if (tries == 32) { + fprintf ( stderr, "%s: AVR device not responding\n", progname ); + return -1; + } } return 0; @@ -654,6 +658,8 @@ int ppi_sense_test ( int fd ) */ void usage ( void ) { + int i; + fprintf ( stderr, "\nUsage: %s [-r] [-e|-f] [-u InputFile|-o Outputfile]\n" "\n" @@ -661,11 +667,21 @@ void usage ( void ) " -r : erase the flash and eeprom (required before programming)\n" " -e : select eeprom for reading or writing\n" " -f : select flash for reading or writing\n" - " -p Part : 8515 or 2313\n" + " -p Part : see below for valid parts\n" " -u InputFile : write data from this file\n" " -o OutputFile : write data to this file\n" + " -F : override invalid device signature check\n" + " -s : read device signature bytes\n" "\n", progname ); + + fprintf(stderr, " Valid Parts for the -p option are:\n"); + for (i=0; i