82 static struct ftdi_context
ftdic;
84 #define OPENJTAG_BUFFER_SIZE 504
85 #define OPENJTAG_MAX_PENDING_RESULTS 256
103 static struct libusb_device_handle *
usbh;
106 #define CY7C65215_JTAG_REQUEST 0x40
107 #define CY7C65215_JTAG_ENABLE 0xD0
108 #define CY7C65215_JTAG_DISABLE 0xD1
109 #define CY7C65215_JTAG_READ 0xD2
110 #define CY7C65215_JTAG_WRITE 0xD3
112 #define CY7C65215_USB_TIMEOUT 100
117 #define CY7C65215_JTAG_CLASS 0xff
118 #define CY7C65215_JTAG_SUBCLASS 0x04
122 #ifdef _DEBUG_USB_COMMS_
124 #define DEBUG_TYPE_READ 0
125 #define DEBUG_TYPE_WRITE 1
126 #define DEBUG_TYPE_OCD_READ 2
127 #define DEBUG_TYPE_BUFFER 3
130 static void openjtag_debug_buffer(uint8_t *
buffer,
int length, uint8_t
type)
138 case DEBUG_TYPE_READ:
139 sprintf(line,
"USB READ %d bytes",
length);
141 case DEBUG_TYPE_WRITE:
142 sprintf(line,
"USB WRITE %d bytes",
length);
144 case DEBUG_TYPE_OCD_READ:
145 sprintf(line,
"TO OpenOCD %d bytes",
length);
147 case DEBUG_TYPE_BUFFER:
148 sprintf(line,
"Buffer %d bytes",
length);
154 for (i = 0; i <
length; i += LINE_LEN) {
156 case DEBUG_TYPE_READ:
157 sprintf(line,
"USB READ: %04x", i);
159 case DEBUG_TYPE_WRITE:
160 sprintf(line,
"USB WRITE: %04x", i);
162 case DEBUG_TYPE_OCD_READ:
163 sprintf(line,
"TO OpenOCD: %04x", i);
165 case DEBUG_TYPE_BUFFER:
166 sprintf(line,
"BUFFER: %04x", i);
170 for (j = i; j < i + LINE_LEN && j <
length; j++) {
171 sprintf(s,
" %02x",
buffer[j]);
207 uint8_t *buf,
int size, uint32_t *bytes_written)
210 #ifdef _DEBUG_USB_COMMS_
211 openjtag_debug_buffer(buf,
size, DEBUG_TYPE_WRITE);
214 retval = ftdi_write_data(&
ftdic, buf,
size);
221 *bytes_written = retval;
227 uint8_t *buf,
int size, uint32_t *bytes_written)
231 #ifdef _DEBUG_USB_COMMS_
232 openjtag_debug_buffer(buf,
size, DEBUG_TYPE_WRITE);
244 LOG_ERROR(
"vendor command failed, error %d", ret);
253 *bytes_written = ret;
259 uint8_t *buf,
int size, uint32_t *bytes_written)
270 uint8_t *buf, uint32_t qty, uint32_t *bytes_read)
278 while ((*bytes_read < qty) &&
timeout--) {
279 retval = ftdi_read_data(&
ftdic, buf + *bytes_read,
284 ftdi_get_error_string(&
ftdic));
287 *bytes_read += retval;
290 #ifdef _DEBUG_USB_COMMS_
291 openjtag_debug_buffer(buf, *bytes_read, DEBUG_TYPE_READ);
298 uint8_t *buf, uint32_t qty, uint32_t *bytes_read)
311 LOG_ERROR(
"vendor command failed, error %d", ret);
323 #ifdef _DEBUG_USB_COMMS_
324 openjtag_debug_buffer(buf, *bytes_read, DEBUG_TYPE_READ);
376 LOG_WARNING(
"adapter speed not recognized, reverting to 375 kHz");
386 uint8_t latency_timer;
390 LOG_WARNING(
"no openjtag device description specified, "
391 "using default 'Open JTAG Project'");
395 if (ftdi_init(&
ftdic) < 0)
404 if (ftdi_usb_reset(&
ftdic) < 0) {
405 LOG_ERROR(
"unable to reset ftdi device");
409 if (ftdi_set_latency_timer(&
ftdic, 2) < 0) {
410 LOG_ERROR(
"unable to set latency timer");
414 if (ftdi_get_latency_timer(&
ftdic, &latency_timer) < 0) {
415 LOG_ERROR(
"unable to get latency timer");
418 LOG_DEBUG(
"current latency timer: %u", latency_timer);
420 ftdi_disable_bitbang(&
ftdic);
422 if (ftdi_set_baudrate(&
ftdic, 3000000) < 0) {
423 LOG_ERROR(
"Can't set baud rate to max: %s",
424 ftdi_get_error_string(&
ftdic));
443 LOG_ERROR(
"unable to open cy7c65215 device");
451 LOG_ERROR(
"unable to claim JTAG interface");
460 LOG_ERROR(
"could not enable JTAG module");
498 ftdi_usb_close(&
ftdic);
577 #ifdef _DEBUG_USB_COMMS_
578 openjtag_debug_buffer(
buffer,
659 cmd->cmd.reset->trst,
cmd->cmd.reset->srst);
663 if (
cmd->cmd.reset->trst) {
704 int scan_size, old_state;
713 #ifdef _DEBUG_USB_COMMS_
714 openjtag_debug_buffer(
buffer, (scan_size + 7) / 8, DEBUG_TYPE_BUFFER);
745 if (
cmd->cmd.runtest->num_cycles > 16)
749 cmd->cmd.runtest->num_cycles) {
752 command |= ((
cmd->cmd.runtest->num_cycles - 1) & 0x0F) << 4;
786 LOG_ERROR(
"BUG: unknown Open JTAG command type encountered");
815 else if (khz >= 24000)
817 else if (khz >= 12000)
819 else if (khz >= 6000)
821 else if (khz >= 3000)
823 else if (khz >= 1500)
838 LOG_ERROR(
"require exactly one argument to "
839 "openjtag_device_desc <description>");
856 LOG_ERROR(
"require exactly one argument to "
857 "openjtag_variant <variant>");
864 .
name =
"device_desc",
865 .handler = openjtag_handle_device_desc_command,
867 .help =
"set the USB device description of the OpenJTAG",
868 .usage =
"description-string",
872 .handler = openjtag_handle_variant_command,
874 .help =
"set the OpenJTAG variant",
875 .usage =
"variant-string",
884 .help =
"perform openjtag management",
const char *const jtag_only[]
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
struct jtag_command * jtag_command_queue
The current queue of jtag_command_s structures.
int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer)
int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd)
const char * tap_state_name(tap_state_t state)
Function tap_state_name Returns a string suitable for display representing the JTAG tap_state.
void tap_set_end_state(tap_state_t new_end_state)
This function sets the state of an "end state follower" which tracks the state that any cable driver ...
tap_state_t tap_get_end_state(void)
For more information,.
tap_state_t tap_get_state(void)
This function gets the state of the "state follower" which tracks the state of the TAPs connected to ...
#define tap_set_state(new_state)
This function sets the state of a "state follower" which tracks the state of the TAPs connected to th...
void jtag_sleep(uint32_t us)
#define ERROR_JTAG_DEVICE_ERROR
#define ERROR_JTAG_INIT_FAILED
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
static int ftdi_tcioflush(struct ftdi_context *ftdi)
int jtag_libusb_bulk_write(struct libusb_device_handle *dev, int ep, char *bytes, int size, int timeout, int *transferred)
int jtag_libusb_control_transfer(struct libusb_device_handle *dev, uint8_t request_type, uint8_t request, uint16_t value, uint16_t index, char *bytes, uint16_t size, unsigned int timeout)
void jtag_libusb_close(struct libusb_device_handle *dev)
int jtag_libusb_bulk_read(struct libusb_device_handle *dev, int ep, char *bytes, int size, int timeout, int *transferred)
int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[], struct libusb_device_handle **out, adapter_get_alternate_serial_fn adapter_get_alternate_serial)
int jtag_libusb_choose_interface(struct libusb_device_handle *devh, unsigned int *usb_read_ep, unsigned int *usb_write_ep, int bclass, int subclass, int protocol, int trans_type)
Find the first interface optionally matching class, subclass and protocol and claim it.
#define LOG_DEBUG_IO(expr ...)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_DEBUG(expr ...)
static int openjtag_quit_standard(void)
static int openjtag_khz(int khz, int *jtag_speed)
static uint8_t usb_tx_buf[OPENJTAG_BUFFER_SIZE]
static const uint16_t cy7c65215_vids[]
static int8_t openjtag_get_tap_state(int8_t state)
static int openjtag_quit(void)
#define CY7C65215_JTAG_ENABLE
static struct openjtag_scan_result openjtag_scan_result_buffer[OPENJTAG_MAX_PENDING_RESULTS]
static void openjtag_add_byte(char buf)
static int openjtag_buf_read_cy7c65215(uint8_t *buf, uint32_t qty, uint32_t *bytes_read)
#define CY7C65215_JTAG_WRITE
static struct jtag_interface openjtag_interface
static int openjtag_buf_read_standard(uint8_t *buf, uint32_t qty, uint32_t *bytes_read)
#define CY7C65215_JTAG_DISABLE
static char * openjtag_device_desc
static int openjtag_buf_read(uint8_t *buf, uint32_t qty, uint32_t *bytes_read)
static uint16_t openjtag_vid
static int openjtag_buf_write_standard(uint8_t *buf, int size, uint32_t *bytes_written)
static void openjtag_write_tap_buffer(void)
#define CY7C65215_USB_TIMEOUT
static void openjtag_execute_command(struct jtag_command *cmd)
static const struct command_registration openjtag_command_handlers[]
static const uint16_t cy7c65215_pids[]
#define OPENJTAG_BUFFER_SIZE
#define CY7C65215_JTAG_SUBCLASS
static void openjtag_execute_runtest(struct jtag_command *cmd)
static int openjtag_execute_tap_queue(void)
static uint32_t usb_rx_buf_len
static void openjtag_execute_scan(struct jtag_command *cmd)
static int openjtag_speed_div(int speed, int *khz)
static uint16_t openjtag_pid
static int openjtag_scan_result_count
static int usb_tx_buf_offs
#define CY7C65215_JTAG_READ
static const char *const openjtag_variant_names[]
static int openjtag_buf_write_cy7c65215(uint8_t *buf, int size, uint32_t *bytes_written)
static int openjtag_speed(int speed)
static const struct command_registration openjtag_subcommand_handlers[]
static void openjtag_execute_sleep(struct jtag_command *cmd)
static uint8_t usb_rx_buf[OPENJTAG_BUFFER_SIZE]
static void openjtag_execute_statemove(struct jtag_command *cmd)
struct adapter_driver openjtag_adapter_driver
static struct libusb_device_handle * usbh
static int openjtag_execute_queue(void)
static unsigned int ep_out
#define CY7C65215_JTAG_CLASS
static enum @25 openjtag_variant
static int openjtag_buf_write(uint8_t *buf, int size, uint32_t *bytes_written)
static unsigned int ep_in
@ OPENJTAG_TAP_CAPTURE_DR
static int openjtag_quit_cy7c65215(void)
static int openjtag_sendcommand(uint8_t cmd)
static struct ftdi_context ftdic
static int openjtag_init_cy7c65215(void)
static int openjtag_init_standard(void)
enum openjtag_tap_state openjtag_tap_state_t
COMMAND_HANDLER(openjtag_handle_device_desc_command)
#define CY7C65215_JTAG_REQUEST
static void openjtag_add_scan(uint8_t *buffer, int length, struct scan_command *scan_cmd)
@ OPENJTAG_VARIANT_STANDARD
@ OPENJTAG_VARIANT_CY7C65215
static void openjtag_set_state(uint8_t openocd_state)
#define OPENJTAG_MAX_PENDING_RESULTS
static int openjtag_init(void)
static void openjtag_execute_reset(struct jtag_command *cmd)
size_t size
Size of the control block search area.
Represents a driver for a debugging interface.
const char *const name
The name of the interface driver.
const char * usage
a string listing the options and arguments, required or optional
Represents a driver for a debugging interface.
int(* execute_queue)(void)
Execute queued commands.
struct scan_command * command
The scan_command provide a means of encapsulating a set of scan_field_s structures that should be sca...
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.