static void par_close(PROGRAMMER * pgm) { /* * Restore pin values before closing, * but ensure that buffers are turned off. */ ppi_setall(&pgm->fd, PPIDATA, pgm->ppidata); ppi_setall(&pgm->fd, PPICTRL, pgm->ppictrl); par_setmany(pgm, pgm->pinno[PPI_AVR_BUFF], 1); /* * Handle exit specs. */ switch (pgm->exit_reset) { case EXIT_RESET_ENABLED: par_setpin(pgm, pgm->pinno[PIN_AVR_RESET], 0); break; case EXIT_RESET_DISABLED: par_setpin(pgm, pgm->pinno[PIN_AVR_RESET], 1); break; case EXIT_RESET_UNSPEC: /* Leave it alone. */ break; } switch (pgm->exit_datahigh) { case EXIT_DATAHIGH_ENABLED: ppi_setall(&pgm->fd, PPIDATA, 0xff); break; case EXIT_DATAHIGH_DISABLED: ppi_setall(&pgm->fd, PPIDATA, 0x00); break; case EXIT_DATAHIGH_UNSPEC: /* Leave it alone. */ break; } switch (pgm->exit_vcc) { case EXIT_VCC_ENABLED: par_setmany(pgm, pgm->pinno[PPI_AVR_VCC], 1); break; case EXIT_VCC_DISABLED: par_setmany(pgm, pgm->pinno[PPI_AVR_VCC], 0); break; case EXIT_VCC_UNSPEC: /* Leave it alone. */ break; } ppi_close(&pgm->fd); pgm->fd.ifd = -1; }
static void par_setmany(PROGRAMMER * pgm, unsigned int pinset, int value) { int pin; for (pin = 1; pin <= 17; pin++) { if (pinset & (1 << pin)) par_setpin(pgm, pin, value); } }
static void par_setmany(PROGRAMMER * pgm, unsigned int pinset, int value) { int pin, mask; /* mask is anything non-pin - needs to be applied to each par_setpin to preserve inversion */ mask = pinset & (~PIN_MASK); for (pin = 1; pin <= 17; pin++) { if (pinset & (1 << pin)) par_setpin(pgm, pin | mask, value); } }
static void par_enable(PROGRAMMER * pgm) { /* * Prepare to start talking to the connected device - pull reset low * first, delay a few milliseconds, then enable the buffer. This * sequence allows the AVR to be reset before the buffer is enabled * to avoid a short period of time where the AVR may be driving the * programming lines at the same time the programmer tries to. Of * course, if a buffer is being used, then the /RESET line from the * programmer needs to be directly connected to the AVR /RESET line * and not via the buffer chip. */ par_setpin(pgm, pgm->pinno[PIN_AVR_RESET], 0); usleep(1); /* * enable the 74367 buffer, if connected; this signal is active low */ par_setmany(pgm, pgm->pinno[PPI_AVR_BUFF], 0); }