Remove tabs and reformat
This commit is contained in:
parent
c3413ff0f4
commit
2b3534ea8a
104
src/avr.c
104
src/avr.c
|
@ -49,7 +49,7 @@ int avr_tpi_poll_nvmbsy(const PROGRAMMER *pgm) {
|
||||||
|
|
||||||
/* TPI chip erase sequence */
|
/* TPI chip erase sequence */
|
||||||
int avr_tpi_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
|
int avr_tpi_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
|
||||||
int err;
|
int err;
|
||||||
AVRMEM *mem;
|
AVRMEM *mem;
|
||||||
|
|
||||||
if (p->prog_modes & PM_TPI) {
|
if (p->prog_modes & PM_TPI) {
|
||||||
|
@ -62,27 +62,27 @@ int avr_tpi_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char cmd[] = {
|
unsigned char cmd[] = {
|
||||||
/* write pointer register high byte */
|
/* write pointer register high byte */
|
||||||
(TPI_CMD_SSTPR | 0),
|
(TPI_CMD_SSTPR | 0),
|
||||||
((mem->offset & 0xFF) | 1),
|
((mem->offset & 0xFF) | 1),
|
||||||
/* and low byte */
|
/* and low byte */
|
||||||
(TPI_CMD_SSTPR | 1),
|
(TPI_CMD_SSTPR | 1),
|
||||||
((mem->offset >> 8) & 0xFF),
|
((mem->offset >> 8) & 0xFF),
|
||||||
/* write CHIP_ERASE command to NVMCMD register */
|
/* write CHIP_ERASE command to NVMCMD register */
|
||||||
(TPI_CMD_SOUT | TPI_SIO_ADDR(TPI_IOREG_NVMCMD)),
|
(TPI_CMD_SOUT | TPI_SIO_ADDR(TPI_IOREG_NVMCMD)),
|
||||||
TPI_NVMCMD_CHIP_ERASE,
|
TPI_NVMCMD_CHIP_ERASE,
|
||||||
/* write dummy value to start erase */
|
/* write dummy value to start erase */
|
||||||
TPI_CMD_SST,
|
TPI_CMD_SST,
|
||||||
0xFF
|
0xFF
|
||||||
};
|
};
|
||||||
|
|
||||||
while (avr_tpi_poll_nvmbsy(pgm))
|
while (avr_tpi_poll_nvmbsy(pgm))
|
||||||
;
|
;
|
||||||
|
|
||||||
err = pgm->cmd_tpi(pgm, cmd, sizeof(cmd), NULL, 0);
|
err = pgm->cmd_tpi(pgm, cmd, sizeof(cmd), NULL, 0);
|
||||||
if(err)
|
if(err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
while (avr_tpi_poll_nvmbsy(pgm));
|
while (avr_tpi_poll_nvmbsy(pgm));
|
||||||
|
|
||||||
|
@ -97,56 +97,56 @@ int avr_tpi_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
|
||||||
|
|
||||||
/* TPI program enable sequence */
|
/* TPI program enable sequence */
|
||||||
int avr_tpi_program_enable(const PROGRAMMER *pgm, const AVRPART *p, unsigned char guard_time) {
|
int avr_tpi_program_enable(const PROGRAMMER *pgm, const AVRPART *p, unsigned char guard_time) {
|
||||||
int err, retry;
|
int err, retry;
|
||||||
unsigned char cmd[2];
|
unsigned char cmd[2];
|
||||||
unsigned char response;
|
unsigned char response;
|
||||||
|
|
||||||
if(p->prog_modes & PM_TPI) {
|
if(p->prog_modes & PM_TPI) {
|
||||||
/* set guard time */
|
/* set guard time */
|
||||||
cmd[0] = (TPI_CMD_SSTCS | TPI_REG_TPIPCR);
|
cmd[0] = (TPI_CMD_SSTCS | TPI_REG_TPIPCR);
|
||||||
cmd[1] = guard_time;
|
cmd[1] = guard_time;
|
||||||
|
|
||||||
err = pgm->cmd_tpi(pgm, cmd, sizeof(cmd), NULL, 0);
|
err = pgm->cmd_tpi(pgm, cmd, sizeof(cmd), NULL, 0);
|
||||||
if(err)
|
if(err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
/* read TPI ident reg */
|
/* read TPI ident reg */
|
||||||
cmd[0] = (TPI_CMD_SLDCS | TPI_REG_TPIIR);
|
cmd[0] = (TPI_CMD_SLDCS | TPI_REG_TPIIR);
|
||||||
err = pgm->cmd_tpi(pgm, cmd, 1, &response, sizeof(response));
|
err = pgm->cmd_tpi(pgm, cmd, 1, &response, sizeof(response));
|
||||||
if (err || response != TPI_IDENT_CODE) {
|
if (err || response != TPI_IDENT_CODE) {
|
||||||
pmsg_error("TPIIR not correct\n");
|
pmsg_error("TPIIR not correct\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* send SKEY command + SKEY */
|
/* send SKEY command + SKEY */
|
||||||
err = pgm->cmd_tpi(pgm, tpi_skey_cmd, sizeof(tpi_skey_cmd), NULL, 0);
|
err = pgm->cmd_tpi(pgm, tpi_skey_cmd, sizeof(tpi_skey_cmd), NULL, 0);
|
||||||
if(err)
|
if(err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
/* check if device is ready */
|
/* check if device is ready */
|
||||||
for(retry = 0; retry < 10; retry++)
|
for(retry = 0; retry < 10; retry++)
|
||||||
{
|
{
|
||||||
cmd[0] = (TPI_CMD_SLDCS | TPI_REG_TPISR);
|
cmd[0] = (TPI_CMD_SLDCS | TPI_REG_TPISR);
|
||||||
err = pgm->cmd_tpi(pgm, cmd, 1, &response, sizeof(response));
|
err = pgm->cmd_tpi(pgm, cmd, 1, &response, sizeof(response));
|
||||||
if(err || !(response & TPI_REG_TPISR_NVMEN))
|
if(err || !(response & TPI_REG_TPISR_NVMEN))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pmsg_error("target does not reply when enabling TPI external programming mode\n");
|
pmsg_error("target does not reply when enabling TPI external programming mode\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
pmsg_error("part has no TPI\n");
|
pmsg_error("part has no TPI\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TPI: setup NVMCMD register and pointer register (PR) for read/write/erase */
|
/* TPI: setup NVMCMD register and pointer register (PR) for read/write/erase */
|
||||||
static int avr_tpi_setup_rw(const PROGRAMMER *pgm, const AVRMEM *mem,
|
static int avr_tpi_setup_rw(const PROGRAMMER *pgm, const AVRMEM *mem,
|
||||||
unsigned long addr, unsigned char nvmcmd)
|
unsigned long addr, unsigned char nvmcmd) {
|
||||||
{
|
|
||||||
unsigned char cmd[4];
|
unsigned char cmd[4];
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -444,9 +444,7 @@ int avr_read_mem(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *mem, con
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i < mem->size; i++) {
|
for (i=0; i < mem->size; i++) {
|
||||||
if (vmem == NULL ||
|
if (vmem == NULL || (vmem->tags[i] & TAG_ALLOCATED) != 0) {
|
||||||
(vmem->tags[i] & TAG_ALLOCATED) != 0)
|
|
||||||
{
|
|
||||||
rc = pgm->read_byte(pgm, p, mem, i, mem->buf + i);
|
rc = pgm->read_byte(pgm, p, mem, i, mem->buf + i);
|
||||||
if (rc != LIBAVRDUDE_SUCCESS) {
|
if (rc != LIBAVRDUDE_SUCCESS) {
|
||||||
pmsg_error("unable to read byte at address 0x%04lx\n", i);
|
pmsg_error("unable to read byte at address 0x%04lx\n", i);
|
||||||
|
@ -707,9 +705,7 @@ int avr_write_byte_default(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM
|
||||||
gettimeofday (&tv, NULL);
|
gettimeofday (&tv, NULL);
|
||||||
start_time = (tv.tv_sec * 1000000) + tv.tv_usec;
|
start_time = (tv.tv_sec * 1000000) + tv.tv_usec;
|
||||||
do {
|
do {
|
||||||
/*
|
// Do polling, but timeout after max_write_delay
|
||||||
* Do polling, but timeout after max_write_delay.
|
|
||||||
*/
|
|
||||||
rc = pgm->read_byte(pgm, p, mem, addr, &r);
|
rc = pgm->read_byte(pgm, p, mem, addr, &r);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
pgm->pgm_led(pgm, OFF);
|
pgm->pgm_led(pgm, OFF);
|
||||||
|
|
Loading…
Reference in New Issue