* Copyright (C) 2005 by Dominic Rath *
* Dominic.Rath@gmx.de *
* *
- * Copyright (C) 2007,2008 Øyvind Harboe *
+ * Copyright (C) 2007,2008 Øyvind Harboe *
* oyvind.harboe@zylin.com *
* *
* Copyright (C) 2008 Rob Brown, Lou Deluxe *
usb_buffer_p,
0,
sizeof(usb_buffer) - (usb_buffer_p - usb_buffer)
- );
+);
usb_ret = usb_bulk_write(
pHDev,
USB_EP1OUT_ADDR,
(char *)usb_buffer, sizeof(usb_buffer),
USB_TIMEOUT_MS
- );
+);
return(usb_ret);
}
usb_buffer + 4,
0,
sizeof(usb_buffer) - 4
- );
+);
remain = length;
count = 0;
pHDev, USB_EP1OUT_ADDR,
usb_buffer, sizeof(usb_buffer),
USB_TIMEOUT_MS
- );
+);
if (usb_ret < sizeof(usb_buffer)) {
break;
pHDev, USB_EP1IN_ADDR,
buffer, length,
USB_TIMEOUT_MS
- );
+);
if (usb_ret < length) {
break;
usb_buffer + 4,
buffer,
length
- );
+);
memset(
usb_buffer + 4 + length,
0,
sizeof(usb_buffer) - 4 - length
- );
+);
usb_ret = usb_bulk_write(
pHDev, USB_EP1OUT_ADDR,
(char *)usb_buffer, sizeof(usb_buffer),
USB_TIMEOUT_MS
- );
+);
if ((size_t)usb_ret < sizeof(usb_buffer)) {
break;
usb_err = ep1_generic_commandl(
pHDev, 1,
EP1_CMD_DTC_STOP
- );
+);
if (usb_err < 0) return(usb_err);
while (length) {
pHDev,
DTC_LOAD_BUFFER,
header->length + 1, buffer
- );
+);
if (usb_err < 0) return(usb_err);
/* Load it into the DTC. */
EP1_CMD_DTC_LOAD,
(DTC_LOAD_BUFFER >> 8),
DTC_LOAD_BUFFER
- );
+);
if (usb_err < 0) return(usb_err);
break;
EP1_CMD_DTC_CALL,
buffer[0],
EP1_CMD_DTC_WAIT
- );
+);
if (usb_err < 0) return(usb_err);
break;
pHDev,
ST7_USB_BUF_EP0OUT + lut_start,
header->length + 1, buffer
- );
+);
if (usb_err < 0) return(usb_err);
break;
ST7_EP2TXR >> 8,
ST7_EP2TXR,
1
- );
+);
if (usb_err < 0) return(usb_err);
/* read back ep2txr */
pHDev, USB_EP1IN_ADDR,
(char *)&ep2txr, 1,
USB_TIMEOUT_MS
- );
+);
if (usb_err < 0) return(usb_err);
usb_err = ep1_generic_commandl(
EP1_CMD_DTC_CALL, /* start running the DTC */
dtc_entry_download,
EP1_CMD_DTC_GET_CACHED_STATUS
- );
+);
if (usb_err < 0) return(usb_err);
/* wait for completion */
pHDev, USB_EP1IN_ADDR,
(char *)&ep2txr, 1,
USB_TIMEOUT_MS
- );
+);
return(usb_err);
}
USB_EP2OUT_ADDR,
(char *)command_buffer, USB_EP2BANK_SIZE,
USB_TIMEOUT_MS
- );
+);
if (usb_err < 0) return(usb_err);
DTC_STATUS_POLL_BYTE >> 8,
DTC_STATUS_POLL_BYTE,
1
- );
+);
if (usb_err < 0) return(usb_err);
usb_err = usb_bulk_read(
USB_EP1IN_ADDR,
(char *)ep2_buffer, 1,
USB_TIMEOUT_MS
- );
+);
if (usb_err < 0) return(usb_err);
if (ep2_buffer[0] & 0x01) break;
if (!--i) {
LOG_ERROR("%s, %d: too many retries waiting for DTC status\n",
__FILE__, __LINE__
- );
+);
return(-ETIMEDOUT);
}
}
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",
__FILE__, __LINE__, usb_err
- );
+);
return(usb_err);
}
* The dtc reply queue is a singly linked list that describes what to do with the reply packet that comes from the DTC. Only SCAN_IN and SCAN_IO generate these entries.
*/
-typedef
-struct dtc_reply_queue_entry_s {
- struct dtc_reply_queue_entry_s *next;
- jtag_command_t *cmd; /* the command that resulted in this entry */
+struct dtc_reply_queue_entry {
+ struct dtc_reply_queue_entry *next;
+ struct jtag_command *cmd; /* the command that resulted in this entry */
struct {
uint8_t *buffer; /* the scan buffer */
int length; /* how many bits are processed in this operation? */
enum scan_type type; /* SCAN_IN/SCAN_OUT/SCAN_IO */
} scan;
-} dtc_reply_queue_entry_t;
+};
/*
static
struct {
- dtc_reply_queue_entry_t *rq_head;
- dtc_reply_queue_entry_t *rq_tail;
+ struct dtc_reply_queue_entry *rq_head;
+ struct dtc_reply_queue_entry *rq_tail;
uint32_t cmd_index;
uint32_t reply_index;
uint8_t cmd_buffer[USB_EP2BANK_SIZE];
static
inline
-dtc_reply_queue_entry_t *
+struct dtc_reply_queue_entry *
dtc_queue_enqueue_reply(
enum scan_type type,
uint8_t *buffer,
int size,
int offset,
int length,
- jtag_command_t *cmd
+ struct jtag_command *cmd
) {
- dtc_reply_queue_entry_t *rq_entry;
+ struct dtc_reply_queue_entry *rq_entry;
- rq_entry = malloc(sizeof(dtc_reply_queue_entry_t));
+ rq_entry = malloc(sizeof(struct dtc_reply_queue_entry));
if (rq_entry != NULL) {
rq_entry->scan.type = type;
rq_entry->scan.buffer = buffer;
static
int
dtc_queue_run(void) {
- dtc_reply_queue_entry_t *rq_p, *rq_next;
+ struct dtc_reply_queue_entry *rq_p, *rq_next;
int retval;
int usb_err;
int bit_cnt;
usb_err = dtc_run_download(pHDev,
dtc_queue.cmd_buffer, dtc_queue.cmd_index,
NULL, 0
- );
+);
if (usb_err < 0) {
LOG_ERROR("dtc_run_download: %s\n", usb_strerror());
exit(1);
usb_err = dtc_run_download(pHDev,
dtc_queue.cmd_buffer, dtc_queue.cmd_index,
reply_buffer, dtc_queue.reply_index
- );
+);
if (usb_err < 0) {
LOG_ERROR("dtc_run_download: %s\n", usb_strerror());
exit(1);
rq_p = dtc_queue.rq_head;
rq_p != NULL;
rq_p = rq_next
- ) {
+) {
tdo_p = rq_p->scan.buffer + (rq_p->scan.offset / 8);
tdo_mask = 1 << (rq_p->scan.offset % 8);
;
bit_cnt;
bit_cnt--
- ) {
+) {
if (*dtc_p & dtc_mask) {
*tdo_p |= tdo_mask;
} else {
x = *dtc_p++;
if ((
rq_p->scan.type == SCAN_IN
- ) && (
+) && (
rq_p->scan.offset != rq_p->scan.size - 1
- )) {
+)) {
/* extra bits were sent as a full byte with padding on the end */
dtc_mask = 1 << (8 - 1);
} else {
;
bit_cnt;
bit_cnt--
- ) {
+) {
if (x & dtc_mask) {
*tdo_p |= tdo_mask;
} else {
static
void rlink_state_move(void) {
- int i=0, tms=0;
+ int i = 0, tms = 0;
uint8_t tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state());
int tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
}
static
-void rlink_path_move(pathmove_command_t *cmd)
+void rlink_path_move(struct pathmove_command *cmd)
{
int num_states = cmd->num_states;
int state_count;
ST7_PADR >> 8,
ST7_PADR,
1
- );
+);
if (usb_err < 0) {
LOG_ERROR("%s", usb_strerror());
exit(1);
pHDev, USB_EP1IN_ADDR,
(char *)&bitmap, 1,
USB_TIMEOUT_MS
- );
+);
if (usb_err < 1) {
LOG_ERROR("%s", usb_strerror());
exit(1);
ST7_PBDDR >> 8,
ST7_PBDDR,
1
- );
+);
if (usb_err < 0) {
LOG_ERROR("%s", usb_strerror());
exit(1);
pHDev, USB_EP1IN_ADDR,
(char *)&bitmap, 1,
USB_TIMEOUT_MS
- );
+);
if (usb_err < 1) {
LOG_ERROR("%s", usb_strerror());
exit(1);
1,
bitmap,
EP1_CMD_DTC_GET_CACHED_STATUS
- );
+);
if (usb_err < 0) {
LOG_ERROR("%s", usb_strerror());
exit(1);
pHDev, USB_EP1IN_ADDR,
(char *)&bitmap, 1,
USB_TIMEOUT_MS
- );
+);
if (usb_err < 1) {
LOG_ERROR("%s", usb_strerror());
exit(1);
static
int
rlink_scan(
- jtag_command_t *cmd,
+ struct jtag_command *cmd,
enum scan_type type,
uint8_t *buffer,
int scan_size
(!ir_scan && (tap_get_state() == TAP_DRSHIFT))
||
(ir_scan && (tap_get_state() == TAP_IRSHIFT))
- )) {
+)) {
saved_end_state = tap_get_end_state();
rlink_end_state(ir_scan ? TAP_IRSHIFT : TAP_DRSHIFT);
rlink_state_move();
#if 0
- printf("scan_size = %d, type=0x%x\n", scan_size, type);
+ printf("scan_size = %d, type = 0x%x\n", scan_size, type);
{
int i;
/* 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))
- ) {
+) {
dtc_queue_run();
}
type, buffer, scan_size, tdi_bit_offset,
chunk_bits,
cmd
- ) == NULL) {
+) == NULL) {
LOG_ERROR("enqueuing DTC reply entry: %s\n", strerror(errno));
exit(1);
}
(dtc_queue.cmd_index >= sizeof(dtc_queue.cmd_buffer) - (1 + 1 + 1))
||
(dtc_queue.reply_index >= USB_EP2IN_SIZE - (1))
- ) {
+) {
dtc_queue_run();
}
type, buffer, scan_size, tdi_bit_offset,
extra_bits,
cmd
- ) == NULL) {
+) == NULL) {
LOG_ERROR("enqueuing DTC reply entry: %s\n", strerror(errno));
exit(1);
}
(dtc_queue.cmd_index >= sizeof(dtc_queue.cmd_buffer) - (1 + 1))
||
(dtc_queue.reply_index >= USB_EP2IN_SIZE - (1))
- ) {
+) {
dtc_queue_run();
}
type, buffer, scan_size, tdi_bit_offset,
1,
cmd
- ) == NULL) {
+) == NULL) {
LOG_ERROR("enqueuing DTC reply entry: %s\n", strerror(errno));
exit(1);
}
static
int rlink_execute_queue(void)
{
- jtag_command_t *cmd = jtag_command_queue; /* currently processed command */
+ struct jtag_command *cmd = jtag_command_queue; /* currently processed command */
int scan_size;
enum scan_type type;
uint8_t *buffer;
ep1_generic_commandl(pHDev, 2,
EP1_CMD_SET_PORTD_LEDS,
~(ST7_PD_NBUSY_LED)
- );
+);
#endif
while (cmd)
ep1_generic_commandl(pHDev, 2,
EP1_CMD_SET_PORTD_LEDS,
~0
- );
+);
#endif
return retval;
speed = rlink_speed_table[rlink_speed_table_size - 1].prescaler;
}
- for (i = rlink_speed_table_size; i--; ) {
+ 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("%s, %d: starting DTC: %s",
__FILE__, __LINE__,
usb_strerror()
- );
+);
exit(1);
}
) {
int i;
- for (i = rlink_speed_table_size; i--; ) {
+ for (i = rlink_speed_table_size; i--;) {
if (rlink_speed_table[i].prescaler == speed) {
*khz = rlink_speed_table[i].khz;
return(ERROR_OK);
return ERROR_FAIL;
}
- for (i = rlink_speed_table_size; i--; ) {
+ for (i = rlink_speed_table_size; i--;) {
if (rlink_speed_table[i].khz <= khz) {
*speed = rlink_speed_table[i].prescaler;
return(ERROR_OK);
static
int
handle_dtc_directory_command(
- struct command_context_s *cmd_ctx,
+ struct command_context *cmd_ctx,
char *cmd,
char **args,
int argc
static
-int rlink_register_commands(struct command_context_s *cmd_ctx)
+int rlink_register_commands(struct command_context *cmd_ctx)
{
#ifdef _DEBUG_JTAG_IO_
handle_dtc_directory_command,
COMMAND_CONFIG,
"The directory in which to search for DTC load images"
- );
+);
#endif
return ERROR_OK;
struct usb_bus *busses;
struct usb_bus *bus;
int i, j, retries;
- int found=0;
- int success=0;
+ int found = 0;
+ int success = 0;
uint8_t reply_buffer[USB_EP1IN_SIZE];
usb_init();
for (dev = bus->devices; dev; dev = dev->next)
{
- if ( (dev->descriptor.idVendor == USB_IDVENDOR) && (dev->descriptor.idProduct == USB_IDPRODUCT) )
+ if ((dev->descriptor.idVendor == USB_IDVENDOR) && (dev->descriptor.idProduct == USB_IDPRODUCT))
{
found = 1;
LOG_DEBUG("Found device on bus.\n");
do
{
- if ( dev->descriptor.bNumConfigurations > 1 )
+ if (dev->descriptor.bNumConfigurations > 1)
{
LOG_ERROR("Whoops! NumConfigurations is not 1, don't know what to do...\n");
break;
}
- if ( dev->config->bNumInterfaces > 1 )
+ if (dev->config->bNumInterfaces > 1)
{
LOG_ERROR("Whoops! NumInterfaces is not 1, don't know what to do...\n");
break;
}
- pHDev=usb_open(dev);
- if ( !pHDev )
+ pHDev = usb_open(dev);
+ if (!pHDev)
LOG_ERROR ("Failed to open device.\n");
else
{
if (!i)
{
- if ( usb_set_altinterface(pHDev,0) )
+ if (usb_set_altinterface(pHDev,0))
{
LOG_ERROR("Failed to set interface.\n");
break;
}
else
- success=1;
+ success = 1;
}
}
} while (0);
}
}
- if ( !found )
+ if (!found)
{
LOG_ERROR("No device found on bus.\n");
exit(1);
}
- if ( !success )
+ if (!success)
{
LOG_ERROR("Initialisation failed.");
exit(1);
j = ep1_generic_commandl(
pHDev, 1,
EP1_CMD_GET_FWREV
- );
+);
if (j < USB_EP1OUT_SIZE) {
LOG_ERROR("USB write error: %s", usb_strerror());
return(ERROR_FAIL);
pHDev, USB_EP1IN_ADDR,
(char *)reply_buffer, sizeof(reply_buffer),
200
- );
+);
if (j != -ETIMEDOUT) break;
}
ST7_PEDR,
1,
ST7_PE_ADAPTER_SENSE_OUT
- );
+);
usb_bulk_read(
pHDev, USB_EP1IN_ADDR,
(char *)reply_buffer, 1,
USB_TIMEOUT_MS
- );
+);
if ((reply_buffer[0] & ST7_PE_ADAPTER_SENSE_IN) != 0) {
LOG_WARNING("target detection problem\n");
0x00, /* DR */
0x00, /* DDR */
0x00 /* OR */
- );
+);
usb_bulk_read(
pHDev, USB_EP1IN_ADDR,
(char *)reply_buffer, 1,
USB_TIMEOUT_MS
- );
+);
if ((reply_buffer[0] & ST7_PE_ADAPTER_SENSE_IN) == 0) {
ST7_PBDDR,
1,
0x00
- );
+);
/* make sure DTC is stopped, set VPP control, set up ports A and B */
ep1_generic_commandl(
ST7_PBDR,
1,
0x00
- );
+);
/* set LED updating mode and make sure they're unlit */
ep1_generic_commandl(
#endif
EP1_CMD_SET_PORTD_LEDS,
~0
- );
+);
tap_state_queue_init();
dtc_queue_init();
~0,
EP1_CMD_SET_PORTD_VPP,
~0
- );
+);
usb_release_interface(pHDev,0);
usb_close(pHDev);
}
-jtag_interface_t rlink_interface =
+struct jtag_interface rlink_interface =
{
.name = "rlink",
.init = rlink_init,