* pgm.[ch], main.c, par.c, avr910.c, butterfly.c, stk500.c:

Move save/restore-functionality into open/close.
	* par.c: open/close now saves/restores PPICTRL, too.
	* TODO: exitspecs don't work if RESET is in PPICTRL.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@407 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
Jan-Hinnerk Reichert 2004-01-28 20:01:44 +00:00
parent 9c1f837677
commit 51491c6916
9 changed files with 59 additions and 106 deletions

View File

@ -1,3 +1,10 @@
2004-01-28 Jan-Hinnerk Reichert <hinni@despammed.com>
* pgm.[ch], main.c, par.c, avr910.c, butterfly.c, stk500.c:
Move save/restore-functionality into open/close.
* par.c: open/close now saves/restores PPICTRL, too.
* TODO: exitspecs don't work if RESET is in PPICTRL.
2004-01-26 Theodore A. Roth <troth@openavr.org> 2004-01-26 Theodore A. Roth <troth@openavr.org>
* configure.ac (AC_INIT): Post release version update. * configure.ac (AC_INIT): Post release version update.

View File

@ -247,22 +247,6 @@ static int avr910_initialize(PROGRAMMER * pgm, AVRPART * p)
} }
static int avr910_save(PROGRAMMER * pgm)
{
/* Do nothing. */
return 0;
}
static void avr910_restore(PROGRAMMER * pgm)
{
/* Do nothing. */
return;
}
static void avr910_disable(PROGRAMMER * pgm) static void avr910_disable(PROGRAMMER * pgm)
{ {
/* Do nothing. */ /* Do nothing. */
@ -308,7 +292,7 @@ static int avr910_cmd(PROGRAMMER * pgm, unsigned char cmd[4],
} }
static void avr910_open(PROGRAMMER * pgm, char * port) static int avr910_open(PROGRAMMER * pgm, char * port)
{ {
/* /*
* If baudrate was not specified use 19.200 Baud * If baudrate was not specified use 19.200 Baud
@ -644,8 +628,6 @@ void avr910_initpgm(PROGRAMMER * pgm)
pgm->vfy_led = avr910_vfy_led; pgm->vfy_led = avr910_vfy_led;
pgm->initialize = avr910_initialize; pgm->initialize = avr910_initialize;
pgm->display = avr910_display; pgm->display = avr910_display;
pgm->save = avr910_save;
pgm->restore = avr910_restore;
pgm->enable = avr910_enable; pgm->enable = avr910_enable;
pgm->disable = avr910_disable; pgm->disable = avr910_disable;
pgm->powerup = avr910_powerup; pgm->powerup = avr910_powerup;

View File

@ -311,26 +311,6 @@ static int butterfly_initialize(PROGRAMMER * pgm, AVRPART * p)
} }
static int butterfly_save(PROGRAMMER * pgm)
{
no_show_func_info();
/* Do nothing. */
return 0;
}
static void butterfly_restore(PROGRAMMER * pgm)
{
no_show_func_info();
/* Do nothing. */
return;
}
static void butterfly_disable(PROGRAMMER * pgm) static void butterfly_disable(PROGRAMMER * pgm)
{ {
no_show_func_info(); no_show_func_info();
@ -351,7 +331,7 @@ static void butterfly_enable(PROGRAMMER * pgm)
} }
static void butterfly_open(PROGRAMMER * pgm, char * port) static int butterfly_open(PROGRAMMER * pgm, char * port)
{ {
no_show_func_info(); no_show_func_info();
@ -362,6 +342,8 @@ static void butterfly_open(PROGRAMMER * pgm, char * port)
* drain any extraneous input * drain any extraneous input
*/ */
butterfly_drain (pgm, 0); butterfly_drain (pgm, 0);
return 0;
} }
@ -615,8 +597,6 @@ void butterfly_initpgm(PROGRAMMER * pgm)
pgm->vfy_led = butterfly_vfy_led; pgm->vfy_led = butterfly_vfy_led;
pgm->initialize = butterfly_initialize; pgm->initialize = butterfly_initialize;
pgm->display = butterfly_display; pgm->display = butterfly_display;
pgm->save = butterfly_save;
pgm->restore = butterfly_restore;
pgm->enable = butterfly_enable; pgm->enable = butterfly_enable;
pgm->disable = butterfly_disable; pgm->disable = butterfly_disable;
pgm->powerup = butterfly_powerup; pgm->powerup = butterfly_powerup;

View File

@ -20,3 +20,5 @@
- FIXME: ser_posix.c: serial_close(): Should really restore the terminal to - FIXME: ser_posix.c: serial_close(): Should really restore the terminal to
original state here. original state here.
- FIXME: main.c, par.c: exitspecs don't work if RESET-pin is controlled over
PPICTRL.

24
main.c
View File

@ -679,7 +679,6 @@ int main(int argc, char * argv [])
struct avrpart * p; /* which avr part we are programming */ struct avrpart * p; /* which avr part we are programming */
struct avrpart * v; /* used for verify */ struct avrpart * v; /* used for verify */
int readorwrite; /* true if a chip read/write op was selected */ int readorwrite; /* true if a chip read/write op was selected */
int ppidata; /* cached value of the ppi data register */
AVRMEM * sig; /* signature data */ AVRMEM * sig; /* signature data */
struct stat sb; struct stat sb;
UPDATE * upd; UPDATE * upd;
@ -1161,7 +1160,7 @@ int main(int argc, char * argv [])
*/ */
if (port[0] == 0) { if (port[0] == 0) {
fprintf(stderr, "\n%s: no port has been specified on the command line " fprintf(stderr, "\n%s: no port has been specified on the command line "
"or the config file\n", "or the config file\n",
progname); progname);
fprintf(stderr, "%sSpecify a port using the -P option and try again\n\n", fprintf(stderr, "%sSpecify a port using the -P option and try again\n\n",
progbuf); progbuf);
@ -1173,7 +1172,12 @@ int main(int argc, char * argv [])
fprintf(stderr, "%sUsing Programmer : %s\n", progbuf, programmer); fprintf(stderr, "%sUsing Programmer : %s\n", progbuf, programmer);
} }
pgm->open(pgm, port); rc = pgm->open(pgm, port);
if (rc < 0) {
exitrc = 1;
pgm->ppidata = 0; /* clear all bits at exit */
goto main_exit;
}
if (verbose) { if (verbose) {
avr_display(stderr, p, progbuf, verbose); avr_display(stderr, p, progbuf, verbose);
@ -1186,15 +1190,8 @@ int main(int argc, char * argv [])
exitrc = 0; exitrc = 0;
/* /*
* allow the programmer to save its state * handle exit specs. FIXME: this should be moved to "par.c"
*/ */
rc = pgm->save(pgm);
if (rc < 0) {
exitrc = 1;
ppidata = 0; /* clear all bits at exit */
goto main_exit;
}
if (strcmp(pgm->type, "PPI") == 0) { if (strcmp(pgm->type, "PPI") == 0) {
pgm->ppidata &= ~ppiclrbits; pgm->ppidata &= ~ppiclrbits;
pgm->ppidata |= ppisetbits; pgm->ppidata |= ppisetbits;
@ -1412,11 +1409,6 @@ int main(int argc, char * argv [])
pgm->powerdown(pgm); pgm->powerdown(pgm);
/*
* restore programmer state
*/
pgm->restore(pgm);
pgm->disable(pgm); pgm->disable(pgm);
pgm->rdy_led(pgm, OFF); pgm->rdy_led(pgm, OFF);

61
par.c
View File

@ -105,15 +105,11 @@ static void par_powerdown (PROGRAMMER * pgm);
static int par_initialize (PROGRAMMER * pgm, AVRPART * p); static int par_initialize (PROGRAMMER * pgm, AVRPART * p);
static int par_save (PROGRAMMER * pgm);
static void par_restore (PROGRAMMER * pgm);
static void par_disable (PROGRAMMER * pgm); static void par_disable (PROGRAMMER * pgm);
static void par_enable (PROGRAMMER * pgm); static void par_enable (PROGRAMMER * pgm);
static void par_open (PROGRAMMER * pgm, char * port); static int par_open (PROGRAMMER * pgm, char * port);
static void par_close (PROGRAMMER * pgm); static void par_close (PROGRAMMER * pgm);
@ -437,26 +433,6 @@ static int par_initialize(PROGRAMMER * pgm, AVRPART * p)
} }
static int par_save(PROGRAMMER * pgm)
{
int rc;
rc = ppi_getall(pgm->fd, PPIDATA);
if (rc < 0) {
fprintf(stderr, "%s: error reading status of ppi data port\n", progname);
return -1;
}
pgm->ppidata = rc;
return 0;
}
static void par_restore(PROGRAMMER * pgm)
{
ppi_setall(pgm->fd, PPIDATA, pgm->ppidata);
}
static void par_disable(PROGRAMMER * pgm) static void par_disable(PROGRAMMER * pgm)
{ {
ppi_set(pgm->fd, PPIDATA, pgm->pinno[PPI_AVR_BUFF]); ppi_set(pgm->fd, PPIDATA, pgm->pinno[PPI_AVR_BUFF]);
@ -485,8 +461,10 @@ static void par_enable(PROGRAMMER * pgm)
} }
static void par_open(PROGRAMMER * pgm, char * port) static int par_open(PROGRAMMER * pgm, char * port)
{ {
int rc;
pgm->fd = ppi_open(port); pgm->fd = ppi_open(port);
if (pgm->fd < 0) { if (pgm->fd < 0) {
fprintf(stderr, "%s: failed to open parallel port \"%s\"\n\n", fprintf(stderr, "%s: failed to open parallel port \"%s\"\n\n",
@ -495,11 +473,38 @@ static void par_open(PROGRAMMER * pgm, char * port)
} }
ppi_claim(pgm); ppi_claim(pgm);
/*
* save pin values, so they can be restored when device is closed
*/
rc = ppi_getall(pgm->fd, PPIDATA);
if (rc < 0) {
fprintf(stderr, "%s: error reading status of ppi data port\n", progname);
return -1;
}
pgm->ppidata = rc;
rc = ppi_getall(pgm->fd, PPICTRL);
if (rc < 0) {
fprintf(stderr, "%s: error reading status of ppi ctrl port\n", progname);
return -1;
}
pgm->ppictrl = rc;
return 0;
} }
static void par_close(PROGRAMMER * pgm) static void par_close(PROGRAMMER * pgm)
{ {
/*
* Restore pin values before closing,
* but ensure that buffers are turned off.
*/
pgm->ppidata |= pgm->pinno[PPI_AVR_BUFF];
ppi_setall(pgm->fd, PPIDATA, pgm->ppidata);
ppi_setall(pgm->fd, PPICTRL, pgm->ppictrl);
ppi_release(pgm); ppi_release(pgm);
ppi_close(pgm->fd); ppi_close(pgm->fd);
@ -513,7 +518,7 @@ static void par_display(PROGRAMMER * pgm, char * p)
char buffpins[64]; char buffpins[64];
if (pgm->pinno[PPI_AVR_VCC]) { if (pgm->pinno[PPI_AVR_VCC]) {
snprintf(vccpins, sizeof(vccpins), " = pins %s", snprintf(vccpins, sizeof(vccpins), " = pins %s",
vccpins_str(pgm->pinno[PPI_AVR_VCC])); vccpins_str(pgm->pinno[PPI_AVR_VCC]));
} }
else { else {
@ -563,8 +568,6 @@ void par_initpgm(PROGRAMMER * pgm)
pgm->vfy_led = par_vfy_led; pgm->vfy_led = par_vfy_led;
pgm->initialize = par_initialize; pgm->initialize = par_initialize;
pgm->display = par_display; pgm->display = par_display;
pgm->save = par_save;
pgm->restore = par_restore;
pgm->enable = par_enable; pgm->enable = par_enable;
pgm->disable = par_disable; pgm->disable = par_disable;
pgm->powerup = par_powerup; pgm->powerup = par_powerup;

4
pgm.c
View File

@ -72,8 +72,6 @@ PROGRAMMER * pgm_new(void)
pgm->vfy_led = pgm_default_1; pgm->vfy_led = pgm_default_1;
pgm->initialize = pgm_default_2; pgm->initialize = pgm_default_2;
pgm->display = pgm_default_6; pgm->display = pgm_default_6;
pgm->save = pgm_default_3;
pgm->restore = pgm_default_4;
pgm->enable = pgm_default_4; pgm->enable = pgm_default_4;
pgm->disable = pgm_default_4; pgm->disable = pgm_default_4;
pgm->powerup = pgm_default_4; pgm->powerup = pgm_default_4;
@ -81,7 +79,7 @@ PROGRAMMER * pgm_new(void)
pgm->program_enable = pgm_default_2; pgm->program_enable = pgm_default_2;
pgm->chip_erase = pgm_default_2; pgm->chip_erase = pgm_default_2;
pgm->cmd = pgm_default_5; pgm->cmd = pgm_default_5;
pgm->open = pgm_default_6; pgm->open = pgm_default_3;
pgm->close = pgm_default_4; pgm->close = pgm_default_4;
/* /*

5
pgm.h
View File

@ -42,6 +42,7 @@ typedef struct programmer_t {
char port[PGM_PORTLEN]; char port[PGM_PORTLEN];
unsigned int pinno[N_PINS]; unsigned int pinno[N_PINS];
int ppidata; int ppidata;
int ppictrl;
int baudrate; int baudrate;
int fd; int fd;
int page_size; /* page size if the programmer supports paged write/load */ int page_size; /* page size if the programmer supports paged write/load */
@ -51,8 +52,6 @@ typedef struct programmer_t {
int (*vfy_led) (struct programmer_t * pgm, int value); int (*vfy_led) (struct programmer_t * pgm, int value);
int (*initialize) (struct programmer_t * pgm, AVRPART * p); int (*initialize) (struct programmer_t * pgm, AVRPART * p);
void (*display) (struct programmer_t * pgm, char * p); void (*display) (struct programmer_t * pgm, char * p);
int (*save) (struct programmer_t * pgm);
void (*restore) (struct programmer_t * pgm);
void (*enable) (struct programmer_t * pgm); void (*enable) (struct programmer_t * pgm);
void (*disable) (struct programmer_t * pgm); void (*disable) (struct programmer_t * pgm);
void (*powerup) (struct programmer_t * pgm); void (*powerup) (struct programmer_t * pgm);
@ -61,7 +60,7 @@ typedef struct programmer_t {
int (*chip_erase) (struct programmer_t * pgm, AVRPART * p); int (*chip_erase) (struct programmer_t * pgm, AVRPART * p);
int (*cmd) (struct programmer_t * pgm, unsigned char cmd[4], int (*cmd) (struct programmer_t * pgm, unsigned char cmd[4],
unsigned char res[4]); unsigned char res[4]);
void (*open) (struct programmer_t * pgm, char * port); int (*open) (struct programmer_t * pgm, char * port);
void (*close) (struct programmer_t * pgm); void (*close) (struct programmer_t * pgm);
int (*paged_write) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m, int (*paged_write) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m,
int page_size, int n_bytes); int page_size, int n_bytes);

View File

@ -522,16 +522,6 @@ static int stk500_initialize(PROGRAMMER * pgm, AVRPART * p)
} }
static int stk500_save(PROGRAMMER * pgm)
{
return 0;
}
static void stk500_restore(PROGRAMMER * pgm)
{
return;
}
static void stk500_disable(PROGRAMMER * pgm) static void stk500_disable(PROGRAMMER * pgm)
{ {
unsigned char buf[16]; unsigned char buf[16];
@ -585,7 +575,7 @@ static void stk500_enable(PROGRAMMER * pgm)
} }
static void stk500_open(PROGRAMMER * pgm, char * port) static int stk500_open(PROGRAMMER * pgm, char * port)
{ {
strcpy(pgm->port, port); strcpy(pgm->port, port);
pgm->fd = serial_open(port, 115200); pgm->fd = serial_open(port, 115200);
@ -598,6 +588,8 @@ static void stk500_open(PROGRAMMER * pgm, char * port)
stk500_getsync(pgm); stk500_getsync(pgm);
stk500_drain(pgm, 0); stk500_drain(pgm, 0);
return 0;
} }
@ -1185,8 +1177,6 @@ void stk500_initpgm(PROGRAMMER * pgm)
pgm->vfy_led = stk500_vfy_led; pgm->vfy_led = stk500_vfy_led;
pgm->initialize = stk500_initialize; pgm->initialize = stk500_initialize;
pgm->display = stk500_display; pgm->display = stk500_display;
pgm->save = stk500_save;
pgm->restore = stk500_restore;
pgm->enable = stk500_enable; pgm->enable = stk500_enable;
pgm->disable = stk500_disable; pgm->disable = stk500_disable;
pgm->powerup = stk500_powerup; pgm->powerup = stk500_powerup;