Add ppi_pulse() function and fix ppi_toggle() to actully toggle

instead of pulse.

Make all abnormal returns after the parallel port has been opened go
through a single exit point at the bottom of 'main()'.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@9 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
bsd 2000-08-07 01:48:53 +00:00
parent 18c89843e6
commit 8372ead3de
1 changed files with 41 additions and 45 deletions

View File

@ -209,11 +209,20 @@ int ppi_toggle ( int fd, int reg, int bit )
return -1; return -1;
ioctl(fd, get, &v); ioctl(fd, get, &v);
v |= bit; v ^= bit;
ioctl(fd, set, &v); ioctl(fd, set, &v);
v &= ~bit; return 0;
ioctl(fd, set, &v); }
/*
* pulse the indicated bit of the specified register.
*/
int ppi_pulse ( int fd, int reg, int bit )
{
ppi_toggle(fd, reg, bit);
ppi_toggle(fd, reg, bit);
return 0; return 0;
} }
@ -236,7 +245,7 @@ int avr_txrx_bit ( int fd, int bit )
else else
ppi_clr(fd, PPIDATA, AVR_INSTR); ppi_clr(fd, PPIDATA, AVR_INSTR);
ppi_toggle(fd, PPIDATA, AVR_CLOCK); ppi_pulse(fd, PPIDATA, AVR_CLOCK);
return r; return r;
} }
@ -569,7 +578,7 @@ int avr_initialize ( int fd )
ppi_clr(fd, PPIDATA, AVR_CLOCK); ppi_clr(fd, PPIDATA, AVR_CLOCK);
ppi_clr(fd, PPIDATA, AVR_RESET); ppi_clr(fd, PPIDATA, AVR_RESET);
ppi_toggle(fd, PPIDATA, AVR_RESET); ppi_pulse(fd, PPIDATA, AVR_RESET);
usleep(20000); /* 20 ms */ usleep(20000); /* 20 ms */
@ -582,7 +591,7 @@ int avr_initialize ( int fd )
rc = avr_program_enable ( fd ); rc = avr_program_enable ( fd );
if (rc == 0) if (rc == 0)
break; break;
ppi_toggle(fd, PPIDATA, AVR_CLOCK); ppi_pulse(fd, PPIDATA, AVR_CLOCK);
tries++; tries++;
} while (tries < 32); } while (tries < 32);
@ -648,7 +657,7 @@ void usage ( void )
int main ( int argc, char * argv [] ) int main ( int argc, char * argv [] )
{ {
int fd; int fd;
int rc; int rc, exitrc;
int i; int i;
unsigned char buf[2048]; unsigned char buf[2048];
unsigned char sig[4]; unsigned char sig[4];
@ -801,8 +810,8 @@ int main ( int argc, char * argv [] )
rc = avr_initialize(fd); rc = avr_initialize(fd);
if (rc < 0) { if (rc < 0) {
fprintf ( stderr, "%s: initialization failed, rc=%d\n", progname, rc ); fprintf ( stderr, "%s: initialization failed, rc=%d\n", progname, rc );
avr_powerdown(fd); exitrc = 1;
return 1; goto main_exit;
} }
fprintf ( stderr, "%s: AVR device initialized and ready to accept instructions\n", fprintf ( stderr, "%s: AVR device initialized and ready to accept instructions\n",
@ -844,9 +853,8 @@ int main ( int argc, char * argv [] )
fprintf(stderr, "%s: you must specify an input or an output file\n", fprintf(stderr, "%s: you must specify an input or an output file\n",
progname); progname);
} }
avr_powerdown(fd); exitrc = 1;
close(fd); goto main_exit;
return 1;
} }
@ -858,10 +866,8 @@ int main ( int argc, char * argv [] )
fprintf(stderr, fprintf(stderr,
"%s: please specify either the eeprom (-e) or the flash (-f) memory\n", "%s: please specify either the eeprom (-e) or the flash (-f) memory\n",
progname); progname);
avr_powerdown(fd); exitrc = 1;
close(fd); goto main_exit;
close(iofd);
return 1;
} }
@ -876,10 +882,8 @@ int main ( int argc, char * argv [] )
if (rc) { if (rc) {
fprintf ( stderr, "%s: failed to read all of flash memory, rc=%d\n", fprintf ( stderr, "%s: failed to read all of flash memory, rc=%d\n",
progname, rc ); progname, rc );
avr_powerdown(fd); exitrc = 1;
close(fd); goto main_exit;
close(iofd);
return 1;
} }
} }
else if (eeprom) { else if (eeprom) {
@ -889,10 +893,8 @@ int main ( int argc, char * argv [] )
if (rc) { if (rc) {
fprintf ( stderr, "%s: failed to read all of eeprom memory, rc=%d\n", fprintf ( stderr, "%s: failed to read all of eeprom memory, rc=%d\n",
progname, rc ); progname, rc );
avr_powerdown(fd); exitrc = 1;
close(fd); goto main_exit;
close(iofd);
return 1;
} }
} }
@ -902,18 +904,14 @@ int main ( int argc, char * argv [] )
rc = write ( iofd, buf, size ); rc = write ( iofd, buf, size );
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: write error: %s\n", progname, strerror(errno)); fprintf(stderr, "%s: write error: %s\n", progname, strerror(errno));
avr_powerdown(fd); exitrc = 1;
close(fd); goto main_exit;
close(iofd);
return 1;
} }
else if (rc != size) { else if (rc != size) {
fprintf(stderr, "%s: wrote only %d bytes of the expected %d\n", fprintf(stderr, "%s: wrote only %d bytes of the expected %d\n",
progname, rc, size); progname, rc, size);
avr_powerdown(fd); exitrc = 1;
close(fd); goto main_exit;
close(iofd);
return 1;
} }
} }
else { else {
@ -934,10 +932,8 @@ int main ( int argc, char * argv [] )
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: read error from \"%s\": %s\n", fprintf(stderr, "%s: read error from \"%s\": %s\n",
progname, inputf, strerror(errno)); progname, inputf, strerror(errno));
avr_powerdown(fd); exitrc = 1;
close(fd); goto main_exit;
close(iofd);
return 1;
} }
size = rc; size = rc;
@ -952,10 +948,8 @@ int main ( int argc, char * argv [] )
if (rc) { if (rc) {
fprintf ( stderr, "%s: failed to write flash memory, rc=%d\n", fprintf ( stderr, "%s: failed to write flash memory, rc=%d\n",
progname, rc ); progname, rc );
avr_powerdown(fd); exitrc = 1;
close(fd); goto main_exit;
close(iofd);
return 1;
} }
} }
else if (eeprom) { else if (eeprom) {
@ -965,22 +959,24 @@ int main ( int argc, char * argv [] )
if (rc) { if (rc) {
fprintf ( stderr, "%s: failed to write eeprom memory, rc=%d\n", fprintf ( stderr, "%s: failed to write eeprom memory, rc=%d\n",
progname, rc ); progname, rc );
avr_powerdown(fd); exitrc = 1;
close(fd); goto main_exit;
close(iofd);
return 1;
} }
} }
} }
main_exit:
/* /*
* normal program completion * program complete
*/ */
avr_powerdown(fd); avr_powerdown(fd);
close(fd); close(fd);
close(iofd); close(iofd);
fprintf(stderr, "\n" );
return 0; return 0;
} }