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 #define DEBUG_TYPE_READ 0
123 #define DEBUG_TYPE_WRITE 1
124 #define DEBUG_TYPE_OCD_READ 2
125 #define DEBUG_TYPE_BUFFER 3
140 sprintf(line,
"USB READ %d bytes",
length);
143 sprintf(line,
"USB WRITE %d bytes",
length);
146 sprintf(line,
"TO OpenOCD %d bytes",
length);
149 sprintf(line,
"Buffer %d bytes",
length);
158 sprintf(line,
"USB READ: %04x", i);
161 sprintf(line,
"USB WRITE: %04x", i);
164 sprintf(line,
"TO OpenOCD: %04x", i);
167 sprintf(line,
"BUFFER: %04x", i);
172 sprintf(s,
" %02x",
buffer[j]);
206 uint8_t *buf,
int size, uint32_t *bytes_written)
212 retval = ftdi_write_data(&
ftdic, buf,
size);
219 *bytes_written = retval;
225 uint8_t *buf,
int size, uint32_t *bytes_written)
249 *bytes_written = ret;
255 uint8_t *buf,
int size, uint32_t *bytes_written)
266 uint8_t *buf, uint32_t qty, uint32_t *bytes_read)
274 while ((*bytes_read < qty) &&
timeout--) {
275 retval = ftdi_read_data(&
ftdic, buf + *bytes_read,
280 ftdi_get_error_string(&
ftdic));
283 *bytes_read += retval;
292 uint8_t *buf, uint32_t qty, uint32_t *bytes_read)
368 LOG_WARNING(
"adapter speed not recognized, reverting to 375 kHz");
378 uint8_t latency_timer;
382 LOG_WARNING(
"no openjtag device description specified, "
383 "using default 'Open JTAG Project'");
387 if (ftdi_init(&
ftdic) < 0)
396 if (ftdi_usb_reset(&
ftdic) < 0) {
397 LOG_ERROR(
"unable to reset ftdi device");
401 if (ftdi_set_latency_timer(&
ftdic, 2) < 0) {
402 LOG_ERROR(
"unable to set latency timer");
406 if (ftdi_get_latency_timer(&
ftdic, &latency_timer) < 0) {
407 LOG_ERROR(
"unable to get latency timer");
410 LOG_DEBUG(
"current latency timer: %u", latency_timer);
412 ftdi_disable_bitbang(&
ftdic);
414 if (ftdi_set_baudrate(&
ftdic, 3000000) < 0) {
415 LOG_ERROR(
"Can't set baud rate to max: %s",
416 ftdi_get_error_string(&
ftdic));
435 LOG_ERROR(
"unable to open cy7c65215 device");
443 LOG_ERROR(
"unable to claim JTAG interface");
452 LOG_ERROR(
"could not enable JTAG module");
490 ftdi_usb_close(&
ftdic);
525 uint32_t rx_expected = 0;
532 }
else if ((
usb_tx_buf[tx_offs] & 0x0F) == 2) {
661 cmd->cmd.reset->trst,
cmd->cmd.reset->srst);
666 if (
cmd->cmd.reset->srst) {
710 int scan_size, old_state;
751 cmd->cmd.runtest->num_cycles) {
753 unsigned int num_cycles =
cmd->cmd.runtest->num_cycles;
756 const unsigned int num_cycles_cmd =
MIN(num_cycles, 16);
759 command |= ((num_cycles_cmd - 1) & 0x0F) << 4;
762 num_cycles -= num_cycles_cmd;
763 }
while (num_cycles > 0);
795 LOG_ERROR(
"BUG: unknown Open JTAG command type encountered");
824 else if (khz >= 24000)
826 else if (khz >= 12000)
828 else if (khz >= 6000)
830 else if (khz >= 3000)
832 else if (khz >= 1500)
847 LOG_ERROR(
"require exactly one argument to "
848 "openjtag_device_desc <description>");
865 LOG_ERROR(
"require exactly one argument to "
866 "openjtag_variant <variant>");
884 .
name =
"device_desc",
885 .handler = openjtag_handle_device_desc_command,
887 .help =
"set the USB device description of the OpenJTAG",
888 .usage =
"description-string",
892 .handler = openjtag_handle_variant_command,
894 .help =
"set the OpenJTAG variant",
895 .usage =
"variant-string",
899 .handler = openjtag_handle_vid_pid_command,
901 .help =
"USB VID and PID of the adapter",
911 .help =
"perform openjtag management",
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define ERROR_COMMAND_SYNTAX_ERROR
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer)
int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd)
uint64_t buffer
Pointer to data buffer to send over SPI.
uint32_t size
Size of dw_spi_transaction::buffer.
enum tap_state tap_get_end_state(void)
For more information,.
const char * tap_state_name(enum tap_state state)
Function tap_state_name Returns a string suitable for display representing the JTAG tap_state.
void tap_set_end_state(enum tap_state new_end_state)
This function sets the state of an "end state follower" which tracks the state that any cable driver ...
enum tap_state 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
tap_state
Defines JTAG Test Access Port states.
#define ERROR_JTAG_INIT_FAILED
static int ftdi_tcioflush(struct ftdi_context *ftdi)
int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[], const char *product, struct libusb_device_handle **out, adapter_get_alternate_serial_fn adapter_get_alternate_serial)
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, int *transferred)
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_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_DEBUG_USB(expr,...)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_LEVEL_IS(FOO)
#define LOG_DEBUG(expr ...)
static void openjtag_debug_buffer(uint8_t *buffer, int length, uint8_t type)
static int openjtag_quit_standard(void)
static int openjtag_khz(int khz, int *jtag_speed)
@ OPENJTAG_VARIANT_STANDARD
@ OPENJTAG_VARIANT_CY7C65215
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 unsigned int ep_out
#define CY7C65215_JTAG_CLASS
static int openjtag_buf_write(uint8_t *buf, int size, uint32_t *bytes_written)
static unsigned int ep_in
static int openjtag_execute_queue(struct jtag_command *cmd_queue)
@ OPENJTAG_TAP_CAPTURE_DR
static int openjtag_quit_cy7c65215(void)
static int openjtag_sendcommand(uint8_t cmd)
static struct ftdi_context ftdic
#define DEBUG_TYPE_OCD_READ
static int openjtag_init_cy7c65215(void)
static int openjtag_init_standard(void)
static enum @31 openjtag_variant
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)
#define DEBUG_TYPE_BUFFER
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)
uint8_t bits[QN908X_FLASH_MAX_BLOCKS *QN908X_FLASH_PAGES_PER_BLOCK/8]
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)(struct jtag_command *cmd_queue)
Execute commands in the supplied queue.
struct scan_command * command
The scan_command provide a means of encapsulating a set of scan_field structures that should be scann...
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.