⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb_jtag.patch

📁 网上流传的usb_blaster原理图里的CPLD源码,主要是实现usb时序转换成JATG时序输出!
💻 PATCH
📖 第 1 页 / 共 2 页
字号:
Index: configure.in===================================================================--- configure.in	(.../vendor/openocd)	(Revision 49)+++ configure.in	(.../branches/openocd-usb_jtag)	(Revision 49)@@ -32,6 +32,14 @@   AS_HELP_STRING([--enable-ft2232_ftd2xx], [Enable building support for FT2232 based devices using the FTD2XX driver]),    [build_ft2232_ftd2xx=$enableval], [build_ft2232_ftd2xx=no])  +AC_ARG_ENABLE(usb_blaster_libftdi,+  AS_HELP_STRING([--enable-usb_blaster_libftdi], [Enable building support for the Altera USB-Blaster using the libftdi driver]), +  [build_usb_blaster_libftdi=$enableval], [build_usb_blaster_libftdi=no])++AC_ARG_ENABLE(usb_blaster_ftd2xx,+  AS_HELP_STRING([--enable-usb_blaster_ftd2xx], [Enable building support for the Altera USB-Blaster using the FTD2XX driver]), +  [build_usb_blaster_ftd2xx=$enableval], [build_usb_blaster_ftd2xx=no])+ AC_ARG_ENABLE(amtjtagaccel,   AS_HELP_STRING([--enable-amtjtagaccel], [Enable building the Amontec JTAG-Accelerator driver]),    [build_amtjtagaccel=$enableval], [build_amtjtagaccel=no])@@ -141,6 +149,18 @@   AC_DEFINE(BUILD_FT2232_FTD2XX, 0, [0 if you don't want ftd2xx ft2232.]) fi +if test $build_usb_blaster_libftdi = yes; then+  AC_DEFINE(BUILD_USB_BLASTER_LIBFTDI, 1, [1 if you want libftdi usb_blaster.])+else+  AC_DEFINE(BUILD_USB_BLASTER_LIBFTDI, 0, [0 if you don't want libftdi usb_blaster.])+fi++if test $build_usb_blaster_ftd2xx = yes; then+  AC_DEFINE(BUILD_USB_BLASTER_FTD2XX, 1, [1 if you want ftd2xx usb_blaster.])+else+  AC_DEFINE(BUILD_USB_BLASTER_FTD2XX, 0, [0 if you don't want ftd2xx usb_blaster.])+fi+ if test $build_amtjtagaccel = yes; then   AC_DEFINE(BUILD_AMTJTAGACCEL, 1, [1 if you want the Amontec JTAG-Accelerator driver.]) else@@ -163,6 +183,8 @@ AM_CONDITIONAL(BITBANG, test $build_bitbang = yes) AM_CONDITIONAL(FT2232_LIBFTDI, test $build_ft2232_libftdi = yes) AM_CONDITIONAL(FT2232_FTD2XX, test $build_ft2232_ftd2xx = yes)+AM_CONDITIONAL(USB_BLASTER_LIBFTDI, test $build_usb_blaster_libftdi = yes)+AM_CONDITIONAL(USB_BLASTER_FTD2XX, test $build_usb_blaster_ftd2xx = yes) AM_CONDITIONAL(AMTJTAGACCEL, test $build_amtjtagaccel = yes) AM_CONDITIONAL(GW16012, test $build_gw16012 = yes) AM_CONDITIONAL(IS_CYGWIN, test $is_cygwin = yes)Index: src/jtag/jtag.c===================================================================--- src/jtag/jtag.c	(.../vendor/openocd)	(Revision 49)+++ src/jtag/jtag.c	(.../branches/openocd-usb_jtag)	(Revision 49)@@ -136,6 +136,14 @@ 	extern jtag_interface_t ft2232_interface; #endif +#if BUILD_USB_BLASTER_FTD2XX == 1+	extern jtag_interface_t usb_blaster_interface;+#endif++#if BUILD_USB_BLASTER_LIBFTDI == 1+	extern jtag_interface_t usb_blaster_interface;+#endif+ #if BUILD_AMTJTAGACCEL == 1 	extern jtag_interface_t amt_jtagaccel_interface; #endif@@ -162,6 +170,12 @@ #if BUILD_FT2232_LIBFTDI == 1 	&ft2232_interface, #endif+#if BUILD_USB_BLASTER_FTD2XX == 1+	&usb_blaster_interface,+#endif+#if BUILD_USB_BLASTER_LIBFTDI == 1+	&usb_blaster_interface,+#endif #if BUILD_AMTJTAGACCEL == 1 	&amt_jtagaccel_interface, #endifIndex: src/jtag/usb_blaster.c===================================================================--- src/jtag/usb_blaster.c	(.../vendor/openocd)	(Revision 0)+++ src/jtag/usb_blaster.c	(.../branches/openocd-usb_jtag)	(Revision 49)@@ -0,0 +1,706 @@+/***************************************************************************+ *                                                                         *+ *   Copyright (C) 2006 Kolja Waschk                                       *+ *   usbjtag@ixo.de                                                        *+ *                                                                         *+ *   Based on ft2232.c and bitbang.c,                                      *+ *   Copyright (C) 2004,2006 by Dominic Rath                               *+ *                                                                         *+ *   This program is free software; you can redistribute it and/or modify  *+ *   it under the terms of the GNU General Public License as published by  *+ *   the Free Software Foundation; either version 2 of the License, or     *+ *   (at your option) any later version.                                   *+ *                                                                         *+ *   This program is distributed in the hope that it will be useful,       *+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *+ *   GNU General Public License for more details.                          *+ *                                                                         *+ *   You should have received a copy of the GNU General Public License     *+ *   along with this program; if not, write to the                         *+ *   Free Software Foundation, Inc.,                                       *+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *+ ***************************************************************************/+#ifdef HAVE_CONFIG_H+#include "config.h"+#endif++#if IS_CYGWIN == 1+#include "windows.h"+#undef ERROR+#endif++#include "replacements.h"++/* project specific includes */+#include "log.h"+#include "types.h"+#include "jtag.h"+#include "configuration.h"+#include "time_support.h"++/* system includes */+#include <string.h>+#include <stdlib.h>+#include <unistd.h>++/* USB_BLASTER access library includes */+#if BUILD_USB_BLASTER_FTD2XX == 1+#include <ftd2xx.h>+#elif BUILD_USB_BLASTER_LIBFTDI == 1+#include <ftdi.h>+#endif++#include <sys/time.h>+#include <time.h>++/* enable this to debug io latency+ */+#if 1+#define _DEBUG_USB_IO_+#endif++/* enable this to debug communication+ */+#if 1+#define _DEBUG_USB_COMMS_+#endif++int usb_blaster_execute_queue(void);++void usb_blaster_blink(void);+int usb_blaster_speed(int speed);+int usb_blaster_register_commands(struct command_context_s *cmd_ctx);+int usb_blaster_init(void);+int usb_blaster_quit(void);++int usb_blaster_handle_device_desc_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);+int usb_blaster_handle_layout_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);+int usb_blaster_handle_vid_pid_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);++char *usb_blaster_device_desc = NULL;+char *usb_blaster_layout = NULL;+u16 usb_blaster_vid = 0x09fb; // Altera+u16 usb_blaster_pid = 0x6001; // USB-Blaster++#if BUILD_USB_BLASTER_FTD2XX == 1+static FT_HANDLE ftdih = NULL;+#elif BUILD_USB_BLASTER_LIBFTDI == 1+static struct ftdi_context ftdic;+#endif++jtag_interface_t usb_blaster_interface = +{+	+	.name = "usb_blaster",+	+	.execute_queue = usb_blaster_execute_queue,+	+	.support_pathmove = 1,+	+	.speed = usb_blaster_speed,+	.register_commands = usb_blaster_register_commands,+	.init = usb_blaster_init,+	.quit = usb_blaster_quit,+};++int usb_blaster_buf_write(u8 *buf, int size, u32* bytes_written)+{+#if BUILD_USB_BLASTER_FTD2XX == 1+	FT_STATUS status;+	DWORD dw_bytes_written;+	+#ifdef _DEBUG_JTAG_IO_+	DEBUG("usb_blaster_buf_write %02X (%d)\n", buf[0], size);+#endif+	if ((status = FT_Write(ftdih, buf, size, &dw_bytes_written)) != FT_OK)+	{+		*bytes_written = dw_bytes_written;+		ERROR("FT_Write returned: %i", status);+		return ERROR_JTAG_DEVICE_ERROR;+	}+	else+	{+		*bytes_written = dw_bytes_written;+		return ERROR_OK;	+	}+#elif BUILD_USB_BLASTER_LIBFTDI == 1+	int retval;+#ifdef _DEBUG_JTAG_IO_+	DEBUG("usb_blaster_buf_write %02X (%d)\n", buf[0], size);+#endif+	if ((retval = ftdi_write_data(&ftdic, buf, size)) < 0)+	{+		*bytes_written = 0;+		ERROR("ftdi_write_data: %s", ftdi_get_error_string(&ftdic));+		return ERROR_JTAG_DEVICE_ERROR;+	}+	else+	{+		*bytes_written = retval;+		return ERROR_OK;	+	}+#endif+}++int usb_blaster_buf_read(u8* buf, int size, u32* bytes_read)+{+#if BUILD_USB_BLASTER_FTD2XX == 1+	DWORD dw_bytes_read;+	FT_STATUS status;+	if ((status = FT_Read(ftdih, buf, size, &dw_bytes_read)) != FT_OK)+	{+		*bytes_read = dw_bytes_read; +		ERROR("FT_Read returned: %i", status);+		return ERROR_JTAG_DEVICE_ERROR;+	}+#ifdef _DEBUG_JTAG_IO_+	DEBUG("usb_blaster_buf_read %02X (%d)\n", buf[0], dw_bytes_read);+#endif+	*bytes_read = dw_bytes_read; +	return ERROR_OK;	++#elif BUILD_USB_BLASTER_LIBFTDI == 1+	int retval;+	int timeout = 100;+	*bytes_read = 0;+	+	while ((*bytes_read < size) && timeout--)+	{+		if ((retval = ftdi_read_data(&ftdic, buf + *bytes_read, size - *bytes_read)) < 0)+		{+			*bytes_read = 0;+			ERROR("ftdi_read_data: %s", ftdi_get_error_string(&ftdic));+			return ERROR_JTAG_DEVICE_ERROR;+		}+		*bytes_read += retval;+	}+#ifdef _DEBUG_JTAG_IO_+	DEBUG("usb_blaster_buf_read %02X (%d)\n", buf[0], *bytes_read);+#endif+	return ERROR_OK;	+#endif+}++/* The following code doesn't fully utilize the possibilities of the USB-Blaster. It+ * writes one byte per JTAG pin state change at a time; it doesn't even try to buffer+ * data up to the maximum packet size of 64 bytes.+ *+ * Actually, the USB-Blaster offers a byte-shift mode to transmit up to 504 data bits+ * (bidirectional) in a single USB packet. A header byte has to be sent as the first+ * byte in a packet with the following meaning:+ *+ *   Bit 7 (0x80): Must be set to indicate byte-shift mode.+ *   Bit 6 (0x40): If set, the USB-Blaster will also read data, not just write.+ *   Bit 5..0:     Define the number N of following bytes+ *+ * All N following bytes will then be clocked out serially on TDI. If Bit 6 was set,+ * it will afterwards return N bytes with TDO data read while clocking out the TDI data.+ * LSB of the first byte after the header byte will appear first on TDI.+ */++/* Simple bit banging mode:+ *+ *   Bit 7 (0x80): Must be zero (see byte-shift mode above)+ *   Bit 6 (0x40): If set, you will receive a byte indicating the state of TDO in return.+ *   Bit 5 (0x20): Unknown; for now, set to one.+ *   Bit 4 (0x10): TDI Output.+ *   Bit 3 (0x08): Unknown; for now, set to one.+ *   Bit 2 (0x04): Unknown; for now, set to one.+ *   Bit 1 (0x02): TMS Output.+ *   Bit 0 (0x01): TCK Output.+ *+ * For transmitting a single data bit, you need to write two bytes. Up to 64 bytes can be+ * combined in a single USB packet (but this is not done in the code below). It isn't+ * possible to read a data without transmitting data.+ */++#define TCK    0+#define TMS    1+#define TDI    4+#define READ   6+#define SHMODE 7+#define OTHERS ((1<<2)|(1<<3)|(1<<5))++void usb_blaster_write(int tck, int tms, int tdi)+{+	u8 buf[1];+	u32 count;+#ifdef _DEBUG_JTAG_IO_+	DEBUG("---- usb_blaster_write(%d,%d,%d)\n", tck,tms,tdi);+#endif+	buf[0] = OTHERS | (tck?(1<<TCK):0) | (tms?(1<<TMS):0) | (tdi?(1<<TDI):0);+	usb_blaster_buf_write(buf, 1, &count);+}++int usb_blaster_write_read(int tck, int tms, int tdi)+{+	u8 buf[1];+	u32 count;+#ifdef _DEBUG_JTAG_IO_+	DEBUG("++++ usb_blaster_write_read(%d,%d,%d)\n", tck,tms,tdi);+#endif+	buf[0] = OTHERS | (tck?(1<<TCK):0) | (tms?(1<<TMS):0) | (tdi?(1<<TDI):0) | (1<<READ);+	usb_blaster_buf_write(buf, 1, &count);+	usb_blaster_buf_read(buf, 1, &count);+	return (buf[0]&1);+}++int usb_blaster_speed(int speed)+{+#if BUILD_USB_BLASTER_FTD2XX == 1+	DEBUG("TODO: usb_blaster_speed() isn't implemented for libftd2xx!");+#elif BUILD_USB_BLASTER_LIBFTDI == 1+	DEBUG("TODO: usb_blaster_speed() isn't optimally implemented!");+	/* TODO: libftdi's ftdi_set_baudrate chokes on high rates, use lowlevel+	 * usb function instead! And additionally allow user to throttle. */+	if(ftdi_set_baudrate(&ftdic, 3000000/4)<0)+	{+		ERROR("Can't set baud rate to max: %s", ftdi_get_error_string(&ftdic));+		return ERROR_JTAG_DEVICE_ERROR;+	};+#endif+	+	return ERROR_OK;+}++int usb_blaster_register_commands(struct command_context_s *cmd_ctx)+{+	register_command(cmd_ctx, NULL, "usb_blaster_device_desc", usb_blaster_handle_device_desc_command,+		COMMAND_CONFIG, NULL);+	register_command(cmd_ctx, NULL, "usb_blaster_vid_pid", usb_blaster_handle_vid_pid_command,+					 COMMAND_CONFIG, NULL);+	return ERROR_OK;+}++void usb_blaster_end_state(state)+{+	if (tap_move_map[state] != -1)+		end_state = state;+	else+	{+		ERROR("BUG: %i is not a valid end state", state);+		exit(-1);+	}+}++void usb_blaster_state_move(void) {+	+	int i=0, tms=0;+	u8 tms_scan = TAP_MOVE(cur_state, end_state);+	+	for (i = 0; i < 7; i++)+	{+		tms = (tms_scan >> i) & 1;+		usb_blaster_write(0, tms, 0);+		usb_blaster_write(1, tms, 0);+	}+	usb_blaster_write(0, tms, 0);+	+	cur_state = end_state;+}++void usb_blaster_path_move(pathmove_command_t *cmd)+{+	int num_states = cmd->num_states;+	int state_count;++	state_count = 0;+	while (num_states)+	{+		if (tap_transitions[cur_state].low == cmd->path[state_count])+		{+			usb_blaster_write(0, 0, 0);+			usb_blaster_write(1, 0, 0);+		}+		else if (tap_transitions[cur_state].high == cmd->path[state_count])+		{+			usb_blaster_write(0, 1, 0);+			usb_blaster_write(1, 1, 0);+		}			+		else+		{+			ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_strings[cur_state], tap_state_strings[cmd->path[state_count]]);+			exit(-1);+		}+		+		cur_state = cmd->path[state_count];+		state_count++;+		num_states--;+	}+	+	end_state = cur_state;+}++void usb_blaster_runtest(int num_cycles)+{+	int i;+	+	enum tap_state saved_end_state = end_state;+	+	/* only do a state_move when we're not already in RTI */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -