* usbtiny.c (usbtiny_paged_load, usbtiny_paged_write):
fix breakage introduced by the recent page handling reorg; it used to cause an infinite loop git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1091 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
parent
dc38f7ca18
commit
07c102e412
|
@ -1,3 +1,9 @@
|
||||||
|
2012-06-07 Joerg Wunsch <j.gnu@uriah.heep.sax.de>
|
||||||
|
|
||||||
|
* usbtiny.c (usbtiny_paged_load, usbtiny_paged_write):
|
||||||
|
fix breakage introduced by the recent page handling reorg;
|
||||||
|
it used to cause an infinite loop
|
||||||
|
|
||||||
2012-05-04 Joerg Wunsch <j.gnu@uriah.heep.sax.de>
|
2012-05-04 Joerg Wunsch <j.gnu@uriah.heep.sax.de>
|
||||||
|
|
||||||
Xmega page erase implementation for XPROG (AVRISPmkII, STK600)
|
Xmega page erase implementation for XPROG (AVRISPmkII, STK600)
|
||||||
|
|
39
usbtiny.c
39
usbtiny.c
|
@ -432,9 +432,9 @@ static void usbtiny_disable ( PROGRAMMER* pgm ) {}
|
||||||
*/
|
*/
|
||||||
static int usbtiny_paged_load (PROGRAMMER * pgm, AVRPART * p, AVRMEM* m,
|
static int usbtiny_paged_load (PROGRAMMER * pgm, AVRPART * p, AVRMEM* m,
|
||||||
unsigned int page_size,
|
unsigned int page_size,
|
||||||
unsigned int i, unsigned int n_bytes)
|
unsigned int addr, unsigned int n_bytes)
|
||||||
{
|
{
|
||||||
unsigned int maxaddr = i + n_bytes;
|
unsigned int maxaddr = addr + n_bytes;
|
||||||
int chunk;
|
int chunk;
|
||||||
int function;
|
int function;
|
||||||
|
|
||||||
|
@ -446,20 +446,16 @@ static int usbtiny_paged_load (PROGRAMMER * pgm, AVRPART * p, AVRMEM* m,
|
||||||
function = USBTINY_EEPROM_READ;
|
function = USBTINY_EEPROM_READ;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; i < maxaddr; i += chunk) {
|
for (; addr < maxaddr; addr += chunk) {
|
||||||
chunk = PDATA(pgm)->chunk_size; // start with the maximum chunk size possible
|
chunk = PDATA(pgm)->chunk_size; // start with the maximum chunk size possible
|
||||||
|
|
||||||
// If we want to xmit less than a chunk, thats OK
|
|
||||||
if (chunk > n_bytes-i)
|
|
||||||
chunk = n_bytes - i;
|
|
||||||
|
|
||||||
// Send the chunk of data to the USBtiny with the function we want
|
// Send the chunk of data to the USBtiny with the function we want
|
||||||
// to perform
|
// to perform
|
||||||
if (usb_in(pgm,
|
if (usb_in(pgm,
|
||||||
function, // EEPROM or flash
|
function, // EEPROM or flash
|
||||||
0, // delay between SPI commands
|
0, // delay between SPI commands
|
||||||
i, // index
|
addr, // address in memory
|
||||||
m->buf + i, // pointer to where we store data
|
m->buf + addr, // pointer to where we store data
|
||||||
chunk, // number of bytes
|
chunk, // number of bytes
|
||||||
32 * PDATA(pgm)->sck_period) // each byte gets turned into a 4-byte SPI cmd
|
32 * PDATA(pgm)->sck_period) // each byte gets turned into a 4-byte SPI cmd
|
||||||
< 0) {
|
< 0) {
|
||||||
|
@ -479,9 +475,9 @@ static int usbtiny_paged_load (PROGRAMMER * pgm, AVRPART * p, AVRMEM* m,
|
||||||
*/
|
*/
|
||||||
static int usbtiny_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
|
static int usbtiny_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
|
||||||
unsigned int page_size,
|
unsigned int page_size,
|
||||||
unsigned int i, unsigned int n_bytes)
|
unsigned int addr, unsigned int n_bytes)
|
||||||
{
|
{
|
||||||
unsigned int maxaddr = i + n_bytes;
|
unsigned int maxaddr = addr + n_bytes;
|
||||||
int chunk; // Size of data to write at once
|
int chunk; // Size of data to write at once
|
||||||
int next;
|
int next;
|
||||||
int function; // which SPI command to use
|
int function; // which SPI command to use
|
||||||
|
@ -496,14 +492,15 @@ static int usbtiny_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
|
||||||
|
|
||||||
delay = 0;
|
delay = 0;
|
||||||
if (! m->paged) {
|
if (! m->paged) {
|
||||||
|
unsigned int poll_value;
|
||||||
// Does this chip not support paged writes?
|
// Does this chip not support paged writes?
|
||||||
i = (m->readback[1] << 8) | m->readback[0];
|
poll_value = (m->readback[1] << 8) | m->readback[0];
|
||||||
if (usb_control(pgm, USBTINY_POLL_BYTES, i, 0 ) < 0)
|
if (usb_control(pgm, USBTINY_POLL_BYTES, poll_value, 0 ) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
delay = m->max_write_delay;
|
delay = m->max_write_delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; i < maxaddr; i=next) {
|
for (; addr < maxaddr; addr += chunk) {
|
||||||
// start with the max chunk size
|
// start with the max chunk size
|
||||||
chunk = PDATA(pgm)->chunk_size;
|
chunk = PDATA(pgm)->chunk_size;
|
||||||
|
|
||||||
|
@ -511,15 +508,11 @@ static int usbtiny_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
|
||||||
if (m->paged && chunk > page_size)
|
if (m->paged && chunk > page_size)
|
||||||
chunk = page_size;
|
chunk = page_size;
|
||||||
|
|
||||||
// if there's less data remaining than one chunk
|
|
||||||
if (chunk > n_bytes-i)
|
|
||||||
chunk = n_bytes - i;
|
|
||||||
|
|
||||||
if (usb_out(pgm,
|
if (usb_out(pgm,
|
||||||
function, // Flash or EEPROM
|
function, // Flash or EEPROM
|
||||||
delay, // How much to wait between each byte
|
delay, // How much to wait between each byte
|
||||||
i, // Index of data
|
addr, // Address in memory
|
||||||
m->buf + i, // Pointer to data
|
m->buf + addr, // Pointer to data
|
||||||
chunk, // Number of bytes to write
|
chunk, // Number of bytes to write
|
||||||
32 * PDATA(pgm)->sck_period + delay // each byte gets turned into a
|
32 * PDATA(pgm)->sck_period + delay // each byte gets turned into a
|
||||||
// 4-byte SPI cmd usb_out() multiplies
|
// 4-byte SPI cmd usb_out() multiplies
|
||||||
|
@ -528,11 +521,11 @@ static int usbtiny_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
next = i + chunk; // Calculate what address we're at now
|
next = addr + chunk; // Calculate what address we're at now
|
||||||
if (m->paged
|
if (m->paged
|
||||||
&& ((next % page_size) == 0 || next == n_bytes) ) {
|
&& ((next % page_size) == 0 || next == maxaddr) ) {
|
||||||
// If we're at a page boundary, send the SPI command to flush it.
|
// If we're at a page boundary, send the SPI command to flush it.
|
||||||
avr_write_page(pgm, p, m, (unsigned long) i);
|
avr_write_page(pgm, p, m, (unsigned long) addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return n_bytes;
|
return n_bytes;
|
||||||
|
|
Loading…
Reference in New Issue