#endif
/* project specific includes */
-#include "interface.h"
-#include "commands.h"
+#include <jtag/interface.h>
+#include <jtag/commands.h>
#include "rlink.h"
#include "rlink_st7.h"
#include "rlink_ep1_cmd.h"
static
int
ep1_generic_commandl(
- usb_dev_handle *pHDev,
+ usb_dev_handle *pHDev_param,
size_t length,
...
) {
);
usb_ret = usb_bulk_write(
- pHDev,
+ pHDev_param,
USB_EP1OUT_ADDR,
(char *)usb_buffer, sizeof(usb_buffer),
USB_TIMEOUT_MS
static
ssize_t
ep1_memory_write(
- usb_dev_handle *pHDev,
+ usb_dev_handle *pHDev_param,
uint16_t addr,
size_t length,
uint8_t const *buffer
);
usb_ret = usb_bulk_write(
- pHDev, USB_EP1OUT_ADDR,
+ pHDev_param, USB_EP1OUT_ADDR,
(char *)usb_buffer, sizeof(usb_buffer),
USB_TIMEOUT_MS
);
static
int
dtc_load_from_buffer(
- usb_dev_handle *pHDev,
+ usb_dev_handle *pHDev_param,
const uint8_t *buffer,
size_t length
) {
/* Stop the DTC before loading anything. */
usb_err = ep1_generic_commandl(
- pHDev, 1,
+ pHDev_param, 1,
EP1_CMD_DTC_STOP
);
if (usb_err < 0) return(usb_err);
while (length) {
if (length < sizeof(*header)) {
- LOG_ERROR("Malformed DTC image\n");
+ LOG_ERROR("Malformed DTC image");
exit(1);
}
length -= sizeof(*header);
if (length < (size_t)header->length + 1) {
- LOG_ERROR("Malformed DTC image\n");
+ LOG_ERROR("Malformed DTC image");
exit(1);
}
case DTCLOAD_LOAD:
/* Send the DTC program to ST7 RAM. */
usb_err = ep1_memory_write(
- pHDev,
+ pHDev_param,
DTC_LOAD_BUFFER,
header->length + 1, buffer
);
/* Load it into the DTC. */
usb_err = ep1_generic_commandl(
- pHDev, 3,
+ pHDev_param, 3,
EP1_CMD_DTC_LOAD,
(DTC_LOAD_BUFFER >> 8),
DTC_LOAD_BUFFER
case DTCLOAD_RUN:
usb_err = ep1_generic_commandl(
- pHDev, 3,
+ pHDev_param, 3,
EP1_CMD_DTC_CALL,
buffer[0],
EP1_CMD_DTC_WAIT
case DTCLOAD_LUT:
usb_err = ep1_memory_write(
- pHDev,
+ pHDev_param,
ST7_USB_BUF_EP0OUT + lut_start,
header->length + 1, buffer
);
break;
default:
- LOG_ERROR("Invalid DTC image record type: 0x%02x\n", header->type);
+ LOG_ERROR("Invalid DTC image record type: 0x%02x", header->type);
exit(1);
break;
}
static
int
dtc_run_download(
- usb_dev_handle *pHDev,
+ usb_dev_handle *pHDev_param,
uint8_t *command_buffer,
int command_buffer_size,
uint8_t *reply_buffer,
int usb_err;
int i;
- LOG_DEBUG(": %d/%d\n", command_buffer_size, reply_buffer_size);
+ LOG_DEBUG(": %d/%d", command_buffer_size, reply_buffer_size);
usb_err = usb_bulk_write(
- pHDev,
+ pHDev_param,
USB_EP2OUT_ADDR,
(char *)command_buffer, USB_EP2BANK_SIZE,
USB_TIMEOUT_MS
/* Wait for DTC to finish running command buffer */
for (i = 10;;) {
usb_err = ep1_generic_commandl(
- pHDev, 4,
+ pHDev_param, 4,
EP1_CMD_MEMORY_READ,
DTC_STATUS_POLL_BYTE >> 8,
if (usb_err < 0) return(usb_err);
usb_err = usb_bulk_read(
- pHDev,
+ pHDev_param,
USB_EP1IN_ADDR,
(char *)ep2_buffer, 1,
USB_TIMEOUT_MS
if (ep2_buffer[0] & 0x01) break;
if (!--i) {
- LOG_ERROR("%s, %d: too many retries waiting for DTC status\n",
+ LOG_ERROR("%s, %d: too many retries waiting for DTC status",
__FILE__, __LINE__
);
return(-ETIMEDOUT);
if (!reply_buffer) reply_buffer_size = 0;
if (reply_buffer_size) {
usb_err = usb_bulk_read(
- pHDev,
+ pHDev_param,
USB_EP2IN_ADDR,
(char *)ep2_buffer, sizeof(ep2_buffer),
USB_TIMEOUT_MS
);
if (usb_err < (int)sizeof(ep2_buffer)) {
- LOG_ERROR("%s, %d: Read of endpoint 2 returned %d\n",
+ LOG_ERROR("%s, %d: Read of endpoint 2 returned %d",
__FILE__, __LINE__, usb_err
);
return(usb_err);
NULL, 0
);
if (usb_err < 0) {
- LOG_ERROR("dtc_run_download: %s\n", usb_strerror());
+ LOG_ERROR("dtc_run_download: %s", usb_strerror());
exit(1);
}
} else {
reply_buffer, dtc_queue.reply_index
);
if (usb_err < 0) {
- LOG_ERROR("dtc_run_download: %s\n", usb_strerror());
+ LOG_ERROR("dtc_run_download: %s", usb_strerror());
exit(1);
} else {
/* process the reply, which empties the reply queue and frees its entries */
tap_state_queue_run(void) {
int i;
int bits;
- uint8_t byte;
+ uint8_t byte_param;
int retval;
retval = 0;
if (!tap_state_queue.length) return(retval);
bits = 1;
- byte = 0;
+ byte_param = 0;
for (i = tap_state_queue.length; i--;) {
- byte <<= 1;
+ byte_param <<= 1;
if (tap_state_queue.buffer & 1) {
- byte |= 1;
+ byte_param |= 1;
}
if ((bits >= 8) || !i) {
- byte <<= (8 - bits);
+ byte_param <<= (8 - bits);
/* make sure there's room for stop, byte op, and one byte */
if (dtc_queue.cmd_index >= (sizeof(dtc_queue.cmd_buffer) - (1 + 1 + 1))) {
#endif
dtc_queue.cmd_buffer[dtc_queue.cmd_index++] =
- byte;
+ byte_param;
- byte = 0;
+ byte_param = 0;
bits = 1;
} else {
bits++;
uint8_t dtc_mask;
if (scan_size < 1) {
- LOG_ERROR("scan_size cannot be less than 1 bit\n");
+ LOG_ERROR("scan_size cannot be less than 1 bit");
exit(1);
}
chunk_bits,
cmd
) == NULL) {
- LOG_ERROR("enqueuing DTC reply entry: %s\n", strerror(errno));
+ LOG_ERROR("enqueuing DTC reply entry: %s", strerror(errno));
exit(1);
}
extra_bits,
cmd
) == NULL) {
- LOG_ERROR("enqueuing DTC reply entry: %s\n", strerror(errno));
+ LOG_ERROR("enqueuing DTC reply entry: %s", strerror(errno));
exit(1);
}
1,
cmd
) == NULL) {
- LOG_ERROR("enqueuing DTC reply entry: %s\n", strerror(errno));
+ LOG_ERROR("enqueuing DTC reply entry: %s", strerror(errno));
exit(1);
}
switch (cmd->type)
{
case JTAG_RUNTEST:
- case JTAG_STATEMOVE:
+ case JTAG_TLR_RESET:
case JTAG_PATHMOVE:
case JTAG_SCAN:
break;
rlink_end_state(cmd->cmd.runtest->end_state);
rlink_runtest(cmd->cmd.runtest->num_cycles);
break;
- case JTAG_STATEMOVE:
+ case JTAG_TLR_RESET:
#ifdef _DEBUG_JTAG_IO_
LOG_DEBUG("statemove end in %i", cmd->cmd.statemove->end_state);
#endif
for (i = rlink_speed_table_size; i--;) {
if (rlink_speed_table[i].prescaler == speed) {
if (dtc_load_from_buffer(pHDev, rlink_speed_table[i].dtc, rlink_speed_table[i].dtc_size) != 0) {
- LOG_ERROR("An error occurred while trying to load DTC code for speed \"%d\".\n", speed);
+ LOG_ERROR("An error occurred while trying to load DTC code for speed \"%d\".", speed);
exit(1);
}
struct usb_device *dev = usb_device(pHDev);
if (dev->descriptor.bNumConfigurations > 1)
{
- LOG_ERROR("Whoops! NumConfigurations is not 1, don't know what to do...\n");
+ LOG_ERROR("Whoops! NumConfigurations is not 1, don't know what to do...");
return ERROR_FAIL;
}
if (dev->config->bNumInterfaces > 1)
{
- LOG_ERROR("Whoops! NumInterfaces is not 1, don't know what to do...\n");
+ LOG_ERROR("Whoops! NumInterfaces is not 1, don't know what to do...");
return ERROR_FAIL;
}
- LOG_DEBUG("Opened device, pHDev = %p\n", pHDev);
+ LOG_DEBUG("Opened device, pHDev = %p", pHDev);
/* usb_set_configuration required under win32 */
usb_set_configuration(pHDev, dev->config[0].bConfigurationValue);
}
else
{
- LOG_DEBUG("interface claimed!\n");
+ LOG_DEBUG("interface claimed!");
break;
}
} while (--retries);
}
if (usb_set_altinterface(pHDev,0) != 0)
{
- LOG_ERROR("Failed to set interface.\n");
+ LOG_ERROR("Failed to set interface.");
return ERROR_FAIL;
}
LOG_ERROR("USB read error: %s", usb_strerror());
return(ERROR_FAIL);
}
- LOG_DEBUG(INTERFACE_NAME" firmware version: %d.%d.%d\n", reply_buffer[0], reply_buffer[1], reply_buffer[2]);
+ LOG_DEBUG(INTERFACE_NAME" firmware version: %d.%d.%d", reply_buffer[0], reply_buffer[1], reply_buffer[2]);
if ((reply_buffer[0] != 0) || (reply_buffer[1] != 0) || (reply_buffer[2] != 3)) {
- LOG_WARNING("The rlink device is not of the version that the developers have played with. It may or may not work.\n");
+ LOG_WARNING("The rlink device is not of the version that the developers have played with. It may or may not work.");
}
/* Probe port E for adapter presence */
);
if ((reply_buffer[0] & ST7_PE_ADAPTER_SENSE_IN) != 0) {
- LOG_WARNING("target detection problem\n");
+ LOG_WARNING("target detection problem");
}
ep1_generic_commandl(
if ((reply_buffer[0] & ST7_PE_ADAPTER_SENSE_IN) == 0) {
- LOG_WARNING("target not plugged in\n");
+ LOG_WARNING("target not plugged in");
}
/* float ports A and B */
tap_state_queue_init();
dtc_queue_init();
- rlink_speed(jtag_get_speed());
+ int jtag_speed_var;
+ int retval = jtag_get_speed(&jtag_speed_var);
+ if (retval != ERROR_OK)
+ return retval;
+ rlink_speed(jtag_speed_var);
rlink_reset(0, 0);
return ERROR_OK;