44 #define SIO_MODEM_CTRL 1
45 #define SIO_SET_FLOW_CTRL 2
46 #define SIO_SET_BAUD_RATE 3
47 #define SIO_SET_DATA 4
48 #define SIO_POLL_MODEM_STATUS 5
49 #define SIO_SET_EVENT_CHAR 6
50 #define SIO_SET_ERROR_CHAR 7
51 #define SIO_SET_LATENCY_TIMER 9
52 #define SIO_GET_LATENCY_TIMER 10
53 #define SIO_SET_BITMODE 11
54 #define SIO_READ_PINS 12
55 #define SIO_READ_EEPROM 0x90
56 #define SIO_WRITE_EEPROM 0x91
57 #define SIO_ERASE_EEPROM 0x92
59 #define FT232R_BUF_SIZE_EXTRA 4096
63 static struct libusb_device_handle *
adapter;
71 #define FT232R_BIT_COUNT 8
111 size_t total_written = 0;
112 size_t total_read = 0;
113 int rxfifo_free = 128;
118 if (bytes_to_write > 64)
120 if (bytes_to_write > rxfifo_free)
121 bytes_to_write = rxfifo_free;
123 if (bytes_to_write) {
128 bytes_to_write, 1000, &n) !=
ERROR_OK) {
142 sizeof(reply), 1000, &n) !=
ERROR_OK) {
149 int bytes_read = n - 2;
150 total_read += bytes_read;
151 rxfifo_free += bytes_read;
152 if (total_read > total_written) {
164 uint8_t *new_buf_ptr;
192 LOG_ERROR(
"ft232r_write: buffer overflow");
205 LOG_DEBUG(
"ft232r_reset(%d,%d)", trst, srst);
221 LOG_ERROR(
"ft232r_write: buffer overflow");
231 int baud = (divisor == 0) ? 3000000 :
232 (divisor == 1) ? 2000000 :
234 LOG_DEBUG(
"ft232r_speed(%d) rate %d bits/sec", divisor, baud);
237 LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT,
251 LOG_ERROR(
"ft232r not found: vid=%04x, pid=%04x, serial=%s\n",
257 libusb_detach_kernel_driver(
adapter, 0);
259 libusb_set_auto_detach_kernel_driver(
adapter, 1);
261 if (libusb_claim_interface(
adapter, 0)) {
268 LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT,
276 LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT,
279 LOG_ERROR(
"cannot set sync bitbang mode");
284 unsigned int divisor = 1;
285 unsigned char latency_timer = 1;
289 LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT,
296 LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT,
298 LOG_ERROR(
"unable to set latency timer");
304 LOG_ERROR(
"Unable to allocate memory for the buffer");
316 LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT,
319 LOG_ERROR(
"cannot set bitmode to restore serial port");
323 if (libusb_release_interface(
adapter, 0) != 0)
324 LOG_ERROR(
"usb release interface failed");
340 else if (divisor == 1)
343 *khz = 3000 / divisor;
360 *divisor = (2*3000 / khz + 1) / 2;
361 if (*divisor > 0x3FFF)
377 if (
name[0] >=
'0' &&
name[0] <=
'9' &&
name[1] ==
'\0') {
391 LOG_WARNING(
"ignoring extra IDs in ft232r_vid_pid "
392 "(maximum is 1 pair)");
399 LOG_WARNING(
"incomplete ft232r_vid_pid configuration");
424 "FT232R nums: TCK = %d %s, TMS = %d %s, TDI = %d %s, TDO = %d %s",
537 "FT232R restore serial: 0x%04X (%s)",
546 .handler = ft232r_handle_vid_pid_command,
548 .help =
"USB VID and PID of the adapter",
553 .handler = ft232r_handle_jtag_nums_command,
555 .help =
"gpio numbers for tck, tms, tdi, tdo. (in that order)",
556 .usage =
"<0-7|TXD-RI> <0-7|TXD-RI> <0-7|TXD-RI> <0-7|TXD-RI>",
560 .handler = ft232r_handle_tck_num_command,
562 .help =
"gpio number for tck.",
563 .usage =
"<0-7|TXD|RXD|RTS|CTS|DTR|DSR|DCD|RI>",
567 .handler = ft232r_handle_tms_num_command,
569 .help =
"gpio number for tms.",
570 .usage =
"<0-7|TXD|RXD|RTS|CTS|DTR|DSR|DCD|RI>",
574 .handler = ft232r_handle_tdo_num_command,
576 .help =
"gpio number for tdo.",
577 .usage =
"<0-7|TXD|RXD|RTS|CTS|DTR|DSR|DCD|RI>",
581 .handler = ft232r_handle_tdi_num_command,
583 .help =
"gpio number for tdi.",
584 .usage =
"<0-7|TXD|RXD|RTS|CTS|DTR|DSR|DCD|RI>",
588 .handler = ft232r_handle_srst_num_command,
590 .help =
"gpio number for srst.",
591 .usage =
"<0-7|TXD|RXD|RTS|CTS|DTR|DSR|DCD|RI>",
595 .handler = ft232r_handle_trst_num_command,
597 .help =
"gpio number for trst.",
598 .usage =
"<0-7|TXD|RXD|RTS|CTS|DTR|DSR|DCD|RI>",
601 .name =
"restore_serial",
602 .handler = ft232r_handle_restore_serial_command,
604 .help =
"bitmode control word that restores serial port.",
605 .usage =
"bitmode_control_word",
614 .help =
"perform ft232r management",
641 for (i = skip; i < tms_count; i++) {
642 tms = (tms_scan >> i) & 1;
657 unsigned int num_bits =
cmd->cmd.tms->num_bits;
658 const uint8_t *
bits =
cmd->cmd.tms->bits;
663 for (
unsigned int i = 0; i < num_bits; i++) {
664 tms = ((
bits[i/8] >> (i % 8)) & 1);
675 unsigned int num_states =
cmd->num_states;
686 LOG_ERROR(
"BUG: %s -> %s isn't a valid TAP transition",
717 for (
unsigned int i = 0; i < num_cycles; i++) {
742 for (
unsigned int i = 0; i < num_cycles; i++) {
751 int bit_cnt, bit0_index;
764 for (bit_cnt = 0; bit_cnt < scan_size; bit_cnt++) {
765 int tms = (bit_cnt == scan_size-1) ? 1 : 0;
767 int bytec = bit_cnt/8;
768 int bcval = 1 << (bit_cnt % 8);
792 for (bit_cnt = 0; bit_cnt < scan_size; bit_cnt++) {
793 int bytec = bit_cnt/8;
794 int bcval = 1 << (bit_cnt % 8);
824 if ((
cmd->cmd.reset->trst == 1) ||
825 (
cmd->cmd.reset->srst &&
833 LOG_DEBUG_IO(
"runtest %u cycles, end in %s",
cmd->cmd.runtest->num_cycles,
855 LOG_DEBUG_IO(
"pathmove: %u states, end in %s",
cmd->cmd.pathmove->num_states,
862 LOG_DEBUG_IO(
"%s scan end in %s", (
cmd->cmd.scan->ir_scan) ?
"IR" :
"DR",
884 LOG_ERROR(
"BUG: unknown JTAG command type encountered");
const char * adapter_get_required_serial(void)
Retrieves the serial number set with command 'adapter serial'.
const char *const jtag_only[]
void command_print(struct command_invocation *cmd, const char *format,...)
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#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)
enum scan_type jtag_scan_type(const struct scan_command *cmd)
int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd)
scan_type
The inferred type of a scan_command structure, indicating whether the command has the host scan in fr...
@ SCAN_IN
From device to host,.
@ SCAN_OUT
From host to device,.
static void syncbb_stableclocks(unsigned int num_cycles)
Function syncbb_stableclocks issues a number of clock cycles while staying in a stable state.
#define FT232R_BUF_SIZE_EXTRA
struct adapter_driver ft232r_adapter_driver
static char * ft232r_bit_number_to_name(int bit)
static void syncbb_path_move(struct pathmove_command *cmd)
static void syncbb_runtest(unsigned int num_cycles)
static struct libusb_device_handle * adapter
static int ft232r_bit_name_to_number(const char *name)
static uint16_t ft232r_restore_bitmode
0xFFFF disables restore by default, after exit serial port will not work.
static struct jtag_interface ft232r_interface
static const struct command_registration ft232r_subcommand_handlers[]
static char * ft232r_bit_name_array[FT232R_BIT_COUNT]
static uint16_t ft232r_vid
static uint8_t * ft232r_output
#define FT232R_BIT_COUNT
FT232R GPIO bit number to RS232 name.
static uint16_t ft232r_pid
static int ft232r_init(void)
static void syncbb_end_state(tap_state_t state)
#define SIO_SET_BAUD_RATE
static int ft232r_khz(int khz, int *divisor)
static int ft232r_speed_div(int divisor, int *khz)
COMMAND_HANDLER(ft232r_handle_vid_pid_command)
static int ft232r_speed(int divisor)
#define SIO_SET_LATENCY_TIMER
static const struct command_registration ft232r_command_handlers[]
static int ft232r_quit(void)
static int syncbb_execute_queue(struct jtag_command *cmd_queue)
static size_t ft232r_output_len
static void ft232r_write(int tck, int tms, int tdi)
Add one TCK/TMS/TDI sample to send buffer.
static int syncbb_execute_tms(struct jtag_command *cmd)
Clock a bunch of TMS (or SWDIO) transitions, to change the JTAG (or SWD) state machine.
static void syncbb_state_move(int skip)
static void syncbb_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size)
static void ft232r_increase_buf_size(size_t new_buf_size)
static int ft232r_send_recv(void)
Perform sync bitbang output/input transaction.
static size_t ft232r_buf_size
static void ft232r_reset(int trst, int srst)
Control /TRST and /SYSRST pins.
bool tap_is_state_stable(tap_state_t astate)
Function tap_is_state_stable returns true if the astate is stable.
tap_state_t tap_state_transition(tap_state_t cur_state, bool tms)
Function tap_state_transition takes a current TAP state and returns the next state according to the t...
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,.
int tap_get_tms_path(tap_state_t from, tap_state_t to)
This function provides a "bit sequence" indicating what has to be done with TMS during a sequence of ...
int tap_get_tms_path_len(tap_state_t from, tap_state_t to)
Function int tap_get_tms_path_len returns the total number of bits that represents a TMS path transit...
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 DEBUG_CAP_TMS_SEQ
#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)
enum reset_types jtag_get_reset_config(void)
#define ERROR_JTAG_DEVICE_ERROR
#define ERROR_JTAG_QUEUE_FAILED
#define ERROR_JTAG_INIT_FAILED
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
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)
#define LOG_DEBUG_IO(expr ...)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_DEBUG(expr ...)
static uint32_t bit(uint32_t value, unsigned int b)
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.
unsigned int supported
Bit vector listing capabilities exposed by this driver.