diff --git a/ChangeLog b/ChangeLog index 600a1e4d..08b07a2f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2006-08-22 Joerg Wunsch + + * bitbang.c: Move the bitbang prerequisite checks out from + main() into their own bitbang_check_prerequisites(). + * bitbang.h: (Ditto.) + * main.c: (Ditto.) + * par.c: (Ditto.) + * serbb_posix.c: (Ditto.) + * serbb_win32.c: (Ditto.) + 2006-08-22 Joerg Wunsch * avrdude.conf.in: Add page mode parameters for all "eeprom" diff --git a/bitbang.c b/bitbang.c index e6102c7f..a420dc2d 100644 --- a/bitbang.c +++ b/bitbang.c @@ -335,4 +335,24 @@ int bitbang_initialize(PROGRAMMER * pgm, AVRPART * p) return 0; } +static void verify_pin_assigned(PROGRAMMER * pgm, int pin, char * desc) +{ + if (pgm->pinno[pin] == 0) { + fprintf(stderr, "%s: error: no pin has been assigned for %s\n", + progname, desc); + exit(1); + } +} + +/* + * Verify all prerequisites for a bit-bang programmer are present. + */ +void bitbang_check_prerequisites(PROGRAMMER *pgm) +{ + + verify_pin_assigned(pgm, PIN_AVR_RESET, "AVR RESET"); + verify_pin_assigned(pgm, PIN_AVR_SCK, "AVR SCK"); + verify_pin_assigned(pgm, PIN_AVR_MISO, "AVR MISO"); + verify_pin_assigned(pgm, PIN_AVR_MOSI, "AVR MOSI"); +} diff --git a/bitbang.h b/bitbang.h index 90f0d481..a0cf32e6 100644 --- a/bitbang.h +++ b/bitbang.h @@ -27,6 +27,8 @@ int bitbang_getpin(int fd, int pin); int bitbang_highpulsepin(int fd, int pin); void bitbang_delay(unsigned int us); +void bitbang_check_prerequisites(PROGRAMMER *pgm); + int bitbang_rdy_led (PROGRAMMER * pgm, int value); int bitbang_err_led (PROGRAMMER * pgm, int value); int bitbang_pgm_led (PROGRAMMER * pgm, int value); diff --git a/main.c b/main.c index 64a11e7a..4de31113 100644 --- a/main.c +++ b/main.c @@ -165,17 +165,6 @@ void programmer_display(char * p) -void verify_pin_assigned(int pin, char * desc) -{ - if (pgm->pinno[pin] == 0) { - fprintf(stderr, "%s: error: no pin has been assigned for %s\n", - progname, desc); - exit(1); - } -} - - - PROGRAMMER * locate_programmer(LISTID programmers, char * configid) { LNODEID ln1, ln2; @@ -1097,7 +1086,6 @@ int main(int argc, char * argv []) } } - /* * set up seperate instances of the avr part, one for use in * programming, one for use in verifying. These are separate @@ -1106,13 +1094,6 @@ int main(int argc, char * argv []) p = avr_dup_part(p); v = avr_dup_part(p); - if (strcmp(pgm->type, "PPI") == 0) { - verify_pin_assigned(PIN_AVR_RESET, "AVR RESET"); - verify_pin_assigned(PIN_AVR_SCK, "AVR SCK"); - verify_pin_assigned(PIN_AVR_MISO, "AVR MISO"); - verify_pin_assigned(PIN_AVR_MOSI, "AVR MOSI"); - } - /* * open the programmer */ diff --git a/par.c b/par.c index 7cc30ff4..6f7ac1e8 100644 --- a/par.c +++ b/par.c @@ -254,6 +254,8 @@ static int par_open(PROGRAMMER * pgm, char * port) { int rc; + bitbang_check_prerequisites(pgm); + pgm->fd = ppi_open(port); if (pgm->fd < 0) { fprintf(stderr, "%s: failed to open parallel port \"%s\"\n\n", diff --git a/serbb_posix.c b/serbb_posix.c index b78cddae..dae8bbb7 100644 --- a/serbb_posix.c +++ b/serbb_posix.c @@ -200,6 +200,8 @@ static int serbb_open(PROGRAMMER *pgm, char *port) struct termios mode; int flags; + bitbang_check_prerequisites(pgm); + /* adapted from uisp code */ pgm->fd = open(port, O_RDWR | O_NOCTTY | O_NONBLOCK); diff --git a/serbb_win32.c b/serbb_win32.c index e4cd95d5..8876fb08 100644 --- a/serbb_win32.c +++ b/serbb_win32.c @@ -272,6 +272,8 @@ static int serbb_open(PROGRAMMER *pgm, char *port) LPVOID lpMsgBuf; HANDLE hComPort = INVALID_HANDLE_VALUE; + bitbang_check_prerequisites(pgm); + hComPort = CreateFile(port, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);