2013-05-02 11:06:15 +00:00
|
|
|
#include "ac_cfg.h"
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2014-05-19 10:01:59 +00:00
|
|
|
#include "avrdude.h"
|
|
|
|
#include "libavrdude.h"
|
|
|
|
|
2013-05-02 11:06:15 +00:00
|
|
|
#include "usbasp.h"
|
|
|
|
|
|
|
|
#include "avrftdi_tpi.h"
|
|
|
|
#include "avrftdi_private.h"
|
|
|
|
|
2013-05-16 17:11:35 +00:00
|
|
|
#ifndef DO_NOT_BUILD_AVRFTDI
|
2013-05-02 11:06:15 +00:00
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
static void avrftdi_tpi_disable(const PROGRAMMER *);
|
|
|
|
static int avrftdi_tpi_program_enable(const PROGRAMMER *pgm, const AVRPART *p);
|
2013-05-02 11:06:45 +00:00
|
|
|
|
2013-09-02 20:22:53 +00:00
|
|
|
#ifdef notyet
|
2013-05-02 11:06:15 +00:00
|
|
|
static void
|
|
|
|
avrftdi_debug_frame(uint16_t frame)
|
|
|
|
{
|
|
|
|
static char bit_name[] = "IDLES01234567PSS";
|
|
|
|
//static char bit_name[] = "SSP76543210SELDI";
|
|
|
|
char line0[34], line1[34], line2[34];
|
|
|
|
int bit, pos;
|
|
|
|
|
|
|
|
for(bit = 0; bit < 16; bit++)
|
|
|
|
{
|
|
|
|
pos = 16 - bit - 1;
|
|
|
|
if(frame & (1 << pos))
|
|
|
|
{
|
|
|
|
line0[2*pos] = '_';
|
|
|
|
line0[2*pos+1] = ' ';
|
|
|
|
|
|
|
|
line2[2*pos] = ' ';
|
|
|
|
line2[2*pos+1] = ' ';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
line0[2*pos] = ' ';
|
|
|
|
line0[2*pos+1] = ' ';
|
|
|
|
|
|
|
|
line2[2*pos] = '-';
|
|
|
|
line2[2*pos+1] = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
line1[2*pos] = bit_name[pos];
|
|
|
|
line1[2*pos+1] = ' ';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
line0[32] = 0;
|
|
|
|
line1[32] = 0;
|
|
|
|
line2[32] = 0;
|
|
|
|
|
2013-05-02 11:06:22 +00:00
|
|
|
log_debug("%s\n", line0);
|
|
|
|
log_debug("%s\n", line1);
|
|
|
|
//log_debug("%s\n", line2);
|
2013-05-02 11:06:15 +00:00
|
|
|
}
|
2013-09-02 20:22:53 +00:00
|
|
|
#endif /* notyet */
|
2013-05-02 11:06:15 +00:00
|
|
|
|
|
|
|
int
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
avrftdi_tpi_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
|
2013-05-02 11:06:15 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
avrftdi_t* pdata = to_pdata(pgm);
|
|
|
|
unsigned char buf[] = { MPSSE_DO_WRITE | MPSSE_WRITE_NEG | MPSSE_LSB, 0x01, 0x00, 0xff, 0xff };
|
|
|
|
|
2013-05-02 11:06:22 +00:00
|
|
|
log_info("Setting /Reset pin low\n");
|
2013-05-06 11:48:08 +00:00
|
|
|
pgm->setpin(pgm, PIN_AVR_RESET, OFF);
|
|
|
|
pgm->setpin(pgm, PIN_AVR_SCK, OFF);
|
|
|
|
pgm->setpin(pgm, PIN_AVR_MOSI, ON);
|
2013-05-02 11:06:15 +00:00
|
|
|
usleep(20 * 1000);
|
|
|
|
|
2013-05-06 11:48:08 +00:00
|
|
|
pgm->setpin(pgm, PIN_AVR_RESET, ON);
|
2013-05-02 11:06:15 +00:00
|
|
|
/* worst case 128ms */
|
|
|
|
usleep(2 * 128 * 1000);
|
|
|
|
|
|
|
|
/*setting rst back to 0 */
|
2013-05-06 11:48:08 +00:00
|
|
|
pgm->setpin(pgm, PIN_AVR_RESET, OFF);
|
2013-05-02 11:06:15 +00:00
|
|
|
/*wait at least 20ms bevor issuing spi commands to avr */
|
|
|
|
usleep(20 * 1000);
|
|
|
|
|
2013-05-02 11:07:00 +00:00
|
|
|
log_info("Sending 16 init clock cycles ...\n");
|
2013-05-02 11:06:15 +00:00
|
|
|
ret = ftdi_write_data(pdata->ftdic, buf, sizeof(buf));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
|
|
|
|
void avrftdi_tpi_initpgm(PROGRAMMER *pgm) {
|
|
|
|
log_info("Using TPI interface\n");
|
|
|
|
|
|
|
|
pgm->program_enable = avrftdi_tpi_program_enable;
|
|
|
|
pgm->cmd_tpi = avrftdi_cmd_tpi;
|
|
|
|
pgm->chip_erase = avr_tpi_chip_erase;
|
|
|
|
pgm->disable = avrftdi_tpi_disable;
|
|
|
|
|
|
|
|
pgm->paged_load = NULL;
|
|
|
|
pgm->paged_write = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-02 11:06:52 +00:00
|
|
|
#define TPI_PARITY_MASK 0x2000
|
2013-05-02 11:06:15 +00:00
|
|
|
|
2022-01-08 15:08:35 +00:00
|
|
|
static inline int count1s(unsigned int x)
|
|
|
|
{
|
|
|
|
#if defined(__GNUC__)
|
|
|
|
return __builtin_popcount(x);
|
|
|
|
#else
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
while (x)
|
|
|
|
{
|
|
|
|
count += x & 1;
|
|
|
|
x >>= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-05-02 11:06:15 +00:00
|
|
|
static uint16_t
|
|
|
|
tpi_byte2frame(uint8_t byte)
|
|
|
|
{
|
|
|
|
uint16_t frame = 0xc00f;
|
2022-01-08 15:08:35 +00:00
|
|
|
int parity = count1s(byte) & 1;
|
2013-05-02 11:06:15 +00:00
|
|
|
|
|
|
|
frame |= ((byte << 5) & 0x1fe0);
|
|
|
|
|
|
|
|
if(parity)
|
2013-05-02 11:06:52 +00:00
|
|
|
frame |= TPI_PARITY_MASK;
|
2013-05-02 11:06:15 +00:00
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
tpi_frame2byte(uint16_t frame, uint8_t * byte)
|
|
|
|
{
|
2013-05-02 11:06:52 +00:00
|
|
|
/* drop idle and start bit(s) */
|
|
|
|
*byte = (frame >> 5) & 0xff;
|
2013-05-02 11:06:15 +00:00
|
|
|
|
2022-01-08 15:08:35 +00:00
|
|
|
int parity = count1s(*byte) & 1;
|
2013-05-02 11:06:52 +00:00
|
|
|
int parity_rcvd = (frame & TPI_PARITY_MASK) ? 1 : 0;
|
2013-05-02 11:06:15 +00:00
|
|
|
|
|
|
|
return parity != parity_rcvd;
|
|
|
|
}
|
|
|
|
|
2013-09-02 20:22:53 +00:00
|
|
|
#ifdef notyet
|
2013-05-02 11:06:15 +00:00
|
|
|
static int
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
avrftdi_tpi_break(const PROGRAMMER *pgm) {
|
2013-05-02 11:06:37 +00:00
|
|
|
unsigned char buffer[] = { MPSSE_DO_WRITE | MPSSE_WRITE_NEG | MPSSE_LSB, 1, 0, 0, 0 };
|
2013-05-02 11:06:15 +00:00
|
|
|
E(ftdi_write_data(to_pdata(pgm)->ftdic, buffer, sizeof(buffer)) != sizeof(buffer), to_pdata(pgm)->ftdic);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2013-09-02 20:22:53 +00:00
|
|
|
#endif /* notyet */
|
2013-05-02 11:06:15 +00:00
|
|
|
|
|
|
|
static int
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
avrftdi_tpi_write_byte(const PROGRAMMER *pgm, unsigned char byte) {
|
2013-05-02 11:06:15 +00:00
|
|
|
uint16_t frame;
|
|
|
|
|
|
|
|
struct ftdi_context* ftdic = to_pdata(pgm)->ftdic;
|
|
|
|
|
|
|
|
unsigned char buffer[] = { MPSSE_DO_WRITE | MPSSE_WRITE_NEG | MPSSE_LSB, 1, 0, 0, 0 };
|
|
|
|
|
|
|
|
frame = tpi_byte2frame(byte);
|
|
|
|
|
|
|
|
buffer[3] = frame & 0xff;
|
|
|
|
buffer[4] = frame >> 8;
|
|
|
|
|
2013-05-02 11:07:00 +00:00
|
|
|
log_trace("Byte %02x, frame: %04x, MPSSE: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
|
|
|
|
byte, frame, buffer[0], buffer[1], buffer[2], buffer[3], buffer[4]);
|
2013-05-02 11:06:15 +00:00
|
|
|
|
2013-05-02 11:07:00 +00:00
|
|
|
//avrftdi_debug_frame(frame);
|
2013-05-02 11:06:15 +00:00
|
|
|
|
|
|
|
E(ftdi_write_data(ftdic, buffer, sizeof(buffer)) != sizeof(buffer), ftdic);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-02 11:06:52 +00:00
|
|
|
#define TPI_FRAME_SIZE 12
|
|
|
|
#define TPI_IDLE_BITS 2
|
|
|
|
|
2013-05-02 11:06:15 +00:00
|
|
|
static int
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
avrftdi_tpi_read_byte(const PROGRAMMER *pgm, unsigned char *byte) {
|
2013-05-02 11:06:15 +00:00
|
|
|
uint16_t frame;
|
|
|
|
|
2013-05-02 11:06:52 +00:00
|
|
|
/* use 2 guard bits, 2 default idle bits + 12 frame bits = 16 bits total */
|
|
|
|
const int bytes = 3;
|
|
|
|
int err, i = 0;
|
|
|
|
|
|
|
|
unsigned char buffer[4];
|
2013-05-02 11:06:15 +00:00
|
|
|
|
2013-05-02 11:07:00 +00:00
|
|
|
buffer[0] = MPSSE_DO_READ | MPSSE_LSB;
|
2013-05-02 11:06:15 +00:00
|
|
|
buffer[1] = (bytes-1) & 0xff;
|
|
|
|
buffer[2] = ((bytes-1) >> 8) & 0xff;
|
|
|
|
buffer[3] = SEND_IMMEDIATE;
|
|
|
|
|
2013-05-02 11:07:00 +00:00
|
|
|
log_trace("MPSSE: 0x%02x 0x%02x 0x%02x 0x%02x (Read frame)\n",
|
2013-05-02 11:06:15 +00:00
|
|
|
buffer[0], buffer[1], buffer[2], buffer[3]);
|
|
|
|
|
|
|
|
ftdi_write_data(to_pdata(pgm)->ftdic, buffer, 4);
|
|
|
|
|
|
|
|
memset(buffer, 0, sizeof(buffer));
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
do {
|
2013-05-02 11:06:52 +00:00
|
|
|
int err = ftdi_read_data(to_pdata(pgm)->ftdic, &buffer[i], bytes - i);
|
|
|
|
E(err < 0, to_pdata(pgm)->ftdic);
|
|
|
|
i += err;
|
2013-05-02 11:06:15 +00:00
|
|
|
} while(i < bytes);
|
|
|
|
|
|
|
|
|
2013-05-02 11:06:52 +00:00
|
|
|
log_trace("MPSSE: 0x%02x 0x%02x 0x%02x 0x%02x (Read frame)\n",
|
|
|
|
buffer[0], buffer[1], buffer[2], buffer[3]);
|
|
|
|
|
2013-05-02 11:06:15 +00:00
|
|
|
|
2013-05-02 11:06:52 +00:00
|
|
|
frame = buffer[0] | (buffer[1] << 8);
|
|
|
|
|
|
|
|
err = tpi_frame2byte(frame, byte);
|
|
|
|
log_trace("Frame: 0x%04x, byte: 0x%02x\n", frame, *byte);
|
|
|
|
|
|
|
|
//avrftdi_debug_frame(frame);
|
2013-05-02 11:06:15 +00:00
|
|
|
|
2013-05-02 11:06:52 +00:00
|
|
|
return err;
|
2013-05-02 11:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
avrftdi_tpi_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
|
2013-05-06 12:50:42 +00:00
|
|
|
return avr_tpi_program_enable(pgm, p, TPIPCR_GT_2b);
|
2013-05-02 11:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
avrftdi_cmd_tpi(const PROGRAMMER *pgm, const unsigned char *cmd, int cmd_len,
|
2013-09-02 20:22:53 +00:00
|
|
|
unsigned char *res, int res_len)
|
2013-05-02 11:06:15 +00:00
|
|
|
{
|
|
|
|
int i, err = 0;
|
|
|
|
|
|
|
|
for(i = 0; i < cmd_len; i++)
|
|
|
|
{
|
|
|
|
err = avrftdi_tpi_write_byte(pgm, cmd[i]);
|
|
|
|
if(err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < res_len; i++)
|
|
|
|
{
|
|
|
|
err = avrftdi_tpi_read_byte(pgm, &res[i]);
|
|
|
|
if(err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-02 11:06:45 +00:00
|
|
|
static void
|
Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:
- Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
const AVRPART *p); this allows changes in the PROGRAMMER structure after
the part is known. For example, use TPI, UPDI, PDI functions in that
programmer appropriate to the part. This used to be done later in the
process, eg, in the initialize() function, which "taints" all other
programmer functions wrt const and sometimes requires other finessing with
flags etc. Much clearer with the modified enable() interface.
- Move TPI initpgm-type code from initialize() to enable() --- note that
initpgm() does not have the info at the time when it is called whether or
not TPI is required
- buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
modification of the flag does not change PROGRAMMER structure)
- Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
FLAGS32_WRITE bits
- Move the xbeeResetPin component to private data in stk500.c as this is
needed by xbee when it saddles on the stk500 code (previously, the flags
component of the part was re-dedicated to this)
- Change the way the "chained" private data are used in jtag3.c whilst
keeping the PROGRAMMER structure read-only otherwise
- In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
(for const assertion).
- In usbasp change the code from changing PROGRAMMER functions late to
dispatching to TPI or regular SPI protocol functions at runtime; reason
being the decision whether to use TPI protocol is done at run-time
depending on the capability of the attached programmer
Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 15:05:28 +00:00
|
|
|
avrftdi_tpi_disable(const PROGRAMMER *pgm) {
|
2013-05-03 12:58:15 +00:00
|
|
|
unsigned char cmd[] = {TPI_OP_SSTCS(TPIPCR), 0};
|
|
|
|
pgm->cmd_tpi(pgm, cmd, sizeof(cmd), NULL, 0);
|
|
|
|
|
2013-05-02 11:06:45 +00:00
|
|
|
log_info("Leaving Programming mode.\n");
|
2013-05-02 11:06:15 +00:00
|
|
|
}
|
|
|
|
|
2013-05-16 17:11:35 +00:00
|
|
|
#endif /* DO_NOT_BUILD_AVRFTDI */
|
2013-05-02 11:06:15 +00:00
|
|
|
|