Move pin definitions to their own file.

First pass at providing feedback via the optionally connected leds.  I
don't actually have any of these attached to my programmer, so I can
only guess as whether this is toggling them on and off correctly.

Also, enable and disable the optional 74367 buffer.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@50 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
Brian S. Dean 2001-01-24 19:10:34 +00:00
parent fc56e6b4f9
commit eff6750e5c
6 changed files with 96 additions and 24 deletions

View File

@ -30,8 +30,8 @@ all : ${TARGET}
${TARGET} : ${OBJS} ${TARGET} : ${OBJS}
${CC} ${LDFLAGS} -o ${TARGET} ${OBJS} ${LIBS} ${CC} ${LDFLAGS} -o ${TARGET} ${OBJS} ${LIBS}
main.o : avr.h fileio.h ppi.h term.h main.o : avr.h fileio.h ppi.h term.h pindefs.h
avr.o : avr.h ppi.h avr.o : avr.h ppi.h pindefs.h
fileio.o : fileio.h avr.h fileio.o : fileio.h avr.h
ppi.o : ppi.h ppi.o : ppi.h
term.o : term.h avr.h term.o : term.h avr.h

16
avr.c
View File

@ -35,6 +35,7 @@
#include "avr.h" #include "avr.h"
#include "pindefs.h"
#include "ppi.h" #include "ppi.h"
@ -172,6 +173,8 @@ unsigned char avr_read_byte ( int fd, struct avrpart * p,
/* order here is very important, AVR_EEPROM, AVR_FLASH, AVR_FLASH+1 */ /* order here is very important, AVR_EEPROM, AVR_FLASH, AVR_FLASH+1 */
static unsigned char cmdbyte[3] = { 0xa0, 0x20, 0x28 }; static unsigned char cmdbyte[3] = { 0xa0, 0x20, 0x28 };
LED_ON(fd, PIN_LED_PGM);
offset = 0; offset = 0;
if (memtype == AVR_FLASH) { if (memtype == AVR_FLASH) {
@ -186,6 +189,8 @@ unsigned char avr_read_byte ( int fd, struct avrpart * p,
avr_cmd(fd, cmd, res); avr_cmd(fd, cmd, res);
LED_OFF(fd, PIN_LED_PGM);
return res[3]; return res[3];
} }
@ -244,6 +249,8 @@ int avr_write_byte ( int fd, struct avrpart * p, AVRMEM memtype,
return 0; return 0;
} }
LED_ON(fd, PIN_LED_PGM);
offset = 0; offset = 0;
caddr = addr; caddr = addr;
@ -285,10 +292,12 @@ int avr_write_byte ( int fd, struct avrpart * p, AVRMEM memtype,
* we couldn't write the data, indicate our displeasure by * we couldn't write the data, indicate our displeasure by
* returning an error code * returning an error code
*/ */
LED_OFF(fd, PIN_LED_PGM);
return -1; return -1;
} }
} }
LED_OFF(fd, PIN_LED_PGM);
return 0; return 0;
} }
@ -310,6 +319,8 @@ int avr_write ( int fd, struct avrpart * p, AVRMEM memtype, int size )
unsigned short i; unsigned short i;
unsigned char data; unsigned char data;
LED_OFF(fd, PIN_LED_ERR);
buf = p->mem[memtype]; buf = p->mem[memtype];
wsize = p->memsize[memtype]; wsize = p->memsize[memtype];
if (size < wsize) { if (size < wsize) {
@ -331,6 +342,7 @@ int avr_write ( int fd, struct avrpart * p, AVRMEM memtype, int size )
if (rc) { if (rc) {
fprintf(stderr, " ***failed; "); fprintf(stderr, " ***failed; ");
fprintf(stderr, "\n"); fprintf(stderr, "\n");
LED_ON(fd, PIN_LED_ERR);
} }
} }
@ -365,10 +377,14 @@ int avr_chip_erase ( int fd, struct avrpart * p )
unsigned char data[4] = {0xac, 0x80, 0x00, 0x00}; unsigned char data[4] = {0xac, 0x80, 0x00, 0x00};
unsigned char res[4]; unsigned char res[4];
LED_ON(fd, PIN_LED_PGM);
avr_cmd(fd, data, res); avr_cmd(fd, data, res);
usleep(p->chip_erase_delay); usleep(p->chip_erase_delay);
avr_initialize(fd, p); avr_initialize(fd, p);
LED_OFF(fd, PIN_LED_PGM);
return 0; return 0;
} }

14
avr.h
View File

@ -34,20 +34,6 @@
#include <stdio.h> #include <stdio.h>
#define PPI_AVR_VCC 0x0f /* ppi pins 2-5, data reg bits 0-3 */
#define PIN_AVR_BUFF 6
#define PIN_AVR_RESET 7
#define PIN_AVR_SCK 8
#define PIN_AVR_MOSI 9
#define PIN_AVR_MISO 10
#define PIN_LED_ERR 1
#define PIN_LED_RDY 14
#define PIN_LED_PGM 16
#define PIN_LED_VFY 17
/* /*
* AVR memory designations; the order of these is important, these are * AVR memory designations; the order of these is important, these are
* used as indexes into statically initialized data, don't change them * used as indexes into statically initialized data, don't change them

34
main.c
View File

@ -81,6 +81,7 @@
#include "avr.h" #include "avr.h"
#include "fileio.h" #include "fileio.h"
#include "pindefs.h"
#include "ppi.h" #include "ppi.h"
#include "term.h" #include "term.h"
@ -105,12 +106,6 @@ void usage ( void )
" %s[-i filename] [-m memtype] [-o filename] [-P parallel] [-t]\n\n", " %s[-i filename] [-m memtype] [-o filename] [-P parallel] [-t]\n\n",
progname, progbuf); progname, progbuf);
#if 0
fprintf(stderr, " Valid Parts for the -p option are:\n");
avr_list_parts(stderr, " ");
fprintf(stderr, "\n");
#endif
} }
@ -407,6 +402,19 @@ int main ( int argc, char * argv [] )
ppidata &= ~ppiclrbits; ppidata &= ~ppiclrbits;
ppidata |= ppisetbits; ppidata |= ppisetbits;
/*
* turn off all the status leds
*/
LED_OFF(fd, PIN_LED_RDY);
LED_OFF(fd, PIN_LED_ERR);
LED_OFF(fd, PIN_LED_PGM);
LED_OFF(fd, PIN_LED_VFY);
/*
* enable the 74367 buffer, if connected; this signal is active low
*/
ppi_setpin(fd, PIN_AVR_BUFF, 0);
/* /*
* initialize the chip in preperation for accepting commands * initialize the chip in preperation for accepting commands
*/ */
@ -417,6 +425,9 @@ int main ( int argc, char * argv [] )
goto main_exit; goto main_exit;
} }
/* indicate ready */
LED_ON(fd, PIN_LED_RDY);
fprintf ( stderr, fprintf ( stderr,
"%s: AVR device initialized and ready to accept instructions\n", "%s: AVR device initialized and ready to accept instructions\n",
progname ); progname );
@ -556,6 +567,8 @@ int main ( int argc, char * argv [] )
* verify that the in memory file (p->flash or p->eeprom) is the * verify that the in memory file (p->flash or p->eeprom) is the
* same as what is on the chip * same as what is on the chip
*/ */
LED_ON(fd, PIN_LED_VFY);
fprintf(stderr, "%s: verifying %s memory against %s:\n", fprintf(stderr, "%s: verifying %s memory against %s:\n",
progname, avr_memtstr(memtype), inputf); progname, avr_memtstr(memtype), inputf);
fprintf(stderr, "%s: reading on-chip %s data:\n", fprintf(stderr, "%s: reading on-chip %s data:\n",
@ -564,6 +577,7 @@ int main ( int argc, char * argv [] )
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: failed to read all of %s memory, rc=%d\n", fprintf(stderr, "%s: failed to read all of %s memory, rc=%d\n",
progname, avr_memtstr(memtype), rc); progname, avr_memtstr(memtype), rc);
LED_ON(fd, PIN_LED_ERR);
exitrc = 1; exitrc = 1;
goto main_exit; goto main_exit;
} }
@ -573,12 +587,15 @@ int main ( int argc, char * argv [] )
if (rc < 0) { if (rc < 0) {
fprintf(stderr, "%s: verification error; content mismatch\n", fprintf(stderr, "%s: verification error; content mismatch\n",
progname); progname);
LED_ON(fd, PIN_LED_ERR);
exitrc = 1; exitrc = 1;
goto main_exit; goto main_exit;
} }
fprintf(stderr, "%s: %d bytes of %s verified\n", fprintf(stderr, "%s: %d bytes of %s verified\n",
progname, rc, avr_memtstr(memtype)); progname, rc, avr_memtstr(memtype));
LED_OFF(fd, PIN_LED_VFY);
} }
@ -592,6 +609,11 @@ int main ( int argc, char * argv [] )
avr_powerdown(fd); avr_powerdown(fd);
ppi_setall(fd, PPIDATA, ppidata); ppi_setall(fd, PPIDATA, ppidata);
/*
* disable the 74367 buffer, if connected; this signal is active low
*/
ppi_setpin(fd, PIN_AVR_BUFF, 1);
close(fd); close(fd);
fprintf(stderr, "\n%s done. Thank you.\n\n", progname); fprintf(stderr, "\n%s done. Thank you.\n\n", progname);

49
pindefs.h Normal file
View File

@ -0,0 +1,49 @@
/*
* Copyright 2000 Brian S. Dean <bsd@bsdhome.com>
* All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BRIAN S. DEAN ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BRIAN S. DEAN BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*/
/* $Id$ */
#ifndef __pindefs_h__
#define __pindefs_h__
#define PPI_AVR_VCC 0x0f /* ppi pins 2-5, data reg bits 0-3 */
#define PIN_AVR_BUFF 6
#define PIN_AVR_RESET 7
#define PIN_AVR_SCK 8
#define PIN_AVR_MOSI 9
#define PIN_AVR_MISO 10
#define PIN_LED_ERR 1
#define PIN_LED_RDY 14
#define PIN_LED_PGM 16
#define PIN_LED_VFY 17
#define LED_ON(fd,pin) ppi_setpin(fd,pin,0)
#define LED_OFF(fd,pin) ppi_setpin(fd,pin,1)
#endif

3
ppi.c
View File

@ -310,8 +310,7 @@ int ppi_getpinreg ( int pin )
*/ */
int ppi_sense ( int fd ) int ppi_sense ( int fd )
{ {
unsigned int r, pr; unsigned int pr;
unsigned int v;
int count; int count;
char buf[128]; char buf[128];
int i; int i;