1 /***************************************************************************
2 * Copyright (C) 2004, 2006 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
29 #include "replacements.h"
31 /* project specific includes */
35 #include "configuration.h"
36 #include "time_support.h"
43 /* FT2232 access library includes */
44 #if BUILD_FT2232_FTD2XX == 1
46 #elif BUILD_FT2232_LIBFTDI == 1
53 /* enable this to debug io latency
56 #define _DEBUG_USB_IO_
59 /* enable this to debug communication
62 #define _DEBUG_USB_COMMS_
65 int ft2232_execute_queue(void);
67 int ft2232_speed(int speed);
68 int ft2232_register_commands(struct command_context_s *cmd_ctx);
69 int ft2232_init(void);
70 int ft2232_quit(void);
72 int ft2232_handle_device_desc_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
73 int ft2232_handle_serial_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
74 int ft2232_handle_layout_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
75 int ft2232_handle_vid_pid_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
77 char *ft2232_device_desc = NULL;
78 char *ft2232_serial = NULL;
79 char *ft2232_layout = NULL;
82 /* vid = pid = 0 marks the end of the list */
83 static u16 ft2232_vid[MAX_USB_IDS+1] = { 0x0403, 0 };
84 static u16 ft2232_pid[MAX_USB_IDS+1] = { 0x6010, 0 };
86 typedef struct ft2232_layout_s
90 void(*reset)(int trst, int srst);
94 /* init procedures for supported layouts */
95 int usbjtag_init(void);
96 int jtagkey_init(void);
97 int olimex_jtag_init(void);
99 int turtle_init(void);
101 /* reset procedures for supported layouts */
102 void usbjtag_reset(int trst, int srst);
103 void jtagkey_reset(int trst, int srst);
104 void olimex_jtag_reset(int trst, int srst);
105 void m5960_reset(int trst, int srst);
106 void turtle_reset(int trst, int srst);
108 /* blink procedures for layouts that support a blinking led */
109 void olimex_jtag_blink(void);
110 void turtle_jtag_blink(void);
112 ft2232_layout_t ft2232_layouts[] =
114 {"usbjtag", usbjtag_init, usbjtag_reset, NULL},
115 {"jtagkey", jtagkey_init, jtagkey_reset, NULL},
116 {"jtagkey_prototype_v1", jtagkey_init, jtagkey_reset, NULL},
117 {"oocdlink", jtagkey_init, jtagkey_reset, NULL},
118 {"signalyzer", usbjtag_init, usbjtag_reset, NULL},
119 {"evb_lm3s811", usbjtag_init, usbjtag_reset, NULL},
120 {"olimex-jtag", olimex_jtag_init, olimex_jtag_reset, olimex_jtag_blink},
121 {"m5960", m5960_init, m5960_reset, NULL},
122 {"turtelizer2", turtle_init, turtle_reset, turtle_jtag_blink},
126 static u8 nTRST, nTRSTnOE, nSRST, nSRSTnOE;
128 static ft2232_layout_t *layout;
129 static u8 low_output = 0x0;
130 static u8 low_direction = 0x0;
131 static u8 high_output = 0x0;
132 static u8 high_direction = 0x0;
134 #if BUILD_FT2232_FTD2XX == 1
135 static FT_HANDLE ftdih = NULL;
136 #elif BUILD_FT2232_LIBFTDI == 1
137 static struct ftdi_context ftdic;
140 static u8 *ft2232_buffer = NULL;
141 static int ft2232_buffer_size = 0;
142 static int ft2232_read_pointer = 0;
143 static int ft2232_expect_read = 0;
144 #define FT2232_BUFFER_SIZE 131072
145 #define BUFFER_ADD ft2232_buffer[ft2232_buffer_size++]
146 #define BUFFER_READ ft2232_buffer[ft2232_read_pointer++]
148 jtag_interface_t ft2232_interface =
153 .execute_queue = ft2232_execute_queue,
155 .support_pathmove = 1,
157 .speed = ft2232_speed,
158 .register_commands = ft2232_register_commands,
163 int ft2232_write(u8 *buf, int size, u32* bytes_written)
165 #if BUILD_FT2232_FTD2XX == 1
167 DWORD dw_bytes_written;
168 if ((status = FT_Write(ftdih, buf, size, &dw_bytes_written)) != FT_OK)
170 *bytes_written = dw_bytes_written;
171 ERROR("FT_Write returned: %lu", status);
172 return ERROR_JTAG_DEVICE_ERROR;
176 *bytes_written = dw_bytes_written;
179 #elif BUILD_FT2232_LIBFTDI == 1
181 if ((retval = ftdi_write_data(&ftdic, buf, size)) < 0)
184 ERROR("ftdi_write_data: %s", ftdi_get_error_string(&ftdic));
185 return ERROR_JTAG_DEVICE_ERROR;
189 *bytes_written = retval;
195 int ft2232_read(u8* buf, int size, u32* bytes_read)
197 #if BUILD_FT2232_FTD2XX == 1
203 while ((*bytes_read < size) && timeout--)
205 if ((status = FT_Read(ftdih, buf, size, &dw_bytes_read)) != FT_OK)
208 ERROR("FT_Read returned: %lu", status);
209 return ERROR_JTAG_DEVICE_ERROR;
211 *bytes_read += dw_bytes_read;
213 #elif BUILD_FT2232_LIBFTDI == 1
218 while ((*bytes_read < size) && timeout--)
220 if ((retval = ftdi_read_data(&ftdic, buf + *bytes_read, size - *bytes_read)) < 0)
223 ERROR("ftdi_read_data: %s", ftdi_get_error_string(&ftdic));
224 return ERROR_JTAG_DEVICE_ERROR;
226 *bytes_read += retval;
230 if (*bytes_read < size)
232 ERROR("couldn't read the requested number of bytes from FT2232 device (%i < %i)", *bytes_read, size);
233 return ERROR_JTAG_DEVICE_ERROR;
239 int ft2232_speed(int speed)
245 buf[0] = 0x86; /* command "set divisor" */
246 buf[1] = speed & 0xff; /* valueL (0=6MHz, 1=3MHz, 2=1.5MHz, ...*/
247 buf[2] = (speed >> 8) & 0xff; /* valueH */
249 DEBUG("%2.2x %2.2x %2.2x", buf[0], buf[1], buf[2]);
250 if (((retval = ft2232_write(buf, 3, &bytes_written)) != ERROR_OK) || (bytes_written != 3))
252 ERROR("couldn't set FT2232 TCK speed");
259 int ft2232_register_commands(struct command_context_s *cmd_ctx)
261 register_command(cmd_ctx, NULL, "ft2232_device_desc", ft2232_handle_device_desc_command,
262 COMMAND_CONFIG, NULL);
263 register_command(cmd_ctx, NULL, "ft2232_serial", ft2232_handle_serial_command,
264 COMMAND_CONFIG, NULL);
265 register_command(cmd_ctx, NULL, "ft2232_layout", ft2232_handle_layout_command,
266 COMMAND_CONFIG, NULL);
267 register_command(cmd_ctx, NULL, "ft2232_vid_pid", ft2232_handle_vid_pid_command,
268 COMMAND_CONFIG, NULL);
272 void ft2232_end_state(state)
274 if (tap_move_map[state] != -1)
278 ERROR("BUG: %i is not a valid end state", state);
283 void ft2232_read_scan(enum scan_type type, u8* buffer, int scan_size)
285 int num_bytes = ((scan_size + 7) / 8);
286 int bits_left = scan_size;
289 while(num_bytes-- > 1)
291 buffer[cur_byte] = BUFFER_READ;
296 buffer[cur_byte] = 0x0;
300 buffer[cur_byte] = BUFFER_READ >> 1;
303 buffer[cur_byte] = (buffer[cur_byte] | ((BUFFER_READ & 0x02) << 6)) >> (8 - bits_left);
307 void ft2232_debug_dump_buffer(void)
313 for (i = 0; i < ft2232_buffer_size; i++)
315 line_p += snprintf(line_p, 256 - (line_p - line), "%2.2x ", ft2232_buffer[i]);
327 int ft2232_send_and_recv(jtag_command_t *first, jtag_command_t *last)
337 #ifdef _DEBUG_USB_IO_
338 struct timeval start, inter, inter2, end;
339 struct timeval d_inter, d_inter2, d_end;
342 #ifdef _DEBUG_USB_COMMS_
343 DEBUG("write buffer (size %i):", ft2232_buffer_size);
344 ft2232_debug_dump_buffer();
347 #ifdef _DEBUG_USB_IO_
348 gettimeofday(&start, NULL);
351 if ((retval = ft2232_write(ft2232_buffer, ft2232_buffer_size, &bytes_written)) != ERROR_OK)
353 ERROR("couldn't write MPSSE commands to FT2232");
357 #ifdef _DEBUG_USB_IO_
358 gettimeofday(&inter, NULL);
361 if (ft2232_expect_read)
364 ft2232_buffer_size = 0;
366 #ifdef _DEBUG_USB_IO_
367 gettimeofday(&inter2, NULL);
370 if ((retval = ft2232_read(ft2232_buffer, ft2232_expect_read, &bytes_read)) != ERROR_OK)
372 ERROR("couldn't read from FT2232");
376 #ifdef _DEBUG_USB_IO_
377 gettimeofday(&end, NULL);
379 timeval_subtract(&d_inter, &inter, &start);
380 timeval_subtract(&d_inter2, &inter2, &start);
381 timeval_subtract(&d_end, &end, &start);
383 INFO("inter: %i.%i, inter2: %i.%i end: %i.%i", d_inter.tv_sec, d_inter.tv_usec, d_inter2.tv_sec, d_inter2.tv_usec, d_end.tv_sec, d_end.tv_usec);
387 ft2232_buffer_size = bytes_read;
389 if (ft2232_expect_read != ft2232_buffer_size)
391 ERROR("ft2232_expect_read (%i) != ft2232_buffer_size (%i) (%i retries)", ft2232_expect_read, ft2232_buffer_size, 100 - timeout);
392 ft2232_debug_dump_buffer();
397 #ifdef _DEBUG_USB_COMMS_
398 DEBUG("read buffer (%i retries): %i bytes", 100 - timeout, ft2232_buffer_size);
399 ft2232_debug_dump_buffer();
403 ft2232_expect_read = 0;
404 ft2232_read_pointer = 0;
412 type = jtag_scan_type(cmd->cmd.scan);
413 if (type != SCAN_OUT)
415 scan_size = jtag_scan_size(cmd->cmd.scan);
416 buffer = calloc(CEIL(scan_size, 8), 1);
417 ft2232_read_scan(type, buffer, scan_size);
418 jtag_read_buffer(buffer, cmd->cmd.scan);
428 ft2232_buffer_size = 0;
433 void ft2232_add_pathmove(pathmove_command_t *cmd)
435 int num_states = cmd->num_states;
445 /* command "Clock Data to TMS/CS Pin (no Read)" */
447 /* number of states remaining */
448 BUFFER_ADD = (num_states % 7) - 1;
450 while (num_states % 7)
452 if (tap_transitions[cur_state].low == cmd->path[state_count])
453 buf_set_u32(&tms_byte, bit_count++, 1, 0x0);
454 else if (tap_transitions[cur_state].high == cmd->path[state_count])
455 buf_set_u32(&tms_byte, bit_count++, 1, 0x1);
458 ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_strings[cur_state], tap_state_strings[cmd->path[state_count]]);
462 cur_state = cmd->path[state_count];
467 BUFFER_ADD = tms_byte;
470 end_state = cur_state;
473 void ft2232_add_scan(int ir_scan, enum scan_type type, u8 *buffer, int scan_size)
475 int num_bytes = (scan_size + 7) / 8;
476 int bits_left = scan_size;
480 if (!((!ir_scan && (cur_state == TAP_SD)) || (ir_scan && (cur_state == TAP_SI))))
482 /* command "Clock Data to TMS/CS Pin (no Read)" */
489 BUFFER_ADD = TAP_MOVE(cur_state, TAP_SI);
494 BUFFER_ADD = TAP_MOVE(cur_state, TAP_SD);
497 //DEBUG("added TMS scan (no read)");
500 /* add command for complete bytes */
501 while (num_bytes > 1)
506 /* Clock Data Bytes In and Out LSB First */
508 //DEBUG("added TDI bytes (io %i)", num_bytes);
510 else if (type == SCAN_OUT)
512 /* Clock Data Bytes Out on -ve Clock Edge LSB First (no Read) */
514 //DEBUG("added TDI bytes (o)");
516 else if (type == SCAN_IN)
518 /* Clock Data Bytes In on +ve Clock Edge LSB First (no Write) */
520 //DEBUG("added TDI bytes (i %i)", num_bytes);
522 thisrun_bytes = (num_bytes > 65537) ? 65536 : (num_bytes - 1);
523 num_bytes -= thisrun_bytes;
524 BUFFER_ADD = (thisrun_bytes - 1) & 0xff;
525 BUFFER_ADD = ((thisrun_bytes - 1) >> 8) & 0xff;
528 /* add complete bytes */
529 while(thisrun_bytes-- > 0)
531 BUFFER_ADD = buffer[cur_byte];
536 else /* (type == SCAN_IN) */
538 bits_left -= 8 * (thisrun_bytes);
542 /* the most signifcant bit is scanned during TAP movement */
544 last_bit = (buffer[cur_byte] >> (bits_left - 1)) & 0x1;
548 /* process remaining bits but the last one */
553 /* Clock Data Bits In and Out LSB First */
555 //DEBUG("added TDI bits (io) %i", bits_left - 1);
557 else if (type == SCAN_OUT)
559 /* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
561 //DEBUG("added TDI bits (o)");
563 else if (type == SCAN_IN)
565 /* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
567 //DEBUG("added TDI bits (i %i)", bits_left - 1);
569 BUFFER_ADD = bits_left - 2;
571 BUFFER_ADD = buffer[cur_byte];
574 if ((ir_scan && (end_state == TAP_SI)) ||
575 (!ir_scan && (end_state == TAP_SD)))
579 /* Clock Data Bits In and Out LSB First */
581 //DEBUG("added TDI bits (io) %i", bits_left - 1);
583 else if (type == SCAN_OUT)
585 /* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
587 //DEBUG("added TDI bits (o)");
589 else if (type == SCAN_IN)
591 /* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
593 //DEBUG("added TDI bits (i %i)", bits_left - 1);
596 BUFFER_ADD = last_bit;
600 /* move from Shift-IR/DR to end state */
601 if (type != SCAN_OUT)
603 /* Clock Data to TMS/CS Pin with Read */
605 //DEBUG("added TMS scan (read)");
609 /* Clock Data to TMS/CS Pin (no Read) */
611 //DEBUG("added TMS scan (no read)");
614 BUFFER_ADD = TAP_MOVE(cur_state, end_state) | (last_bit << 7);
615 cur_state = end_state;
619 int ft2232_large_scan(scan_command_t *cmd, enum scan_type type, u8 *buffer, int scan_size)
621 int num_bytes = (scan_size + 7) / 8;
622 int bits_left = scan_size;
625 u8 *receive_buffer = malloc(CEIL(scan_size, 8));
626 u8 *receive_pointer = receive_buffer;
630 int thisrun_read = 0;
634 ERROR("BUG: large IR scans are not supported");
638 if (cur_state != TAP_SD)
640 /* command "Clock Data to TMS/CS Pin (no Read)" */
645 BUFFER_ADD = TAP_MOVE(cur_state, TAP_SD);
649 if ((retval = ft2232_write(ft2232_buffer, ft2232_buffer_size, &bytes_written)) != ERROR_OK)
651 ERROR("couldn't write MPSSE commands to FT2232");
654 DEBUG("ft2232_buffer_size: %i, bytes_written: %i", ft2232_buffer_size, bytes_written);
655 ft2232_buffer_size = 0;
657 /* add command for complete bytes */
658 while (num_bytes > 1)
664 /* Clock Data Bytes In and Out LSB First */
666 //DEBUG("added TDI bytes (io %i)", num_bytes);
668 else if (type == SCAN_OUT)
670 /* Clock Data Bytes Out on -ve Clock Edge LSB First (no Read) */
672 //DEBUG("added TDI bytes (o)");
674 else if (type == SCAN_IN)
676 /* Clock Data Bytes In on +ve Clock Edge LSB First (no Write) */
678 //DEBUG("added TDI bytes (i %i)", num_bytes);
680 thisrun_bytes = (num_bytes > 65537) ? 65536 : (num_bytes - 1);
681 thisrun_read = thisrun_bytes;
682 num_bytes -= thisrun_bytes;
683 BUFFER_ADD = (thisrun_bytes - 1) & 0xff;
684 BUFFER_ADD = ((thisrun_bytes - 1) >> 8) & 0xff;
687 /* add complete bytes */
688 while(thisrun_bytes-- > 0)
690 BUFFER_ADD = buffer[cur_byte];
695 else /* (type == SCAN_IN) */
697 bits_left -= 8 * (thisrun_bytes);
700 if ((retval = ft2232_write(ft2232_buffer, ft2232_buffer_size, &bytes_written)) != ERROR_OK)
702 ERROR("couldn't write MPSSE commands to FT2232");
705 DEBUG("ft2232_buffer_size: %i, bytes_written: %i", ft2232_buffer_size, bytes_written);
706 ft2232_buffer_size = 0;
708 if (type != SCAN_OUT)
710 if ((retval = ft2232_read(receive_pointer, thisrun_read, &bytes_read)) != ERROR_OK)
712 ERROR("couldn't read from FT2232");
715 DEBUG("thisrun_read: %i, bytes_read: %i", thisrun_read, bytes_read);
716 receive_pointer += bytes_read;
722 /* the most signifcant bit is scanned during TAP movement */
724 last_bit = (buffer[cur_byte] >> (bits_left - 1)) & 0x1;
728 /* process remaining bits but the last one */
733 /* Clock Data Bits In and Out LSB First */
735 //DEBUG("added TDI bits (io) %i", bits_left - 1);
737 else if (type == SCAN_OUT)
739 /* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
741 //DEBUG("added TDI bits (o)");
743 else if (type == SCAN_IN)
745 /* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
747 //DEBUG("added TDI bits (i %i)", bits_left - 1);
749 BUFFER_ADD = bits_left - 2;
751 BUFFER_ADD = buffer[cur_byte];
753 if (type != SCAN_OUT)
757 if (end_state == TAP_SD)
761 /* Clock Data Bits In and Out LSB First */
763 //DEBUG("added TDI bits (io) %i", bits_left - 1);
765 else if (type == SCAN_OUT)
767 /* Clock Data Bits Out on -ve Clock Edge LSB First (no Read) */
769 //DEBUG("added TDI bits (o)");
771 else if (type == SCAN_IN)
773 /* Clock Data Bits In on +ve Clock Edge LSB First (no Write) */
775 //DEBUG("added TDI bits (i %i)", bits_left - 1);
778 BUFFER_ADD = last_bit;
782 /* move from Shift-IR/DR to end state */
783 if (type != SCAN_OUT)
785 /* Clock Data to TMS/CS Pin with Read */
787 //DEBUG("added TMS scan (read)");
791 /* Clock Data to TMS/CS Pin (no Read) */
793 //DEBUG("added TMS scan (no read)");
796 BUFFER_ADD = TAP_MOVE(cur_state, end_state) | (last_bit << 7);
797 cur_state = end_state;
800 if (type != SCAN_OUT)
803 if ((retval = ft2232_write(ft2232_buffer, ft2232_buffer_size, &bytes_written)) != ERROR_OK)
805 ERROR("couldn't write MPSSE commands to FT2232");
808 DEBUG("ft2232_buffer_size: %i, bytes_written: %i", ft2232_buffer_size, bytes_written);
809 ft2232_buffer_size = 0;
811 if (type != SCAN_OUT)
813 if ((retval = ft2232_read(receive_pointer, thisrun_read, &bytes_read)) != ERROR_OK)
815 ERROR("couldn't read from FT2232");
818 DEBUG("thisrun_read: %i, bytes_read: %i", thisrun_read, bytes_read);
819 receive_pointer += bytes_read;
825 int ft2232_predict_scan_out(int scan_size, enum scan_type type)
827 int predicted_size = 3;
828 int num_bytes = (scan_size - 1) / 8;
830 if (cur_state != TAP_SD)
833 if (type == SCAN_IN) /* only from device to host */
836 predicted_size += (CEIL(num_bytes, 65536)) * 3;
837 /* remaining bits - 1 (up to 7) */
838 predicted_size += ((scan_size - 1) % 8) ? 2 : 0;
840 else /* host to device, or bidirectional */
843 predicted_size += num_bytes + (CEIL(num_bytes, 65536)) * 3;
844 /* remaining bits -1 (up to 7) */
845 predicted_size += ((scan_size - 1) % 8) ? 3 : 0;
848 return predicted_size;
851 int ft2232_predict_scan_in(int scan_size, enum scan_type type)
853 int predicted_size = 0;
855 if (type != SCAN_OUT)
858 predicted_size += (CEIL(scan_size, 8) > 1) ? (CEIL(scan_size, 8) - 1) : 0;
859 /* remaining bits - 1 */
860 predicted_size += ((scan_size - 1) % 8) ? 1 : 0;
861 /* last bit (from TMS scan) */
865 //DEBUG("scan_size: %i, predicted_size: %i", scan_size, predicted_size);
867 return predicted_size;
870 void usbjtag_reset(int trst, int srst)
875 if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
876 low_direction |= nTRSTnOE; /* switch to output pin (output is low) */
878 low_output &= ~nTRST; /* switch output low */
882 if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
883 low_direction &= ~nTRSTnOE; /* switch to input pin (high-Z + internal and external pullup) */
885 low_output |= nTRST; /* switch output high */
890 if (jtag_reset_config & RESET_SRST_PUSH_PULL)
891 low_output &= ~nSRST; /* switch output low */
893 low_direction |= nSRSTnOE; /* switch to output pin (output is low) */
897 if (jtag_reset_config & RESET_SRST_PUSH_PULL)
898 low_output |= nSRST; /* switch output high */
900 low_direction &= ~nSRSTnOE; /* switch to input pin (high-Z) */
903 /* command "set data bits low byte" */
905 BUFFER_ADD = low_output;
906 BUFFER_ADD = low_direction;
910 void jtagkey_reset(int trst, int srst)
915 if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
916 high_output &= ~nTRSTnOE;
918 high_output &= ~nTRST;
922 if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
923 high_output |= nTRSTnOE;
925 high_output |= nTRST;
930 if (jtag_reset_config & RESET_SRST_PUSH_PULL)
931 high_output &= ~nSRST;
933 high_output &= ~nSRSTnOE;
937 if (jtag_reset_config & RESET_SRST_PUSH_PULL)
938 high_output |= nSRST;
940 high_output |= nSRSTnOE;
943 /* command "set data bits high byte" */
945 BUFFER_ADD = high_output;
946 BUFFER_ADD = high_direction;
947 DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst, srst, high_output, high_direction);
950 void olimex_jtag_reset(int trst, int srst)
955 if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
956 high_output &= ~nTRSTnOE;
958 high_output &= ~nTRST;
962 if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
963 high_output |= nTRSTnOE;
965 high_output |= nTRST;
970 high_output |= nSRST;
974 high_output &= ~nSRST;
977 /* command "set data bits high byte" */
979 BUFFER_ADD = high_output;
980 BUFFER_ADD = high_direction;
981 DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst, srst, high_output, high_direction);
984 void m5960_reset(int trst, int srst)
989 low_output &= ~nTRST;
1002 low_output &= ~nSRST;
1005 /* command "set data bits low byte" */
1007 BUFFER_ADD = low_output;
1008 BUFFER_ADD = low_direction;
1009 DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst, srst, high_output, high_direction);
1012 void turtle_reset(int trst, int srst)
1018 low_output |= nSRST;
1022 low_output &= ~nSRST;
1025 /* command "set data bits high byte" */
1027 BUFFER_ADD = low_output;
1028 BUFFER_ADD = low_direction;
1029 DEBUG("srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x", srst, low_output, low_direction);
1032 int ft2232_execute_queue()
1034 jtag_command_t *cmd = jtag_command_queue; /* currently processed command */
1035 jtag_command_t *first_unsent = cmd; /* next command that has to be sent */
1037 int scan_size; /* size of IR or DR scan */
1038 enum scan_type type;
1040 int predicted_size = 0;
1041 int require_send = 0;
1043 ft2232_buffer_size = 0;
1044 ft2232_expect_read = 0;
1046 /* blink, if the current layout has that feature */
1054 case JTAG_END_STATE:
1055 if (cmd->cmd.end_state->end_state != -1)
1056 ft2232_end_state(cmd->cmd.end_state->end_state);
1059 /* only send the maximum buffer size that FT2232C can handle */
1061 if (ft2232_buffer_size + predicted_size + 1 > FT2232_BUFFER_SIZE)
1063 ft2232_send_and_recv(first_unsent, cmd);
1068 layout->reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
1071 #ifdef _DEBUG_JTAG_IO_
1072 DEBUG("trst: %i, srst: %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst);
1076 /* only send the maximum buffer size that FT2232C can handle */
1078 if (cur_state != TAP_RTI)
1079 predicted_size += 3;
1080 predicted_size += 3 * CEIL(cmd->cmd.runtest->num_cycles, 7);
1081 if ((cmd->cmd.runtest->end_state != -1) && (cmd->cmd.runtest->end_state != TAP_RTI))
1082 predicted_size += 3;
1083 if ((cmd->cmd.runtest->end_state == -1) && (end_state != TAP_RTI))
1084 predicted_size += 3;
1085 if (ft2232_buffer_size + predicted_size + 1 > FT2232_BUFFER_SIZE)
1087 ft2232_send_and_recv(first_unsent, cmd);
1091 if (cur_state != TAP_RTI)
1093 /* command "Clock Data to TMS/CS Pin (no Read)" */
1098 BUFFER_ADD = TAP_MOVE(cur_state, TAP_RTI);
1099 cur_state = TAP_RTI;
1102 i = cmd->cmd.runtest->num_cycles;
1105 /* command "Clock Data to TMS/CS Pin (no Read)" */
1108 BUFFER_ADD = (i > 7) ? 6 : (i - 1);
1111 cur_state = TAP_RTI;
1112 i -= (i > 7) ? 7 : i;
1113 //DEBUG("added TMS scan (no read)");
1115 if (cmd->cmd.runtest->end_state != -1)
1116 ft2232_end_state(cmd->cmd.runtest->end_state);
1117 if (cur_state != end_state)
1119 /* command "Clock Data to TMS/CS Pin (no Read)" */
1124 BUFFER_ADD = TAP_MOVE(cur_state, end_state);
1125 cur_state = end_state;
1126 //DEBUG("added TMS scan (no read)");
1129 #ifdef _DEBUG_JTAG_IO_
1130 DEBUG("runtest: %i, end in %i", cmd->cmd.runtest->num_cycles, end_state);
1133 case JTAG_STATEMOVE:
1134 /* only send the maximum buffer size that FT2232C can handle */
1136 if (ft2232_buffer_size + predicted_size + 1 > FT2232_BUFFER_SIZE)
1138 ft2232_send_and_recv(first_unsent, cmd);
1142 if (cmd->cmd.statemove->end_state != -1)
1143 ft2232_end_state(cmd->cmd.statemove->end_state);
1144 /* command "Clock Data to TMS/CS Pin (no Read)" */
1149 BUFFER_ADD = TAP_MOVE(cur_state, end_state);
1150 //DEBUG("added TMS scan (no read)");
1151 cur_state = end_state;
1153 #ifdef _DEBUG_JTAG_IO_
1154 DEBUG("statemove: %i", end_state);
1158 /* only send the maximum buffer size that FT2232C can handle */
1159 predicted_size = 3 * CEIL(cmd->cmd.pathmove->num_states, 7);
1160 if (ft2232_buffer_size + predicted_size + 1 > FT2232_BUFFER_SIZE)
1162 ft2232_send_and_recv(first_unsent, cmd);
1166 ft2232_add_pathmove(cmd->cmd.pathmove);
1168 #ifdef _DEBUG_JTAG_IO_
1169 DEBUG("pathmove: %i states, end in %i", cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]);
1173 scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer);
1174 type = jtag_scan_type(cmd->cmd.scan);
1175 predicted_size = ft2232_predict_scan_out(scan_size, type);
1176 if ((predicted_size + 1) > FT2232_BUFFER_SIZE)
1178 DEBUG("oversized ft2232 scan (predicted_size > FT2232_BUFFER_SIZE)");
1179 /* unsent commands before this */
1180 if (first_unsent != cmd)
1181 ft2232_send_and_recv(first_unsent, cmd);
1183 /* current command */
1184 if (cmd->cmd.scan->end_state != -1)
1185 ft2232_end_state(cmd->cmd.scan->end_state);
1186 ft2232_large_scan(cmd->cmd.scan, type, buffer, scan_size);
1188 first_unsent = cmd->next;
1193 else if (ft2232_buffer_size + predicted_size + 1 > FT2232_BUFFER_SIZE)
1195 DEBUG("ft2232 buffer size reached, sending queued commands (first_unsent: %p, cmd: %p)", first_unsent, cmd);
1196 ft2232_send_and_recv(first_unsent, cmd);
1200 ft2232_expect_read += ft2232_predict_scan_in(scan_size, type);
1201 //DEBUG("new read size: %i", ft2232_expect_read);
1202 if (cmd->cmd.scan->end_state != -1)
1203 ft2232_end_state(cmd->cmd.scan->end_state);
1204 ft2232_add_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size);
1208 #ifdef _DEBUG_JTAG_IO_
1209 DEBUG("%s scan, %i bit, end in %i", (cmd->cmd.scan->ir_scan) ? "IR" : "DR", scan_size, end_state);
1213 ft2232_send_and_recv(first_unsent, cmd);
1214 first_unsent = cmd->next;
1215 jtag_sleep(cmd->cmd.sleep->us);
1216 #ifdef _DEBUG_JTAG_IO_
1217 DEBUG("sleep %i usec", cmd->cmd.sleep->us);
1221 ERROR("BUG: unknown JTAG command type encountered");
1227 if (require_send > 0)
1228 ft2232_send_and_recv(first_unsent, cmd);
1233 #if BUILD_FT2232_FTD2XX == 1
1234 static int ft2232_init_ftd2xx(u16 vid, u16 pid, int more, int *try_more)
1237 DWORD openex_flags = 0;
1238 char *openex_string = NULL;
1241 DEBUG("'ft2232' interface using FTD2XX with '%s' layout (%4.4x:%4.4x)",
1242 ft2232_layout, vid, pid);
1245 /* Add non-standard Vid/Pid to the linux driver */
1246 if ((status = FT_SetVIDPID(vid, pid)) != FT_OK)
1248 WARNING("couldn't add %4.4x:%4.4x",
1253 if (ft2232_device_desc && ft2232_serial)
1255 WARNING("can't open by device description and serial number, giving precedence to serial");
1256 ft2232_device_desc = NULL;
1259 if (ft2232_device_desc)
1261 openex_string = ft2232_device_desc;
1262 openex_flags = FT_OPEN_BY_DESCRIPTION;
1264 else if (ft2232_serial)
1266 openex_string = ft2232_serial;
1267 openex_flags = FT_OPEN_BY_SERIAL_NUMBER;
1271 ERROR("neither device description nor serial number specified");
1272 ERROR("please add \"ft2232_device_desc <string>\" or \"ft2232_serial <string>\" to your .cfg file");
1274 return ERROR_JTAG_INIT_FAILED;
1277 if ((status = FT_OpenEx(openex_string, openex_flags, &ftdih)) != FT_OK)
1282 WARNING("unable to open ftdi device (trying more): %lu",
1285 return ERROR_JTAG_INIT_FAILED;
1287 ERROR("unable to open ftdi device: %lu", status);
1288 status = FT_ListDevices(&num_devices, NULL, FT_LIST_NUMBER_ONLY);
1289 if (status == FT_OK)
1291 char **desc_array = malloc(sizeof(char*) * (num_devices + 1));
1294 for (i = 0; i < num_devices; i++)
1295 desc_array[i] = malloc(64);
1296 desc_array[num_devices] = NULL;
1298 status = FT_ListDevices(desc_array, &num_devices, FT_LIST_ALL | openex_flags);
1300 if (status == FT_OK)
1302 ERROR("ListDevices: %lu\n", num_devices);
1303 for (i = 0; i < num_devices; i++)
1304 ERROR("%i: %s", i, desc_array[i]);
1307 for (i = 0; i < num_devices; i++)
1308 free(desc_array[i]);
1313 printf("ListDevices: NONE\n");
1315 return ERROR_JTAG_INIT_FAILED;
1318 if ((status = FT_SetLatencyTimer(ftdih, 2)) != FT_OK)
1320 ERROR("unable to set latency timer: %lu", status);
1321 return ERROR_JTAG_INIT_FAILED;
1324 if ((status = FT_GetLatencyTimer(ftdih, &latency_timer)) != FT_OK)
1326 ERROR("unable to get latency timer: %lu", status);
1327 return ERROR_JTAG_INIT_FAILED;
1331 DEBUG("current latency timer: %i", latency_timer);
1334 if ((status = FT_SetTimeouts(ftdih, 5000, 5000)) != FT_OK)
1336 ERROR("unable to set timeouts: %lu", status);
1337 return ERROR_JTAG_INIT_FAILED;
1340 if ((status = FT_SetBitMode(ftdih, 0x0b, 2)) != FT_OK)
1342 ERROR("unable to enable bit i/o mode: %lu", status);
1343 return ERROR_JTAG_INIT_FAILED;
1349 static int ft2232_purge_ftd2xx(void)
1353 if ((status = FT_Purge(ftdih, FT_PURGE_RX | FT_PURGE_TX)) != FT_OK)
1355 ERROR("error purging ftd2xx device: %lu", status);
1356 return ERROR_JTAG_INIT_FAILED;
1361 #endif /* BUILD_FT2232_FTD2XX == 1 */
1363 #if BUILD_FT2232_LIBFTDI == 1
1364 static int ft2232_init_libftdi(u16 vid, u16 pid, int more, int *try_more)
1368 DEBUG("'ft2232' interface using libftdi with '%s' layout (%4.4x:%4.4x)",
1369 ft2232_layout, vid, pid);
1371 if (ftdi_init(&ftdic) < 0)
1372 return ERROR_JTAG_INIT_FAILED;
1374 /* context, vendor id, product id */
1375 if (ftdi_usb_open_desc(&ftdic, vid, pid, ft2232_device_desc,
1376 ft2232_serial) < 0) {
1378 WARNING("unable to open ftdi device (trying more): %s",
1381 ERROR("unable to open ftdi device: %s", ftdic.error_str);
1383 return ERROR_JTAG_INIT_FAILED;
1386 if (ftdi_set_interface(&ftdic, INTERFACE_A) < 0)
1388 ERROR("unable to select FT2232 channel A: %s", ftdic.error_str);
1389 return ERROR_JTAG_INIT_FAILED;
1392 if (ftdi_usb_reset(&ftdic) < 0)
1394 ERROR("unable to reset ftdi device");
1395 return ERROR_JTAG_INIT_FAILED;
1398 if (ftdi_set_latency_timer(&ftdic, 2) < 0)
1400 ERROR("unable to set latency timer");
1401 return ERROR_JTAG_INIT_FAILED;
1404 if (ftdi_get_latency_timer(&ftdic, &latency_timer) < 0)
1406 ERROR("unable to get latency timer");
1407 return ERROR_JTAG_INIT_FAILED;
1411 DEBUG("current latency timer: %i", latency_timer);
1414 ftdi_set_bitmode(&ftdic, 0x0b, 2); /* ctx, JTAG I/O mask */
1419 static int ft2232_purge_libftdi(void)
1421 if (ftdi_usb_purge_buffers(&ftdic) < 0)
1423 ERROR("ftdi_purge_buffers: %s", ftdic.error_str);
1424 return ERROR_JTAG_INIT_FAILED;
1429 #endif /* BUILD_FT2232_LIBFTDI == 1 */
1431 int ft2232_init(void)
1436 ft2232_layout_t *cur_layout = ft2232_layouts;
1439 if ((ft2232_layout == NULL) || (ft2232_layout[0] == 0))
1441 ft2232_layout = "usbjtag";
1442 WARNING("No ft2232 layout specified, using default 'usbjtag'");
1445 while (cur_layout->name)
1447 if (strcmp(cur_layout->name, ft2232_layout) == 0)
1449 layout = cur_layout;
1457 ERROR("No matching layout found for %s", ft2232_layout);
1458 return ERROR_JTAG_INIT_FAILED;
1461 for (i = 0; 1; i++) {
1463 * "more indicates that there are more IDs to try, so we should
1464 * not print an error for an ID mismatch (but for anything
1467 * try_more indicates that the error code returned indicates an
1468 * ID mismatch (and nothing else) and that we should proceeed
1469 * with the next ID pair.
1471 int more = ft2232_vid[i+1] || ft2232_pid[i+1];
1474 #if BUILD_FT2232_FTD2XX == 1
1475 retval = ft2232_init_ftd2xx(ft2232_vid[i], ft2232_pid[i],
1477 #elif BUILD_FT2232_LIBFTDI == 1
1478 retval = ft2232_init_libftdi(ft2232_vid[i], ft2232_pid[i],
1483 if (!more || !try_more)
1487 ft2232_buffer_size = 0;
1488 ft2232_buffer = malloc(FT2232_BUFFER_SIZE);
1490 if (layout->init() != ERROR_OK)
1491 return ERROR_JTAG_INIT_FAILED;
1493 ft2232_speed(jtag_speed);
1495 buf[0] = 0x85; /* Disconnect TDI/DO to TDO/DI for Loopback */
1496 if (((retval = ft2232_write(buf, 1, &bytes_written)) != ERROR_OK) || (bytes_written != 1))
1498 ERROR("couldn't write to FT2232 to disable loopback");
1499 return ERROR_JTAG_INIT_FAILED;
1502 #if BUILD_FT2232_FTD2XX == 1
1503 return ft2232_purge_ftd2xx();
1504 #elif BUILD_FT2232_LIBFTDI == 1
1505 return ft2232_purge_libftdi();
1511 int usbjtag_init(void)
1517 low_direction = 0x0b;
1519 if (strcmp(ft2232_layout, "usbjtag") == 0)
1526 else if (strcmp(ft2232_layout, "signalyzer") == 0)
1533 else if (strcmp(ft2232_layout, "evb_lm3s811") == 0)
1540 low_direction = 0x8b;
1544 ERROR("BUG: usbjtag_init called for unknown layout '%s'", ft2232_layout);
1545 return ERROR_JTAG_INIT_FAILED;
1548 if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
1550 low_direction &= ~nTRSTnOE; /* nTRST input */
1551 low_output &= ~nTRST; /* nTRST = 0 */
1555 low_direction |= nTRSTnOE; /* nTRST output */
1556 low_output |= nTRST; /* nTRST = 1 */
1559 if (jtag_reset_config & RESET_SRST_PUSH_PULL)
1561 low_direction |= nSRSTnOE; /* nSRST output */
1562 low_output |= nSRST; /* nSRST = 1 */
1566 low_direction &= ~nSRSTnOE; /* nSRST input */
1567 low_output &= ~nSRST; /* nSRST = 0 */
1570 /* initialize low byte for jtag */
1571 buf[0] = 0x80; /* command "set data bits low byte" */
1572 buf[1] = low_output; /* value (TMS=1,TCK=0, TDI=0, xRST high) */
1573 buf[2] = low_direction; /* dir (output=1), TCK/TDI/TMS=out, TDO=in */
1574 DEBUG("%2.2x %2.2x %2.2x", buf[0], buf[1], buf[2]);
1576 if (((ft2232_write(buf, 3, &bytes_written)) != ERROR_OK) || (bytes_written != 3))
1578 ERROR("couldn't initialize FT2232 with 'USBJTAG' layout");
1579 return ERROR_JTAG_INIT_FAILED;
1585 int jtagkey_init(void)
1591 low_direction = 0x1b;
1593 /* initialize low byte for jtag */
1594 buf[0] = 0x80; /* command "set data bits low byte" */
1595 buf[1] = low_output; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
1596 buf[2] = low_direction; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE=out */
1597 DEBUG("%2.2x %2.2x %2.2x", buf[0], buf[1], buf[2]);
1599 if (((ft2232_write(buf, 3, &bytes_written)) != ERROR_OK) || (bytes_written != 3))
1601 ERROR("couldn't initialize FT2232 with 'JTAGkey' layout");
1602 return ERROR_JTAG_INIT_FAILED;
1605 if (strcmp(layout->name, "jtagkey") == 0)
1612 else if ((strcmp(layout->name, "jtagkey_prototype_v1") == 0) ||
1613 (strcmp(layout->name, "oocdlink") == 0))
1622 ERROR("BUG: jtagkey_init called for non jtagkey layout");
1627 high_direction = 0x0f;
1629 if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
1631 high_output |= nTRSTnOE;
1632 high_output &= ~nTRST;
1636 high_output &= ~nTRSTnOE;
1637 high_output |= nTRST;
1640 if (jtag_reset_config & RESET_SRST_PUSH_PULL)
1642 high_output &= ~nSRSTnOE;
1643 high_output |= nSRST;
1647 high_output |= nSRSTnOE;
1648 high_output &= ~nSRST;
1651 /* initialize high port */
1652 buf[0] = 0x82; /* command "set data bits high byte" */
1653 buf[1] = high_output; /* value */
1654 buf[2] = high_direction; /* all outputs (xRST and xRSTnOE) */
1655 DEBUG("%2.2x %2.2x %2.2x", buf[0], buf[1], buf[2]);
1657 if (((ft2232_write(buf, 3, &bytes_written)) != ERROR_OK) || (bytes_written != 3))
1659 ERROR("couldn't initialize FT2232 with 'JTAGkey' layout");
1660 return ERROR_JTAG_INIT_FAILED;
1666 int olimex_jtag_init(void)
1672 low_direction = 0x1b;
1674 /* initialize low byte for jtag */
1675 buf[0] = 0x80; /* command "set data bits low byte" */
1676 buf[1] = low_output; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
1677 buf[2] = low_direction; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE=out */
1678 DEBUG("%2.2x %2.2x %2.2x", buf[0], buf[1], buf[2]);
1680 if (((ft2232_write(buf, 3, &bytes_written)) != ERROR_OK) || (bytes_written != 3))
1682 ERROR("couldn't initialize FT2232 with 'JTAGkey' layout");
1683 return ERROR_JTAG_INIT_FAILED;
1689 nSRSTnOE = 0x00; /* no output enable for nSRST */
1692 high_direction = 0x0f;
1694 if (jtag_reset_config & RESET_TRST_OPEN_DRAIN)
1696 high_output |= nTRSTnOE;
1697 high_output &= ~nTRST;
1701 high_output &= ~nTRSTnOE;
1702 high_output |= nTRST;
1705 if (jtag_reset_config & RESET_SRST_PUSH_PULL)
1707 ERROR("can't set nSRST to push-pull on the Olimex ARM-USB-OCD");
1711 high_output &= ~nSRST;
1714 /* turn red LED on */
1715 high_output |= 0x08;
1717 /* initialize high port */
1718 buf[0] = 0x82; /* command "set data bits high byte" */
1719 buf[1] = high_output; /* value */
1720 buf[2] = high_direction; /* all outputs (xRST and xRSTnOE) */
1721 DEBUG("%2.2x %2.2x %2.2x", buf[0], buf[1], buf[2]);
1723 if (((ft2232_write(buf, 3, &bytes_written)) != ERROR_OK) || (bytes_written != 3))
1725 ERROR("couldn't initialize FT2232 with 'JTAGkey' layout");
1726 return ERROR_JTAG_INIT_FAILED;
1732 int m5960_init(void)
1738 low_direction = 0xfb;
1740 /* initialize low byte for jtag */
1741 buf[0] = 0x80; /* command "set data bits low byte" */
1742 buf[1] = low_output; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
1743 buf[2] = low_direction; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE[12]=out, n[ST]srst=out */
1744 DEBUG("%2.2x %2.2x %2.2x", buf[0], buf[1], buf[2]);
1746 if (((ft2232_write(buf, 3, &bytes_written)) != ERROR_OK) || (bytes_written != 3))
1748 ERROR("couldn't initialize FT2232 with 'm5960' layout");
1749 return ERROR_JTAG_INIT_FAILED;
1753 nTRSTnOE = 0x0; /* not output enable for nTRST */
1755 nSRSTnOE = 0x00; /* no output enable for nSRST */
1758 high_direction = 0x0c;
1760 /* turn red LED1 on, LED2 off */
1761 high_output |= 0x08;
1763 /* initialize high port */
1764 buf[0] = 0x82; /* command "set data bits high byte" */
1765 buf[1] = high_output; /* value */
1766 buf[2] = high_direction; /* all outputs (xRST and xRSTnOE) */
1767 DEBUG("%2.2x %2.2x %2.2x", buf[0], buf[1], buf[2]);
1769 if (((ft2232_write(buf, 3, &bytes_written)) != ERROR_OK) || (bytes_written != 3))
1771 ERROR("couldn't initialize FT2232 with 'm5960' layout");
1772 return ERROR_JTAG_INIT_FAILED;
1778 int turtle_init(void)
1784 low_direction = 0x5b;
1786 /* initialize low byte for jtag */
1787 buf[0] = 0x80; /* command "set data bits low byte" */
1788 buf[1] = low_output; /* value (TMS=1,TCK=0, TDI=0, nOE=0) */
1789 buf[2] = low_direction; /* dir (output=1), TCK/TDI/TMS=out, TDO=in, nOE=out */
1790 DEBUG("%2.2x %2.2x %2.2x", buf[0], buf[1], buf[2]);
1792 if (((ft2232_write(buf, 3, &bytes_written)) != ERROR_OK) || (bytes_written != 3))
1794 ERROR("couldn't initialize FT2232 with 'turtelizer2' layout");
1795 return ERROR_JTAG_INIT_FAILED;
1801 high_direction = 0x0C;
1803 /* initialize high port */
1804 buf[0] = 0x82; /* command "set data bits high byte" */
1805 buf[1] = high_output;
1806 buf[2] = high_direction;
1807 DEBUG("%2.2x %2.2x %2.2x", buf[0], buf[1], buf[2]);
1809 if (((ft2232_write(buf, 3, &bytes_written)) != ERROR_OK) || (bytes_written != 3))
1811 ERROR("couldn't initialize FT2232 with 'turtelizer2' layout");
1812 return ERROR_JTAG_INIT_FAILED;
1818 void olimex_jtag_blink(void)
1820 /* Olimex ARM-USB-OCD has a LED connected to ACBUS3
1821 * ACBUS3 is bit 3 of the GPIOH port
1823 if (high_output & 0x08)
1825 /* set port pin high */
1826 high_output &= 0x07;
1830 /* set port pin low */
1831 high_output |= 0x08;
1835 BUFFER_ADD = high_output;
1836 BUFFER_ADD = high_direction;
1839 void turtle_jtag_blink(void)
1842 * Turtelizer2 has two LEDs connected to ACBUS2 and ACBUS3
1844 if (high_output & 0x08)
1854 BUFFER_ADD = high_output;
1855 BUFFER_ADD = high_direction;
1859 int ft2232_quit(void)
1861 #if BUILD_FT2232_FTD2XX == 1
1864 status = FT_Close(ftdih);
1865 #elif BUILD_FT2232_LIBFTDI == 1
1866 ftdi_disable_bitbang(&ftdic);
1868 ftdi_usb_close(&ftdic);
1870 ftdi_deinit(&ftdic);
1873 free(ft2232_buffer);
1878 int ft2232_handle_device_desc_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1882 ft2232_device_desc = strdup(args[0]);
1886 ERROR("expected exactly one argument to ft2232_device_desc <description>");
1892 int ft2232_handle_serial_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1896 ft2232_serial = strdup(args[0]);
1900 ERROR("expected exactly one argument to ft2232_serial <serial-number>");
1906 int ft2232_handle_layout_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1911 ft2232_layout = malloc(strlen(args[0]) + 1);
1912 strcpy(ft2232_layout, args[0]);
1917 int ft2232_handle_vid_pid_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1921 if (argc > MAX_USB_IDS*2) {
1922 WARNING("ignoring extra IDs in ft2232_vid_pid "
1923 "(maximum is %d pairs)", MAX_USB_IDS);
1924 argc = MAX_USB_IDS*2;
1926 if (argc < 2 || (argc & 1))
1928 WARNING("incomplete ft2232_vid_pid configuration directive");
1933 for (i = 0; i+1 < argc; i += 2) {
1934 ft2232_vid[i >> 1] = strtol(args[i], NULL, 0);
1935 ft2232_pid[i >> 1] = strtol(args[i+1], NULL, 0);
1938 * Explicitly terminate, in case there are multiples instances of
1941 ft2232_vid[i >> 1] = ft2232_pid[i >> 1] = 0;