Bring avrftdi's messaging into the msg_...() fold

This commit is contained in:
Stefan Rueger
2024-04-17 14:28:14 +01:00
parent a3189140e1
commit f6842c9000
3 changed files with 87 additions and 145 deletions

View File

@@ -52,7 +52,8 @@
#ifdef DO_NOT_BUILD_AVRFTDI
static int avrftdi_noftdi_open(PROGRAMMER *pgm, const char *name) {
pmsg_error("no libftdi or libusb support; install libftdi1/libusb-1.0 or libftdi/libusb and run configure/make again\n");
pmsg_error("no libftdi or libusb support\n");
imsg_error("install libftdi1/libusb-1.0 or libftdi/libusb and run configure/make again\n");
return -1;
}
@@ -138,44 +139,6 @@ static char *ftdi_pin_name(avrftdi_t *pdata, struct pindef_t pin) {
return str;
}
/*
* output function, to save if(vebose>level)-constructs. Also prefixes output
* with "avrftdi function-name(line-number):" to identify were messages came
* from.
* This function is the backend of the log_*-macros, but it can be used
* directly.
*/
void avrftdi_log(int level, const char * func, int line,
const char * fmt, ...) {
static int skip_prefix = 0;
const char *p = fmt;
va_list ap;
if(verbose >= level)
{
if(!skip_prefix)
{
switch(level) {
case ERR: msg_error("E "); break;
case WARN: msg_error("W "); break;
case INFO: msg_error("I "); break;
case DEBUG: msg_error("D "); break;
case TRACE: msg_error("T "); break;
default: msg_error(" "); break;
}
msg_error("%s(%d): ", func, line);
}
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
}
skip_prefix = 1;
while(*p++)
if(*p == '\n' && !(*(p+1)))
skip_prefix = 0;
}
/*
* helper function to print a binary buffer *buf of size len. Begin and end of
* the dump are enclosed in the string contained in *desc. Offset denotes the
@@ -186,16 +149,16 @@ static void buf_dump(const unsigned char *buf, int len, char *desc,
int offset, int width)
{
int i;
msg_info("%s begin:\n", desc);
msg_trace2("%s begin:\n", desc);
for (i = 0; i < offset; i++)
msg_info("%02x ", buf[i]);
msg_info("\n");
msg_trace2("%02x ", buf[i]);
msg_trace2("\n");
for (i++; i <= len; i++) {
msg_info("%02x ", buf[i-1]);
msg_trace2("%02x ", buf[i-1]);
if((i-offset) != 0 && (i-offset)%width == 0)
msg_info("\n");
msg_trace2("\n");
}
msg_info("%s end\n", desc);
msg_trace2("%s end\n", desc);
}
/*
@@ -233,19 +196,19 @@ static int set_frequency(avrftdi_t* ftdi, uint32_t freq)
}
if (divisor < 0) {
log_warn("Frequency too high (%u > %u MHz)\n", freq, clock / 2000000);
log_warn("Resetting Frequency to %uMHz\n", clock / 2000000);
pmsg_warning("frequency too high (%u > %u MHz)\n", freq, clock/2/1000000);
imsg_warning("resetting frequency to %u MHz\n", clock/2/1000000);
divisor = 0;
}
if (divisor > 65535) {
log_warn("Frequency too low (%u < %.3f Hz)\n", freq, (float) clock / 2 / 65535);
log_warn("Resetting Frequency to %.3fHz\n", (float) clock / 2 / 65535);
pmsg_warning("frequency too low (%u < %.3f Hz)\n", freq, (double) clock / 2 / 65536);
imsg_warning("resetting frequency to %.3f Hz\n", (double) clock / 2 / 65536);
divisor = 65535;
}
log_info("Using frequency: %d\n", clock / 2 / (divisor + 1));
log_info("Clock divisor: 0x%04x\n", divisor);
pmsg_info("using frequency: %.3f\n", (double) clock / 2 / (divisor + 1));
imsg_info("clock divisor: %d, 0x%04x\n", divisor, divisor);
*ptr++ = TCK_DIVISOR;
*ptr++ = (uint8_t)(divisor & 0xff);
@@ -276,7 +239,7 @@ static int set_pin(const PROGRAMMER *pgm, int pinfunc, int value) {
return 0;
}
log_debug("Setting pin %s (%s) as %s: %s (%s active)\n",
pmsg_debug("setting pin %s (%s) as %s: %s (%s active)\n",
pinmask_to_str(pin.mask), ftdi_pin_name(pdata, pin),
avr_pin_name(pinfunc),
(value) ? "high" : "low", (pin.inverse[0]) ? "low" : "high");
@@ -509,7 +472,7 @@ static int write_flush(avrftdi_t* pdata)
{
unsigned char buf[6];
log_debug("Setting pin direction (0x%04x) and value (0x%04x)\n",
pmsg_debug("setting pin direction (0x%04x) and value (0x%04x)\n",
pdata->pin_direction, pdata->pin_value);
buf[0] = SET_BITS_LOW;
@@ -521,7 +484,7 @@ static int write_flush(avrftdi_t* pdata)
E(ftdi_write_data(pdata->ftdic, buf, 6) != 6, pdata->ftdic);
log_trace("Set pins command: %02x %02x %02x %02x %02x %02x\n",
msg_trace("set pins command: %02x %02x %02x %02x %02x %02x\n",
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
/* we need to flush here, because set_pin is used as reset.
@@ -548,7 +511,7 @@ static int write_flush(avrftdi_t* pdata)
} while(num < 1);
if(num > 1)
log_warn("Read %d extra bytes\n", num-1);
pmsg_warning("read %d extra bytes\n", num-1);
return 0;
@@ -565,7 +528,7 @@ static int avrftdi_check_pins_bb(const PROGRAMMER *pgm, bool output) {
/* value for 8/12/16 bit wide interface */
int valid_mask = ((1 << pdata->pin_limit) - 1);
log_debug("Using valid mask bitbanging: 0x%08x\n", valid_mask);
pmsg_debug("using valid mask bitbanging: 0x%08x\n", valid_mask);
static struct pindef_t valid_pins;
valid_pins.mask[0] = valid_mask;
valid_pins.inverse[0] = valid_mask ;
@@ -607,7 +570,7 @@ static int avrftdi_check_pins_mpsse(const PROGRAMMER *pgm, bool output) {
valid_mask &= ~(1 << FTDI_TMS_CS);
}
log_debug("Using valid mask mpsse: 0x%08x\n", valid_mask);
pmsg_debug("using valid mask mpsse: 0x%08x\n", valid_mask);
static struct pindef_t valid_pins_others;
valid_pins_others.mask[0] = valid_mask;
valid_pins_others.inverse[0] = valid_mask ;
@@ -657,11 +620,11 @@ static int avrftdi_pin_setup(const PROGRAMMER *pgm) {
bool pin_check_bitbanging = (0 == avrftdi_check_pins_bb(pgm, verbose>3));
if (!pin_check_mpsse && !pin_check_bitbanging) {
log_err("No valid pin configuration found.\n");
pmsg_error("no valid pin configuration found\n");
avrftdi_check_pins_bb(pgm, true);
log_err("Pin configuration for FTDI MPSSE must be:\n");
imsg_error("pin configuration for FTDI MPSSE must be:\n");
if (pgm->flag == PGM_FL_IS_JTAG) {
log_err("%s: 0, %s: 1, %s: 2, %s :3 (is: %s, %s, %s, %s)\n",
imsg_error("%s: 0, %s: 1, %s: 2, %s :3 (is: %s, %s, %s, %s)\n",
avr_pin_name(PIN_JTAG_TCK), avr_pin_name(PIN_JTAG_TDI),
avr_pin_name(PIN_JTAG_TDO), avr_pin_name(PIN_JTAG_TMS),
pins_to_str(&pgm->pin[PIN_JTAG_TCK]),
@@ -669,7 +632,7 @@ static int avrftdi_pin_setup(const PROGRAMMER *pgm) {
pins_to_str(&pgm->pin[PIN_JTAG_TDO]),
pins_to_str(&pgm->pin[PIN_JTAG_TMS]));
} else {
log_err("%s: 0, %s: 1, %s: 2 (is: %s, %s, %s)\n",
imsg_error("%s: 0, %s: 1, %s: 2 (is: %s, %s, %s)\n",
avr_pin_name(PIN_AVR_SCK),
avr_pin_name(PIN_AVR_SDO),
avr_pin_name(PIN_AVR_SDI),
@@ -677,14 +640,14 @@ static int avrftdi_pin_setup(const PROGRAMMER *pgm) {
pins_to_str(&pgm->pin[PIN_AVR_SDO]),
pins_to_str(&pgm->pin[PIN_AVR_SDI]));
}
log_err("If other pin configuration is used, fallback to slower bitbanging mode is used.\n");
imsg_error("if other pin configuration is used, fallback to slower bitbanging mode is used\n");
return -1;
}
pdata->use_bitbanging = !pin_check_mpsse;
if (pdata->use_bitbanging)
log_info("Because of pin configuration fallback to bitbanging mode.\n");
imsg_info("because of pin configuration fallback to bitbanging mode\n");
/*
* TODO: No need to fail for a wrongly configured led or something.
@@ -718,8 +681,8 @@ static int avrftdi_pin_setup(const PROGRAMMER *pgm) {
}
log_info("Pin direction mask: %04x\n", pdata->pin_direction);
log_info("Pin value mask: %04x\n", pdata->pin_value);
pmsg_info("pin direction mask: %04x\n", pdata->pin_direction);
pmsg_info("pin value mask: %04x\n", pdata->pin_value);
return 0;
}
@@ -766,7 +729,7 @@ static int avrftdi_open(PROGRAMMER *pgm, const char *port) {
else if (pgm->usbdev[0] == 'b' || pgm->usbdev[0] == 'B')
interface = INTERFACE_B;
else {
log_warn("Invalid interface '%s'. Setting to Interface A\n", pgm->usbdev);
pmsg_warning("invalid interface '%s'. Setting to Interface A\n", pgm->usbdev);
interface = INTERFACE_A;
}
@@ -778,13 +741,12 @@ static int avrftdi_open(PROGRAMMER *pgm, const char *port) {
err = ftdi_usb_open_desc_index(pdata->ftdic, vid, pid, desc, serial, index);
if(err) {
log_err("Error %d occurred: %s\n", err, ftdi_get_error_string(pdata->ftdic));
//stupid hack, because avrdude calls pgm->close() even when pgm->open() fails
//and usb_dev is initialized to the last usb device from probing
pmsg_error("error %d occurred: %s\n", err, ftdi_get_error_string(pdata->ftdic));
// usb_dev is initialized to the last usb device from probing
pdata->ftdic->usb_dev = NULL;
return err;
} else {
log_info("Using device VID:PID %04x:%04x and SN '%s' on interface %c.\n",
pmsg_info("using device VID:PID %04x:%04x and SN '%s' on interface %c.\n",
vid, pid, serial, INTERFACE_A == interface? 'A': 'B');
}
@@ -816,8 +778,8 @@ static int avrftdi_open(PROGRAMMER *pgm, const char *port) {
case TYPE_AM:
case TYPE_BM:
case TYPE_R:
log_err("Found unsupported device type AM, BM or R. avrftdi ");
log_err("cannot work with your chip. Try the 'synbb' programmer.\n");
pmsg_error("found unsupported device type AM, BM or R\n");
imsg_error("avrftdi cannot work with your chip; try the 'synbb' programmer type\n");
return -1;
case TYPE_2232C:
pdata->pin_limit = 12;
@@ -848,8 +810,8 @@ static int avrftdi_open(PROGRAMMER *pgm, const char *port) {
pdata->tx_buffer_size = 2048;
break;
default:
log_warn("Found unknown device %x. I will do my ", pdata->ftdic->type);
log_warn("best to work with it, but no guarantees ...\n");
pmsg_warning("unknown device type 0x%02x\n", pdata->ftdic->type);
imsg_warning("continuing but no guarantees...\n");
pdata->pin_limit = 8;
pdata->rx_buffer_size = pdata->ftdic->max_packet_size;
pdata->tx_buffer_size = pdata->ftdic->max_packet_size;
@@ -870,8 +832,8 @@ static void avrftdi_close(PROGRAMMER * pgm)
set_pin(pgm, PIN_AVR_RESET, ON);
/* Stop driving the pins - except for the LEDs */
log_info("LED Mask=0x%04x value =0x%04x &=0x%04x\n",
pdata->led_mask, pdata->pin_value, pdata->led_mask & pdata->pin_value);
pmsg_info("LED Mask=0x%04x value =0x%04x &=0x%04x\n",
pdata->led_mask, pdata->pin_value, pdata->led_mask & pdata->pin_value);
pdata->pin_direction = pdata->led_mask;
pdata->pin_value &= pdata->led_mask;
@@ -915,7 +877,7 @@ static int avrftdi_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
static void avrftdi_display(const PROGRAMMER *pgm, const char *p)
{
msg_info("%sPin assignment : 0..7 = DBUS0..7, 8..15 = CBUS0..7\n", p);
msg_info("%spin assignment : 0..7 = DBUS0..7, 8..15 = CBUS0..7\n", p);
if (pgm->flag & PGM_FL_IS_JTAG) {
pgm_display_generic_mask(pgm, p, SHOW_ALL_PINS & ~SHOW_AVR_PINS);
} else {
@@ -936,7 +898,7 @@ static int avrftdi_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
memset(buf, 0, sizeof(buf));
if (p->op[AVR_OP_PGM_ENABLE] == NULL) {
log_err("AVR_OP_PGM_ENABLE command not defined for %s\n", p->desc);
pmsg_error("AVR_OP_PGM_ENABLE command not defined for %s\n", p->desc);
return -1;
}
@@ -945,7 +907,7 @@ static int avrftdi_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
for(i = 0; i < 4; i++) {
pgm->cmd(pgm, buf, buf);
if (buf[p->pollindex-1] != p->pollvalue) {
log_warn("Program enable command not successful. Retrying.\n");
pmsg_warning("program enable command not successful%s\n", i < 3? "; retrying": "");
set_pin(pgm, PIN_AVR_RESET, ON);
usleep(20);
set_pin(pgm, PIN_AVR_RESET, OFF);
@@ -954,7 +916,7 @@ static int avrftdi_program_enable(const PROGRAMMER *pgm, const AVRPART *p) {
return 0;
}
log_err("Device is not responding to program enable. Check connection.\n");
pmsg_error("device is not responding to program enable. Check connection.\n");
return -1;
}
@@ -965,7 +927,7 @@ static int avrftdi_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {
unsigned char res[4];
if (p->op[AVR_OP_CHIP_ERASE] == NULL) {
log_err("AVR_OP_CHIP_ERASE command not defined for %s\n", p->desc);
pmsg_error("AVR_OP_CHIP_ERASE command not defined for %s\n", p->desc);
return -1;
}
@@ -998,7 +960,7 @@ static int avrftdi_lext(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM *m
avr_set_bits(m->op[AVR_OP_LOAD_EXT_ADDR], buf);
avr_set_addr(m->op[AVR_OP_LOAD_EXT_ADDR], buf, address);
if(verbose > TRACE)
if(verbose >= MSG_TRACE2)
buf_dump(buf, sizeof(buf),
"load extended address command", 0, 16 * 3);
@@ -1072,17 +1034,17 @@ static int avrftdi_flash_write(const PROGRAMMER *pgm, const AVRPART *p, const AV
/* pre-check opcodes */
if (m->op[AVR_OP_LOADPAGE_LO] == NULL) {
log_err("AVR_OP_LOADPAGE_LO command not defined for %s\n", p->desc);
pmsg_error("AVR_OP_LOADPAGE_LO command not defined for %s\n", p->desc);
return -1;
}
if (m->op[AVR_OP_LOADPAGE_HI] == NULL) {
log_err("AVR_OP_LOADPAGE_HI command not defined for %s\n", p->desc);
pmsg_error("AVR_OP_LOADPAGE_HI command not defined for %s\n", p->desc);
return -1;
}
if(page_size != (unsigned int) m->page_size) {
log_warn("Parameter page_size is %d, ", page_size);
log_warn("but m->page_size is %d. Using the latter.\n", m->page_size);
pmsg_warning("parameter page_size is %d ", page_size);
msg_warning("but m->page_size is %d; using the latter\n", m->page_size);
}
page_size = m->page_size;
@@ -1095,7 +1057,7 @@ static int avrftdi_flash_write(const PROGRAMMER *pgm, const AVRPART *p, const AV
/* addr is in bytes, but we program in words. */
for(word = addr/2; word < (len + addr)/2; word++)
{
log_debug("-< bytes = %d of %d\n", word * 2, len + addr);
pmsg_debug("-< bytes = %d of %d\n", word * 2, len + addr);
/*setting word*/
avr_set_bits(m->op[AVR_OP_LOADPAGE_LO], bufptr);
@@ -1111,7 +1073,7 @@ static int avrftdi_flash_write(const PROGRAMMER *pgm, const AVRPART *p, const AV
/* issue write page command, if available */
if (m->op[AVR_OP_WRITEPAGE] == NULL) {
log_err("AVR_OP_WRITEPAGE command not defined for %s\n", p->desc);
pmsg_error("AVR_OP_WRITEPAGE command not defined for %s\n", p->desc);
return -1;
} else {
avr_set_bits(m->op[AVR_OP_WRITEPAGE], bufptr);
@@ -1131,29 +1093,29 @@ static int avrftdi_flash_write(const PROGRAMMER *pgm, const AVRPART *p, const AV
if(poll_index+1 > addr) {
buf_size = bufptr - buf;
if(verbose > TRACE)
if(verbose >= MSG_TRACE2)
buf_dump(buf, buf_size, "command buffer", 0, 16*2);
log_info("Transmitting buffer of size: %d\n", buf_size);
pmsg_info("transmitting buffer of size: %d\n", buf_size);
if (0 > avrftdi_transmit(pgm, MPSSE_DO_WRITE, buf, buf, buf_size))
return -1;
bufptr = buf;
log_info("Using m->buf[%d] = 0x%02x as polling value ", poll_index,
pmsg_info("using m->buf[%d] = 0x%02x as polling value ", poll_index,
m->buf[poll_index]);
/* poll page write ready */
do {
log_info(".");
msg_info(".");
pgm->read_byte(pgm, p, m, poll_index, &poll_byte);
} while (m->buf[poll_index] != poll_byte);
log_info("\n");
msg_info("\n");
}
else
{
log_warn("Skipping empty page (containing only 0xff bytes)\n");
pmsg_warning("skipping empty page (containing only 0xff bytes)\n");
/* TODO sync write */
/* sleep */
usleep((m->max_write_delay));
@@ -1180,11 +1142,11 @@ static int avrftdi_flash_read(const PROGRAMMER *pgm, const AVRPART *p, const AVR
/* pre-check opcodes */
if (m->op[AVR_OP_READ_LO] == NULL) {
log_err("AVR_OP_READ_LO command not defined for %s\n", p->desc);
pmsg_error("AVR_OP_READ_LO command not defined for %s\n", p->desc);
return -1;
}
if (m->op[AVR_OP_READ_HI] == NULL) {
log_err("AVR_OP_READ_HI command not defined for %s\n", p->desc);
pmsg_error("AVR_OP_READ_HI command not defined for %s\n", p->desc);
return -1;
}
@@ -1209,14 +1171,14 @@ static int avrftdi_flash_read(const PROGRAMMER *pgm, const AVRPART *p, const AVR
* if there was an error, we did not see, memory validation will
* subsequently fail.
*/
if(verbose > TRACE) {
if(verbose >= MSG_TRACE2) {
buf_dump(o_buf, sizeof(o_buf), "o_buf", 0, 32);
}
if (0 > avrftdi_transmit(pgm, MPSSE_DO_READ | MPSSE_DO_WRITE, o_buf, i_buf, len * 4))
return -1;
if(verbose > TRACE) {
if(verbose >= MSG_TRACE2) {
buf_dump(i_buf, sizeof(i_buf), "i_buf", 0, 32);
}
@@ -1235,7 +1197,7 @@ static int avrftdi_flash_read(const PROGRAMMER *pgm, const AVRPART *p, const AVR
avr_get_output(readop, &i_buf[byte*4], &m->buf[addr+byte]);
}
if(verbose > TRACE)
if(verbose >= MSG_TRACE2)
buf_dump(&m->buf[addr], page_size, "page:", 0, 32);
return len;
@@ -1268,7 +1230,7 @@ static void avrftdi_setup(PROGRAMMER * pgm) {
if(!(pgm->cookie = calloc(1, sizeof(avrftdi_t)))) {
log_err("Error allocating memory.\n");
pmsg_error("Error allocating memory.\n");
exit(1);
}
pdata = to_pdata(pgm);
@@ -1276,7 +1238,7 @@ static void avrftdi_setup(PROGRAMMER * pgm) {
pdata->ftdic = ftdi_new();
if(!pdata->ftdic)
{
log_err("Error allocating memory.\n");
pmsg_error("Error allocating memory.\n");
exit(1);
}
E_VOID(ftdi_init(pdata->ftdic), pdata->ftdic);

View File

@@ -26,39 +26,21 @@
#ifndef DO_NOT_BUILD_AVRFTDI
enum { ERR, WARN, INFO, DEBUG, TRACE };
#define __log(lvl, fmt, ...) \
do { \
avrftdi_log(lvl, __func__, __LINE__, fmt, ##__VA_ARGS__); \
#define E(x, ftdi) \
do { \
if((x)) { \
pmsg_error("%s: %s (%d)\n", #x, strerror(errno), errno); \
imsg_error("%s\n", ftdi_get_error_string(ftdi)); \
return -1; \
} \
} while(0)
#define log_err(fmt, ...) __log(ERR, fmt, ##__VA_ARGS__)
#define log_warn(fmt, ...) __log(WARN, fmt, ##__VA_ARGS__)
#define log_info(fmt, ...) __log(INFO, fmt, ##__VA_ARGS__)
#define log_debug(fmt, ...) __log(DEBUG, fmt, ##__VA_ARGS__)
#define log_trace(fmt, ...) __log(TRACE, fmt, ##__VA_ARGS__)
#define E(x, ftdi) \
do { \
if ((x)) \
{ \
msg_error("%s:%d %s() %s: %s (%d)\n\t%s\n", \
__FILE__, __LINE__, __FUNCTION__, \
#x, strerror(errno), errno, ftdi_get_error_string(ftdi)); \
return -1; \
} \
} while(0)
#define E_VOID(x, ftdi) \
do { \
if ((x)) \
{ \
msg_error("%s:%d %s() %s: %s (%d)\n\t%s\n", \
__FILE__, __LINE__, __FUNCTION__, \
#x, strerror(errno), errno, ftdi_get_error_string(ftdi)); \
} \
#define E_VOID(x, ftdi) \
do { \
if((x)) { \
pmsg_error("%s: %s (%d)\n", #x, strerror(errno), errno); \
imsg_error("%s\n", ftdi_get_error_string(ftdi)); \
} \
} while(0)
enum {
@@ -115,7 +97,5 @@ typedef struct avrftdi_s {
char name_str[128]; // Used in ftdi_pin_name()
} avrftdi_t;
void avrftdi_log(int level, const char * func, int line, const char * fmt, ...);
#endif /* DO_NOT_BUILD_AVRFDTI */

View File

@@ -56,9 +56,9 @@ avrftdi_debug_frame(uint16_t frame)
line1[32] = 0;
line2[32] = 0;
log_debug("%s\n", line0);
log_debug("%s\n", line1);
//log_debug("%s\n", line2);
msg_debug("%s\n", line0);
msg_debug("%s\n", line1);
// msg_debug("%s\n", line2);
}
#endif /* notyet */
@@ -69,7 +69,7 @@ avrftdi_tpi_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
avrftdi_t* pdata = to_pdata(pgm);
unsigned char buf[] = { MPSSE_DO_WRITE | MPSSE_WRITE_NEG | MPSSE_LSB, 0x01, 0x00, 0xff, 0xff };
log_info("Setting /Reset pin low\n");
pmsg_info("Setting /Reset pin low\n");
pgm->setpin(pgm, PIN_AVR_RESET, OFF);
pgm->setpin(pgm, PIN_AVR_SCK, OFF);
pgm->setpin(pgm, PIN_AVR_SDO, ON);
@@ -84,7 +84,7 @@ avrftdi_tpi_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
/*wait at least 20ms bevor issuing spi commands to avr */
usleep(20 * 1000);
log_info("Sending 16 init clock cycles ...\n");
pmsg_info("Sending 16 init clock cycles ...\n");
ret = ftdi_write_data(pdata->ftdic, buf, sizeof(buf));
return ret;
@@ -92,7 +92,7 @@ avrftdi_tpi_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
void avrftdi_tpi_initpgm(PROGRAMMER *pgm) {
log_info("Using TPI interface\n");
pmsg_info("Using TPI interface\n");
pgm->program_enable = avrftdi_tpi_program_enable;
pgm->cmd_tpi = avrftdi_cmd_tpi;
@@ -172,7 +172,7 @@ avrftdi_tpi_write_byte(const PROGRAMMER *pgm, unsigned char byte) {
buffer[3] = frame & 0xff;
buffer[4] = frame >> 8;
log_trace("Byte %02x, frame: %04x, MPSSE: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
msg_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]);
//avrftdi_debug_frame(frame);
@@ -200,7 +200,7 @@ avrftdi_tpi_read_byte(const PROGRAMMER *pgm, unsigned char *byte) {
buffer[2] = ((bytes-1) >> 8) & 0xff;
buffer[3] = SEND_IMMEDIATE;
log_trace("MPSSE: 0x%02x 0x%02x 0x%02x 0x%02x (Read frame)\n",
msg_trace("MPSSE: 0x%02x 0x%02x 0x%02x 0x%02x (Read frame)\n",
buffer[0], buffer[1], buffer[2], buffer[3]);
ftdi_write_data(to_pdata(pgm)->ftdic, buffer, 4);
@@ -215,14 +215,14 @@ avrftdi_tpi_read_byte(const PROGRAMMER *pgm, unsigned char *byte) {
} while(i < bytes);
log_trace("MPSSE: 0x%02x 0x%02x 0x%02x 0x%02x (Read frame)\n",
msg_trace("MPSSE: 0x%02x 0x%02x 0x%02x 0x%02x (Read frame)\n",
buffer[0], buffer[1], buffer[2], buffer[3]);
frame = buffer[0] | (buffer[1] << 8);
err = tpi_frame2byte(frame, byte);
log_trace("Frame: 0x%04x, byte: 0x%02x\n", frame, *byte);
pmsg_trace("Frame: 0x%04x, byte: 0x%02x\n", frame, *byte);
//avrftdi_debug_frame(frame);
@@ -262,7 +262,7 @@ avrftdi_tpi_disable(const 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");
pmsg_info("Leaving Programming mode.\n");
}
#endif /* DO_NOT_BUILD_AVRFTDI */