From 216ed6b0f7080da194bbe9dc850b9b4be17906bd Mon Sep 17 00:00:00 2001 From: "Brian S. Dean" Date: Tue, 16 Oct 2001 23:32:30 +0000 Subject: [PATCH] Fix (again, hopefully) page addressing for the ATMega parts. Rename the poorly chosen name "bank" to "page" for page addressing. Atmel calls it "page" in their documentation. git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@91 81a1dc3b-b13d-400b-aceb-764788c761c2 --- avrdude/avr.c | 66 ++++++++++---------- avrdude/avr.h | 8 +-- avrdude/avrdude.conf.sample | 120 ++++++++++++++++++------------------ avrdude/config_gram.y | 69 +++++++++++---------- avrdude/lexer.l | 9 ++- avrdude/term.c | 4 +- 6 files changed, 145 insertions(+), 131 deletions(-) diff --git a/avrdude/avr.c b/avrdude/avr.c index 9f7fe950..e152ecf7 100644 --- a/avrdude/avr.c +++ b/avrdude/avr.c @@ -295,34 +295,32 @@ int avr_read(int fd, AVRPART * p, int memtype) /* * write a byte of data to the indicated memory region */ -int avr_write_bank(int fd, AVRPART * p, int memtype, - unsigned short bank) +int avr_write_page(int fd, AVRPART * p, int memtype, + unsigned short page) { unsigned char cmd[4]; unsigned char res[4]; - unsigned int shift; LED_ON(fd, pgm->pinno[PIN_LED_PGM]); LED_OFF(fd, pgm->pinno[PIN_LED_ERR]); /* - * 'bank' indicates which bank is being programmed: 0 for the first - * bank_size block, 1 for the second, up to num_banks-1 for the + * 'page' indicates which page is being programmed: 0 for the first + * page_size block, 1 for the second, up to num_pages-1 for the * last. The MCU actually wants the high-order bits of what would * be the actual address instead, shifted left to the upper most * bits of a 16 bit word. For a 128K flash, the actual address is a * 17 bits. To get the right value to send to the MCU, we want to - * shift 'bank' left by 16 - the number of bits in the bank + * shift 'page' left by 16 - the number of bits in the page * address. */ - shift = 16 - p->mem[memtype].bankaddrbits; - bank = bank << shift; + page = page << p->mem[memtype].pageaddr_shift; - fprintf(stderr, "bank address=%u\n", bank); + fprintf(stderr, "page address=%u\n", page); cmd[0] = 0x4c; - cmd[1] = bank >> 8; /* high order bits of address */ - cmd[2] = bank & 0x0ff; /* low order bits of address */ + cmd[1] = page >> 8; /* high order bits of address */ + cmd[2] = page & 0x0ff; /* low order bits of address */ cmd[3] = 0; /* these bits are ignored */ avr_cmd(fd, cmd, res); @@ -355,11 +353,11 @@ int avr_write_byte(int fd, AVRPART * p, int memtype, /* order here is very important, AVR_M_EEPROM, AVR_M_FLASH, AVR_M_FLASH+1 */ static unsigned char cmdbyte[3] = { 0xc0, 0x40, 0x48 }; - if (!p->mem[memtype].banked) { + if (!p->mem[memtype].paged) { /* * check to see if the write is necessary by reading the existing * value and only write if we are changing the value; we can't - * use this optimization for banked addressing. + * use this optimization for paged addressing. */ b = avr_read_byte(fd, p, memtype, addr); if (b == data) { @@ -367,7 +365,7 @@ int avr_write_byte(int fd, AVRPART * p, int memtype, } } else { - addr = addr % p->mem[memtype].bank_size; + addr = addr % p->mem[memtype].page_size; } LED_ON(fd, pgm->pinno[PIN_LED_PGM]); @@ -388,11 +386,11 @@ int avr_write_byte(int fd, AVRPART * p, int memtype, avr_cmd(fd, cmd, res); - if (p->mem[memtype].banked) { + if (p->mem[memtype].paged) { /* - * in banked addressing, single bytes to written to the memory + * in paged addressing, single bytes to written to the memory * page complete immediately, we only need to delay when we commit - * the whole page via the avr_write_bank() routine. + * the whole page via the avr_write_page() routine. */ LED_OFF(fd, pgm->pinno[PIN_LED_PGM]); return 0; @@ -483,15 +481,15 @@ int avr_write(int fd, AVRPART * p, int memtype, int size) werror = 1; } - if (p->mem[memtype].banked) { - if (((i % p->mem[memtype].bank_size) == p->mem[memtype].bank_size-1) || + if (p->mem[memtype].paged) { + if (((i % p->mem[memtype].page_size) == p->mem[memtype].page_size-1) || (i == wsize-1)) { - rc = avr_write_bank(fd, p, memtype, i/p->mem[memtype].bank_size); + rc = avr_write_page(fd, p, memtype, i/p->mem[memtype].page_size); if (rc) { fprintf(stderr, - " *** bank %ld (addresses 0x%04lx - 0x%04lx) failed to write\n", - i % p->mem[memtype].bank_size, - i-p->mem[memtype].bank_size+1, i); + " *** page %ld (addresses 0x%04lx - 0x%04lx) failed to write\n", + i % p->mem[memtype].page_size, + i-p->mem[memtype].page_size+1, i); fprintf(stderr, "\n"); LED_ON(fd, pgm->pinno[PIN_LED_ERR]); werror = 1; @@ -717,18 +715,24 @@ void avr_mem_display(char * prefix, FILE * f, AVRMEM * m, int type) { if (m == NULL) { fprintf(f, - "%sMem Bank Polled\n" - "%sType Banked Size Size #Banks MinW MaxW ReadBack\n" - "%s------ ------ ------ ---- ------ ----- ----- ---------\n", + "%sMem Page Page Polled\n" + "%sType Paged Size Size Shift #Pages MinW MaxW ReadBack\n" + "%s------ ------ ------ ---- ----- ------ ----- ----- ---------\n", prefix, prefix, prefix); } else { fprintf(f, - "%s%-6s %-6s %6d %4d %6d %5d %5d 0x%02x 0x%02x\n", - prefix, avr_memtstr(type), m->banked ? "yes" : "no", - m->size, m->bank_size, m->num_banks, - m->min_write_delay, m->max_write_delay, - m->readback[0], m->readback[1]); + "%s%-6s %-6s %6d %4d %5d %6d %5d %5d 0x%02x 0x%02x\n", + prefix, avr_memtstr(type), + m->paged ? "yes" : "no", + m->size, + m->page_size, + m->pageaddr_shift, + m->num_pages, + m->min_write_delay, + m->max_write_delay, + m->readback[0], + m->readback[1]); } } diff --git a/avrdude/avr.h b/avrdude/avr.h index add89a0b..3444e2ed 100644 --- a/avrdude/avr.h +++ b/avrdude/avr.h @@ -46,11 +46,11 @@ #define AVR_MAXMEMTYPES 2 /* just flash and eeprom */ typedef struct avrmem { - int banked; /* bank addressed (e.g. ATmega flash) */ + int paged; /* page addressed (e.g. ATmega flash) */ int size; /* total memory size in bytes */ - int bank_size; /* size of memory bank (if bank addressed) */ - int num_banks; /* number of banks (if bank addressed) */ - int bankaddrbits; /* number of bits in the bank address */ + int page_size; /* size of memory page (if page addressed) */ + int num_pages; /* number of pages (if page addressed) */ + int pageaddr_shift; /* number of bits in the page address */ int min_write_delay; /* microseconds */ int max_write_delay; /* microseconds */ unsigned char readback[2]; /* polled read-back values */ diff --git a/avrdude/avrdude.conf.sample b/avrdude/avrdude.conf.sample index 2cbc1014..d5e95e00 100644 --- a/avrdude/avrdude.conf.sample +++ b/avrdude/avrdude.conf.sample @@ -31,20 +31,20 @@ # desc = ; # quoted string # chip_erase_delay = ; # micro-seconds # eeprom -# banked = ; # yes / no +# paged = ; # yes / no # size = ; # bytes -# bank_size = ; # bytes -# num_banks = ; # numeric +# page_size = ; # bytes +# num_pages = ; # numeric # min_write_delay = ; # micro-seconds # max_write_delay = ; # micro-seconds # readback_p1 = ; # byte value # readback_p2 = ; # byte value # ; # flash -# banked = ; # yes / no +# paged = ; # yes / no # size = ; # bytes -# bank_size = ; # bytes -# num_banks = ; # numeric +# page_size = ; # bytes +# num_pages = ; # numeric # min_write_delay = ; # micro-seconds # max_write_delay = ; # micro-seconds # readback_p1 = ; # byte value @@ -99,20 +99,20 @@ part desc = "AT90S1200"; chip_erase_delay = 20000; eeprom - banked = no; + paged = no; size = 64; - bank_size = 0; - num_banks = 0; + page_size = 0; + num_pages = 0; min_write_delay = 9000; max_write_delay = 20000; readback_p1 = 0x00; readback_p2 = 0xff; ; flash - banked = no; + paged = no; size = 1024; - bank_size = 0; - num_banks = 0; + page_size = 0; + num_pages = 0; min_write_delay = 9000; max_write_delay = 20000; readback_p1 = 0xff; @@ -126,20 +126,20 @@ part desc = "AT90S2313"; chip_erase_delay = 20000; eeprom - banked = no; + paged = no; size = 128; - bank_size = 0; - num_banks = 0; + page_size = 0; + num_pages = 0; min_write_delay = 9000; max_write_delay = 20000; readback_p1 = 0x80; readback_p2 = 0x7f; ; flash - banked = no; + paged = no; size = 2048; - bank_size = 0; - num_banks = 0; + page_size = 0; + num_pages = 0; min_write_delay = 9000; max_write_delay = 20000; readback_p1 = 0x7f; @@ -153,20 +153,20 @@ part desc = "AT90S2333"; chip_erase_delay = 20000; eeprom - banked = no; + paged = no; size = 128; - bank_size = 0; - num_banks = 0; + page_size = 0; + num_pages = 0; min_write_delay = 9000; max_write_delay = 20000; readback_p1 = 0x00; readback_p2 = 0xff; ; flash - banked = no; + paged = no; size = 2048; - bank_size = 0; - num_banks = 0; + page_size = 0; + num_pages = 0; min_write_delay = 9000; max_write_delay = 20000; readback_p1 = 0xff; @@ -180,20 +180,20 @@ part desc = "AT90S4433"; chip_erase_delay = 20000; eeprom - banked = no; + paged = no; size = 256; - bank_size = 0; - num_banks = 0; + page_size = 0; + num_pages = 0; min_write_delay = 9000; max_write_delay = 20000; readback_p1 = 0x00; readback_p2 = 0xff; ; flash - banked = no; + paged = no; size = 4096; - bank_size = 0; - num_banks = 0; + page_size = 0; + num_pages = 0; min_write_delay = 9000; max_write_delay = 20000; readback_p1 = 0xff; @@ -207,20 +207,20 @@ part desc = "AT90S4434"; chip_erase_delay = 20000; eeprom - banked = no; + paged = no; size = 256; - bank_size = 0; - num_banks = 0; + page_size = 0; + num_pages = 0; min_write_delay = 9000; max_write_delay = 20000; readback_p1 = 0x00; readback_p2 = 0xff; ; flash - banked = no; + paged = no; size = 4096; - bank_size = 0; - num_banks = 0; + page_size = 0; + num_pages = 0; min_write_delay = 9000; max_write_delay = 20000; readback_p1 = 0xff; @@ -234,20 +234,20 @@ part desc = "AT90S8515"; chip_erase_delay = 20000; eeprom - banked = no; + paged = no; size = 512; - bank_size = 0; - num_banks = 0; + page_size = 0; + num_pages = 0; min_write_delay = 9000; max_write_delay = 20000; readback_p1 = 0x80; readback_p2 = 0x7f; ; flash - banked = no; + paged = no; size = 8192; - bank_size = 0; - num_banks = 0; + page_size = 0; + num_pages = 0; min_write_delay = 9000; max_write_delay = 20000; readback_p1 = 0x7f; @@ -261,20 +261,20 @@ part desc = "AT90S8535"; chip_erase_delay = 20000; eeprom - banked = no; + paged = no; size = 512; - bank_size = 0; - num_banks = 0; + page_size = 0; + num_pages = 0; min_write_delay = 9000; max_write_delay = 20000; readback_p1 = 0x00; readback_p2 = 0xff; ; flash - banked = no; + paged = no; size = 8192; - bank_size = 0; - num_banks = 0; + page_size = 0; + num_pages = 0; min_write_delay = 9000; max_write_delay = 20000; readback_p1 = 0xff; @@ -288,20 +288,20 @@ part desc = "ATMEGA103"; chip_erase_delay = 112000; eeprom - banked = no; + paged = no; size = 4096; - bank_size = 0; - num_banks = 0; + page_size = 0; + num_pages = 0; min_write_delay = 4000; max_write_delay = 9000; readback_p1 = 0x00; readback_p2 = 0xff; ; flash - banked = yes; + paged = yes; size = 131072; - bank_size = 256; - num_banks = 512; + page_size = 256; + num_pages = 512; min_write_delay = 22000; max_write_delay = 56000; readback_p1 = 0xff; @@ -315,20 +315,20 @@ part desc = "ATMEGA16"; chip_erase_delay = 9000; eeprom - banked = no; + paged = no; size = 512; - bank_size = 0; - num_banks = 0; + page_size = 0; + num_pages = 0; min_write_delay = 9000; max_write_delay = 9000; readback_p1 = 0xff; readback_p2 = 0xff; ; flash - banked = yes; + paged = yes; size = 16384; - bank_size = 128; - num_banks = 128; + page_size = 128; + num_pages = 128; min_write_delay = 4500; max_write_delay = 9000; readback_p1 = 0xff; diff --git a/avrdude/config_gram.y b/avrdude/config_gram.y index 5c1a8bbe..2a716c1a 100644 --- a/avrdude/config_gram.y +++ b/avrdude/config_gram.y @@ -29,8 +29,8 @@ /* $Id$ */ -%token K_BANK_SIZE -%token K_BANKED +%token K_PAGE_SIZE +%token K_PAGEED %token K_BUFF %token K_CHIP_ERASE_DELAY %token K_DESC @@ -38,23 +38,27 @@ %token K_ERRLED %token K_FLASH %token K_ID +%token K_LOADPAGE %token K_MAX_WRITE_DELAY %token K_MIN_WRITE_DELAY %token K_MISO %token K_MOSI -%token K_NO -%token K_NUM_BANKS +%token K_NUM_PAGES %token K_PART %token K_PGMLED %token K_PROGRAMMER %token K_RDYLED %token K_READBACK_P1 %token K_READBACK_P2 +%token K_READMEM %token K_RESET %token K_SCK %token K_SIZE %token K_VCC %token K_VFYLED +%token K_WRITEPAGE + +%token K_NO %token K_YES %token TKN_COMMA @@ -103,7 +107,8 @@ part_def : { current_part = avr_new_part(); } part_parms { - unsigned int i, j, pagebits; + unsigned int i, j, shift, psize; + if (current_part->id[0] == 0) { fprintf(stderr, "%s: error at %s:%d: required parameter id not specified\n", @@ -115,46 +120,48 @@ part_def : * perform some sanity checking */ for (i=0; imem[i].banked) { - if (!current_part->mem[i].bank_size) { + if (current_part->mem[i].paged) { + if (!current_part->mem[i].page_size) { fprintf(stderr, - "%s: error at %s:%d: must specify bank_size for banked " + "%s: error at %s:%d: must specify page_size for paged " "memory\n", progname, infile, lineno); exit(1); } - if (!current_part->mem[i].num_banks) { + if (!current_part->mem[i].num_pages) { fprintf(stderr, - "%s: error at %s:%d: must specify num_banks for banked " + "%s: error at %s:%d: must specify num_pages for paged " "memory\n", progname, infile, lineno); exit(1); } - if (current_part->mem[i].size != current_part->mem[i].bank_size * - current_part->mem[i].num_banks) { + if (current_part->mem[i].size != current_part->mem[i].page_size * + current_part->mem[i].num_pages) { fprintf(stderr, - "%s: error at %s:%d: bank size (%u) * num_banks (%u) = " + "%s: error at %s:%d: page size (%u) * num_pages (%u) = " "%u does not match memory size (%u)\n", progname, infile, lineno, - current_part->mem[i].bank_size, - current_part->mem[i].num_banks, - current_part->mem[i].bank_size * current_part->mem[i].num_banks, + current_part->mem[i].page_size, + current_part->mem[i].num_pages, + current_part->mem[i].page_size * current_part->mem[i].num_pages, current_part->mem[i].size); exit(1); } - pagebits = 0; - for (j=0; j<32 && !pagebits; j++) { - if ((1 << j) == current_part->mem[i].num_banks) - pagebits = j; + shift = 0; + psize = current_part->mem[i].page_size / 2 - 1; + for (j=0; j<32 && !shift; j++) { + if ((psize >> j) == 0) { + shift = j; + } } - if (!pagebits) { + if (!shift) { fprintf(stderr, - "%s: error at %s:%d: can't determine the number of bank address bits\n" - " Are you sure num_banks (=%u) is correct?\n", - progname, infile, lineno, current_part->mem[i].num_banks); + "%s: error at %s:%d: can't determine amount to shift for the page address\n" + " Are you sure page_size (=%u) is correct?\n", + progname, infile, lineno, current_part->mem[i].page_size); exit(1); } - current_part->mem[i].bankaddrbits = pagebits; + current_part->mem[i].pageaddr_shift = shift; } } @@ -284,9 +291,9 @@ mem_specs : mem_spec : - K_BANKED TKN_EQUAL yesno + K_PAGED TKN_EQUAL yesno { - current_part->mem[current_mem].banked = $3->primary == K_YES ? 1 : 0; + current_part->mem[current_mem].paged = $3->primary == K_YES ? 1 : 0; free_token($3); } | @@ -297,15 +304,15 @@ mem_spec : } | - K_BANK_SIZE TKN_EQUAL TKN_NUMBER + K_PAGE_SIZE TKN_EQUAL TKN_NUMBER { - current_part->mem[current_mem].bank_size = $3->value.number; + current_part->mem[current_mem].page_size = $3->value.number; free_token($3); } | - K_NUM_BANKS TKN_EQUAL TKN_NUMBER + K_NUM_PAGES TKN_EQUAL TKN_NUMBER { - current_part->mem[current_mem].num_banks = $3->value.number; + current_part->mem[current_mem].num_pages = $3->value.number; free_token($3); } | diff --git a/avrdude/lexer.l b/avrdude/lexer.l index 5e96e779..27487102 100644 --- a/avrdude/lexer.l +++ b/avrdude/lexer.l @@ -123,8 +123,8 @@ SIGN [+-] exit(1); } } -bank_size { yylval=NULL; return K_BANK_SIZE; } -banked { yylval=NULL; return K_BANKED; } +bank_size { yylval=NULL; return K_PAGE_SIZE; } +banked { yylval=NULL; return K_PAGED; } buff { yylval=NULL; return K_BUFF; } chip_erase_delay { yylval=NULL; return K_CHIP_ERASE_DELAY; } desc { yylval=NULL; return K_DESC; } @@ -136,7 +136,10 @@ max_write_delay { yylval=NULL; return K_MAX_WRITE_DELAY; } min_write_delay { yylval=NULL; return K_MIN_WRITE_DELAY; } miso { yylval=NULL; return K_MISO; } mosi { yylval=NULL; return K_MOSI; } -num_banks { yylval=NULL; return K_NUM_BANKS; } +num_banks { yylval=NULL; return K_NUM_PAGES; } +num_pages { yylval=NULL; return K_NUM_PAGES; } +page_size { yylval=NULL; return K_PAGE_SIZE; } +paged { yylval=NULL; return K_PAGED; } part { yylval=NULL; return K_PART; } pgmled { yylval=NULL; return K_PGMLED; } programmer { yylval=NULL; return K_PROGRAMMER; } diff --git a/avrdude/term.c b/avrdude/term.c index b529dcc9..fb9ac93f 100644 --- a/avrdude/term.c +++ b/avrdude/term.c @@ -316,8 +316,8 @@ int cmd_write(int fd, struct avrpart * p, int argc, char * argv[]) return -1; } - if (p->mem[memtype].banked) { - fprintf(stderr, "%s (write): sorry, interactive write of bank addressed " + if (p->mem[memtype].paged) { + fprintf(stderr, "%s (write): sorry, interactive write of page addressed " "memory is not supported\n", progname); return -1; }