avrftdi_tpi.c: Update I/O to pgm->cmd_tpi

All I/O of avrftdi_tpi is done in terms of pgm->cmd_tpi() calls instead
of calling avrftdi_tpi_[read,write]_byte() functions directly.

git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@1158 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
Hannes Weisbach 2013-05-03 12:58:15 +00:00
parent 171be6ed47
commit 1d29bd71df
2 changed files with 37 additions and 31 deletions

View File

@ -2,6 +2,8 @@
* avrftdi_private.h: Remove update forward declaration from avrftdi_print to * avrftdi_private.h: Remove update forward declaration from avrftdi_print to
avrftdi_log. avrftdi_log.
* avrftdi_tpi.c: Do all I/O in terms of pgm->cmd_tpi()-calls instead of
avrftdi_tpi_[read,write]_byte().
2013-05-02 Hannes Weisbach <hannes_weisbach@gmx.net> 2013-05-02 Hannes Weisbach <hannes_weisbach@gmx.net>

View File

@ -5,6 +5,7 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include "avr.h"
#include "pgm.h" #include "pgm.h"
#include "avrpart.h" #include "avrpart.h"
#include "pindefs.h" #include "pindefs.h"
@ -22,6 +23,8 @@
static void avrftdi_tpi_disable(PROGRAMMER *); static void avrftdi_tpi_disable(PROGRAMMER *);
static const unsigned char tpi_skey_cmd[] = { TPI_CMD_SKEY, 0xff, 0x88, 0xd8, 0xcd, 0x45, 0xab, 0x89, 0x12 };
static void static void
avrftdi_debug_frame(uint16_t frame) avrftdi_debug_frame(uint16_t frame)
{ {
@ -221,26 +224,26 @@ avrftdi_tpi_program_enable(PROGRAMMER * pgm, AVRPART * p)
int retry; int retry;
int err; int err;
int i; int i;
unsigned char byte = 0; unsigned char cmd[2];
unsigned char response;
log_info("TPI program enable\n"); log_info("TPI program enable\n");
/* set guard time */ /* set guard time */
avrftdi_tpi_write_byte(pgm, TPI_OP_SSTCS(TPIPCR)); cmd[0] = TPI_OP_SSTCS(TPIPCR);
avrftdi_tpi_write_byte(pgm, TPIPCR_GT_2b); cmd[1] = TPIPCR_GT_2b;
pgm->cmd_tpi(pgm, cmd, sizeof(cmd), NULL, 0);
/* send SKEY */ /* send SKEY */
avrftdi_tpi_write_byte(pgm, TPI_CMD_SKEY); pgm->cmd_tpi(pgm, tpi_skey_cmd, sizeof(tpi_skey_cmd), NULL, 0);
for(i = sizeof(tpi_skey) - 1; i >= 0; --i)
avrftdi_tpi_write_byte(pgm, tpi_skey[i]);
/* check if device is ready */ /* check if device is ready */
for(retry = 0; retry < 10; retry++) for(retry = 0; retry < 10; retry++)
{ {
log_info("Reading Identification register\n"); log_info("Reading Identification register\n");
avrftdi_tpi_write_byte(pgm, TPI_OP_SLDCS(TPIIR)); cmd[0] = TPI_OP_SLDCS(TPIIR);
err = avrftdi_tpi_read_byte(pgm, &byte); err = pgm->cmd_tpi(pgm, cmd, 1, &response, sizeof(response));
if(err || byte != TPI_IDENT_CODE) if(err || response != TPI_IDENT_CODE)
{ {
log_err("Error. Sending break.\n"); log_err("Error. Sending break.\n");
avrftdi_tpi_break(pgm); avrftdi_tpi_break(pgm);
@ -249,9 +252,9 @@ avrftdi_tpi_program_enable(PROGRAMMER * pgm, AVRPART * p)
} }
log_info("Reading Status register\n"); log_info("Reading Status register\n");
avrftdi_tpi_write_byte(pgm, TPI_OP_SLDCS(TPISR)); cmd[0] = TPI_OP_SLDCS(TPISR);
err = avrftdi_tpi_read_byte(pgm, &byte); err = pgm->cmd_tpi(pgm, cmd, 1, &response, sizeof(response));
if(err || !(byte & TPISR_NVMEN)) if(err || !(response & TPISR_NVMEN))
{ {
log_err("Error. Sending break.\n"); log_err("Error. Sending break.\n");
avrftdi_tpi_break(pgm); avrftdi_tpi_break(pgm);
@ -269,16 +272,16 @@ avrftdi_tpi_program_enable(PROGRAMMER * pgm, AVRPART * p)
static int static int
avrftdi_tpi_nvm_waitbusy(PROGRAMMER * pgm) avrftdi_tpi_nvm_waitbusy(PROGRAMMER * pgm)
{ {
unsigned char byte; const unsigned char cmd = TPI_OP_SIN(NVMCSR);
unsigned char response;
int err; int err;
int retry; int retry;
for(retry = 50; retry > 0; retry--) for(retry = 50; retry > 0; retry--)
{ {
avrftdi_tpi_write_byte(pgm, TPI_OP_SIN(NVMCSR)); pgm->cmd_tpi(pgm, &cmd, sizeof(cmd), &response, sizeof(response));
err = avrftdi_tpi_read_byte(pgm, &byte);
//TODO usleep on bsy? //TODO usleep on bsy?
if(err || (byte & NVMCSR_BSY)) if(err || (response & NVMCSR_BSY))
continue; continue;
return 0; return 0;
} }
@ -312,18 +315,18 @@ avrftdi_cmd_tpi(PROGRAMMER * pgm, unsigned char cmd[], int cmd_len,
int int
avrftdi_tpi_chip_erase(PROGRAMMER * pgm, AVRPART * p) avrftdi_tpi_chip_erase(PROGRAMMER * pgm, AVRPART * p)
{ {
/* Set PR to flash */ unsigned char cmd [] = {
avrftdi_tpi_write_byte(pgm, TPI_OP_SSTPR(0)); TPI_OP_SSTPR(0),
avrftdi_tpi_write_byte(pgm, 0x01); 0x01,
avrftdi_tpi_write_byte(pgm, TPI_OP_SSTPR(1)); TPI_OP_SSTPR(1),
avrftdi_tpi_write_byte(pgm, 0x40); 0x40,
/* select ERASE */ TPI_OP_SOUT(NVMCMD),
avrftdi_tpi_write_byte(pgm, TPI_OP_SOUT(NVMCMD)); NVMCMD_CHIP_ERASE,
avrftdi_tpi_write_byte(pgm, NVMCMD_CHIP_ERASE); TPI_OP_SST_INC,
/* dummy write */ 0x00 };
avrftdi_tpi_write_byte(pgm, TPI_OP_SST_INC); pgm->cmd_tpi(pgm, cmd, sizeof(cmd), NULL, 0);
avrftdi_tpi_write_byte(pgm, 0x00);
avrftdi_tpi_nvm_waitbusy(pgm); avr_tpi_poll_nvmbsy(pgm);
usleep(p->chip_erase_delay); usleep(p->chip_erase_delay);
@ -333,9 +336,10 @@ avrftdi_tpi_chip_erase(PROGRAMMER * pgm, AVRPART * p)
static void static void
avrftdi_tpi_disable(PROGRAMMER * pgm) avrftdi_tpi_disable(PROGRAMMER * pgm)
{ {
unsigned char cmd[] = {TPI_OP_SSTCS(TPIPCR), 0};
pgm->cmd_tpi(pgm, cmd, sizeof(cmd), NULL, 0);
log_info("Leaving Programming mode.\n"); log_info("Leaving Programming mode.\n");
avrftdi_tpi_write_byte(pgm, TPI_OP_SSTCS(TPIPCR));
avrftdi_tpi_write_byte(pgm, 0);
} }
#else /* HAVE_LIBFTDI1 */ #else /* HAVE_LIBFTDI1 */