In interactive mode, reset the address and length if we start dumping

a memory type different than the previous one.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@103 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
Brian S. Dean 2001-11-21 18:54:11 +00:00
parent b50ce8fabd
commit e95114a18d
4 changed files with 75 additions and 49 deletions

112
avr.c
View File

@ -174,32 +174,6 @@ AVRMEM * avr_locate_mem(AVRPART * p, char * desc)
/*
* transmit and receive a bit of data to/from the AVR device
*/
int avr_txrx_bit(int fd, int bit)
{
int r;
/*
* read the result bit (it is either valid from a previous clock
* pulse or it is ignored in the current context)
*/
r = ppi_getpin(fd, pgm->pinno[PIN_AVR_MISO]);
/* set the data input line as desired */
ppi_setpin(fd, pgm->pinno[PIN_AVR_MOSI], bit);
/*
* pulse the clock line, clocking in the MOSI data, and clocking out
* the next result bit
*/
ppi_pulsepin(fd, pgm->pinno[PIN_AVR_SCK]);
return r;
}
/* /*
* transmit and receive a byte of data to/from the AVR device * transmit and receive a byte of data to/from the AVR device
*/ */
@ -211,7 +185,22 @@ unsigned char avr_txrx(int fd, unsigned char byte)
rbyte = 0; rbyte = 0;
for (i=0; i<8; i++) { for (i=0; i<8; i++) {
b = (byte >> (7-i)) & 0x01; b = (byte >> (7-i)) & 0x01;
r = avr_txrx_bit(fd, b);
/*
* read the result bit (it is either valid from a previous clock
* pulse or it is ignored in the current context)
*/
r = ppi_getpin(fd, pgm->pinno[PIN_AVR_MISO]);
/* set the data input line as desired */
ppi_setpin(fd, pgm->pinno[PIN_AVR_MOSI], b);
/*
* pulse the clock line, clocking in the MOSI data, and clocking out
* the next result bit
*/
ppi_pulsepin(fd, pgm->pinno[PIN_AVR_SCK]);
rbyte = rbyte | (r << (7-i)); rbyte = rbyte | (r << (7-i));
} }
@ -245,6 +234,11 @@ int avr_cmd(int fd, unsigned char cmd[4], unsigned char res[4])
} }
/*
* avr_set_bits()
*
* Set instruction bits in the specified command based on the opcode.
*/
int avr_set_bits(OPCODE * op, unsigned char * cmd) int avr_set_bits(OPCODE * op, unsigned char * cmd)
{ {
int i, j, bit; int i, j, bit;
@ -266,6 +260,12 @@ int avr_set_bits(OPCODE * op, unsigned char * cmd)
} }
/*
* avr_set_addr()
*
* Set address bits in the specified command based on the opcode, and
* the address.
*/
int avr_set_addr(OPCODE * op, unsigned char * cmd, unsigned long addr) int avr_set_addr(OPCODE * op, unsigned char * cmd, unsigned long addr)
{ {
int i, j, bit; int i, j, bit;
@ -289,6 +289,12 @@ int avr_set_addr(OPCODE * op, unsigned char * cmd, unsigned long addr)
} }
/*
* avr_set_input()
*
* Set input data bits in the specified command based on the opcode,
* and the data byte.
*/
int avr_set_input(OPCODE * op, unsigned char * cmd, unsigned char data) int avr_set_input(OPCODE * op, unsigned char * cmd, unsigned char data)
{ {
int i, j, bit; int i, j, bit;
@ -312,7 +318,13 @@ int avr_set_input(OPCODE * op, unsigned char * cmd, unsigned char data)
} }
int avr_get_output(OPCODE * op, unsigned char * cmd, unsigned char * data) /*
* avr_get_output()
*
* Retreive output data bits from the command results based on the
* opcode data.
*/
int avr_get_output(OPCODE * op, unsigned char * res, unsigned char * data)
{ {
int i, j, bit; int i, j, bit;
unsigned char value; unsigned char value;
@ -323,7 +335,7 @@ int avr_get_output(OPCODE * op, unsigned char * cmd, unsigned char * data)
j = 3 - i / 8; j = 3 - i / 8;
bit = i % 8; bit = i % 8;
mask = 1 << bit; mask = 1 << bit;
value = ((cmd[j] & mask) >> bit) & 0x01; value = ((res[j] & mask) >> bit) & 0x01;
value = value << op->bit[i].bitno; value = value << op->bit[i].bitno;
if (value) if (value)
*data = *data | value; *data = *data | value;
@ -350,6 +362,9 @@ int avr_read_byte(int fd, AVRPART * p, AVRMEM * mem, unsigned long addr,
LED_ON(fd, pgm->pinno[PIN_LED_PGM]); LED_ON(fd, pgm->pinno[PIN_LED_PGM]);
LED_OFF(fd, pgm->pinno[PIN_LED_ERR]); LED_OFF(fd, pgm->pinno[PIN_LED_ERR]);
/*
* figure out what opcode to use
*/
if (mem->op[AVR_OP_READ_LO]) { if (mem->op[AVR_OP_READ_LO]) {
if (addr & 0x00000001) if (addr & 0x00000001)
readop = mem->op[AVR_OP_READ_HI]; readop = mem->op[AVR_OP_READ_HI];
@ -389,7 +404,7 @@ int avr_read_byte(int fd, AVRPART * p, AVRMEM * mem, unsigned long addr,
* corresponding buffer of the avrpart pointed to by 'p'. If size = * corresponding buffer of the avrpart pointed to by 'p'. If size =
* 0, read the entire contents, otherwise, read 'size' bytes. * 0, read the entire contents, otherwise, read 'size' bytes.
* *
* Return the number of bytes read, or -1 if an error occurs. * Return the number of bytes read, or < 0 if an error occurs.
*/ */
int avr_read(int fd, AVRPART * p, char * memtype, int size, int verbose) int avr_read(int fd, AVRPART * p, char * memtype, int size, int verbose)
{ {
@ -430,11 +445,8 @@ int avr_read(int fd, AVRPART * p, char * memtype, int size, int verbose)
} }
/* /*
* write a byte of data to the indicated memory region * write a page data at the specified address
*/ */
int avr_write_page(int fd, AVRPART * p, AVRMEM * mem, int avr_write_page(int fd, AVRPART * p, AVRMEM * mem,
unsigned long addr) unsigned long addr)
@ -451,6 +463,10 @@ int avr_write_page(int fd, AVRPART * p, AVRMEM * mem,
return -1; return -1;
} }
/*
* if this memory is word-addressable, adjust the address
* accordingly
*/
if (mem->op[AVR_OP_LOADPAGE_LO]) if (mem->op[AVR_OP_LOADPAGE_LO])
addr = addr / 2; addr = addr / 2;
@ -475,7 +491,7 @@ int avr_write_page(int fd, AVRPART * p, AVRMEM * mem,
/* /*
* write a byte of data to the indicated memory region * write a byte of data at the specified address
*/ */
int avr_write_byte(int fd, AVRPART * p, AVRMEM * mem, int avr_write_byte(int fd, AVRPART * p, AVRMEM * mem,
unsigned long addr, unsigned char data) unsigned long addr, unsigned char data)
@ -601,11 +617,11 @@ int avr_write_byte(int fd, AVRPART * p, AVRMEM * mem,
/* /*
* Write the whole memory region (flash or eeprom, specified by * Write the whole memory region of the specified memory from the
* 'memtype') from the corresponding buffer of the avrpart pointed to * corresponding buffer of the avrpart pointed to by 'p'. Write up to
* by 'p'. Write up to 'size' bytes from the buffer. Data is only * 'size' bytes from the buffer. Data is only written if the new data
* written if the new data value is different from the existing data * value is different from the existing data value. Data beyond
* value. Data beyond 'size' bytes is not affected. * 'size' bytes is not affected.
* *
* Return the number of bytes written, or -1 if an error occurs. * Return the number of bytes written, or -1 if an error occurs.
*/ */
@ -625,7 +641,6 @@ int avr_write(int fd, AVRPART * p, char * memtype, int size, int verbose)
return -1; return -1;
} }
LED_OFF(fd, pgm->pinno[PIN_LED_ERR]); LED_OFF(fd, pgm->pinno[PIN_LED_ERR]);
werror = 0; werror = 0;
@ -643,7 +658,6 @@ int avr_write(int fd, AVRPART * p, char * memtype, int size, int verbose)
} }
for (i=0; i<wsize; i++) { for (i=0; i<wsize; i++) {
/* eeprom or low byte of flash */
data = m->buf[i]; data = m->buf[i];
if (verbose) { if (verbose) {
if (i % 16 == 0) if (i % 16 == 0)
@ -658,6 +672,10 @@ int avr_write(int fd, AVRPART * p, char * memtype, int size, int verbose)
} }
if (m->paged) { if (m->paged) {
/*
* check to see if it is time to flush the page with a page
* write
*/
if (((i % m->page_size) == m->page_size-1) || if (((i % m->page_size) == m->page_size-1) ||
(i == wsize-1)) { (i == wsize-1)) {
rc = avr_write_page(fd, p, m, i); rc = avr_write_page(fd, p, m, i);
@ -792,7 +810,6 @@ int avr_initialize(int fd, AVRPART * p)
avr_powerup(fd); avr_powerup(fd);
ppi_setpin(fd, pgm->pinno[PIN_AVR_SCK], 0); ppi_setpin(fd, pgm->pinno[PIN_AVR_SCK], 0);
ppi_setpin(fd, pgm->pinno[PIN_AVR_RESET], 0); ppi_setpin(fd, pgm->pinno[PIN_AVR_RESET], 0);
ppi_pulsepin(fd, pgm->pinno[PIN_AVR_RESET]); ppi_pulsepin(fd, pgm->pinno[PIN_AVR_RESET]);
@ -833,7 +850,10 @@ int avr_initialize(int fd, AVRPART * p)
} }
/*
* Allocate and initialize memory buffers for each of the device's
* defined memory regions.
*/
int avr_initmem(AVRPART * p) int avr_initmem(AVRPART * p)
{ {
LNODEID ln; LNODEID ln;
@ -918,8 +938,8 @@ void avr_mem_display(char * prefix, FILE * f, AVRMEM * m, int type)
{ {
if (m == NULL) { if (m == NULL) {
fprintf(f, fprintf(f,
"%sMem Page Polled\n" "%s Page Polled\n"
"%sType Paged Size Size #Pages MinW MaxW ReadBack\n" "%sMemory Type Paged Size Size #Pages MinW MaxW ReadBack\n"
"%s----------- ------ ------ ---- ------ ----- ----- ---------\n", "%s----------- ------ ------ ---- ------ ----- ----- ---------\n",
prefix, prefix, prefix); prefix, prefix, prefix);
} }

View File

@ -29,7 +29,6 @@
/* $Id$ */ /* $Id$ */
%token K_OP
%token K_READ %token K_READ
%token K_WRITE %token K_WRITE
%token K_READ_LO %token K_READ_LO

View File

@ -152,7 +152,6 @@ size { yylval=NULL; return K_SIZE; }
vcc { yylval=NULL; return K_VCC; } vcc { yylval=NULL; return K_VCC; }
vfyled { yylval=NULL; return K_VFYLED; } vfyled { yylval=NULL; return K_VFYLED; }
op { yylval=NULL; return K_OP; }
read { yylval=new_token(K_READ); return K_READ; } read { yylval=new_token(K_READ); return K_READ; }
write { yylval=new_token(K_WRITE); return K_WRITE; } write { yylval=new_token(K_WRITE); return K_WRITE; }
read_lo { yylval=new_token(K_READ_LO); return K_READ_LO; } read_lo { yylval=new_token(K_READ_LO); return K_READ_LO; }

10
term.c
View File

@ -206,6 +206,7 @@ int hexdump_buf(FILE * f, int startaddr, unsigned char * buf, int len)
int cmd_dump(int fd, struct avrpart * p, int argc, char * argv[]) int cmd_dump(int fd, struct avrpart * p, int argc, char * argv[])
{ {
static char prevmem[128] = {0};
char * e; char * e;
unsigned char * buf; unsigned char * buf;
int maxsize; int maxsize;
@ -223,6 +224,13 @@ int cmd_dump(int fd, struct avrpart * p, int argc, char * argv[])
memtype = argv[1]; memtype = argv[1];
if (strncmp(prevmem, memtype, strlen(memtype)) != 0) {
addr = 0;
len = 64;
strncpy(prevmem, memtype, sizeof(prevmem)-1);
prevmem[sizeof(prevmem)-1] = 0;
}
mem = avr_locate_mem(p, memtype); mem = avr_locate_mem(p, memtype);
if (mem == NULL) { if (mem == NULL) {
fprintf(stderr, "\"%s\" memory type not defined for part \"%s\"\n", fprintf(stderr, "\"%s\" memory type not defined for part \"%s\"\n",
@ -298,7 +306,7 @@ int cmd_write(int fd, struct avrpart * p, int argc, char * argv[])
AVRMEM * mem; AVRMEM * mem;
if (argc < 4) { if (argc < 4) {
fprintf(stderr, "Usage: write flash|eeprom|fuse <addr> <byte1> " fprintf(stderr, "Usage: write <memtype> <addr> <byte1> "
"<byte2> ... byteN>\n"); "<byte2> ... byteN>\n");
return -1; return -1;
} }