28 #define OPENDOUS_MAX_VIDS_PIDS 4
41 {
"usbprog-jtag", {0x1781, 0}, {0x0C63, 0}, 0x82, 0x02, 0x00, 510 },
42 {
"opendous", {0x1781, 0x03EB, 0}, {0xC0C0, 0x204F, 0}, 0x81, 0x02, 0x00, 360 },
43 {
"usbvlab", {0x16C0, 0}, {0x05DC, 0}, 0x81, 0x02, 0x01, 360 },
44 {
NULL, {0x0000}, {0x0000}, 0x00, 0x00, 0x00, 0 }
47 #define OPENDOUS_WRITE_ENDPOINT (opendous_probe->WRITE_EP)
48 #define OPENDOUS_READ_ENDPOINT (opendous_probe->READ_EP)
52 #define OPENDOUS_USB_TIMEOUT 1000
54 #define OPENDOUS_USB_BUFFER_SIZE (opendous_probe->BUFFERSIZE)
55 #define OPENDOUS_IN_BUFFER_SIZE (OPENDOUS_USB_BUFFER_SIZE)
56 #define OPENDOUS_OUT_BUFFER_SIZE (OPENDOUS_USB_BUFFER_SIZE)
64 #define OPENDOUS_MAX_SPEED 66
65 #define OPENDOUS_MAX_TAP_TRANSMIT ((opendous_probe->BUFFERSIZE)-10)
66 #define OPENDOUS_MAX_INPUT_DATA (OPENDOUS_MAX_TAP_TRANSMIT*4)
69 #define OPENDOUS_TAP_BUFFER_SIZE 65536
81 #define MAX_PENDING_SCAN_RESULTS (OPENDOUS_MAX_INPUT_DATA)
84 #define JTAG_CMD_TAP_OUTPUT 0x0
85 #define JTAG_CMD_SET_TRST 0x1
86 #define JTAG_CMD_SET_SRST 0x2
87 #define JTAG_CMD_READ_INPUT 0x3
88 #define JTAG_CMD_TAP_OUTPUT_EMU 0x4
89 #define JTAG_CMD_SET_DELAY 0x5
90 #define JTAG_CMD_SET_SRST_TRST 0x6
91 #define JTAG_CMD_READ_CONFIG 0x7
94 #define FUNC_START_BOOTLOADER 30
95 #define FUNC_WRITE_DATA 0x50
96 #define FUNC_READ_DATA 0x51
138 #ifdef _DEBUG_USB_COMMS_
139 static void opendous_debug_buffer(uint8_t *
buffer,
int length);
181 int request_version = atoi(
CMD_ARGV[0]);
182 switch (request_version) {
203 .
name =
"opendous_info",
204 .handler = &opendous_handle_opendous_info_command,
206 .help =
"show opendous info",
210 .name =
"opendous_hw_jtag",
211 .handler = &opendous_handle_opendous_hw_jtag_command,
213 .help =
"access opendous HW JTAG command version",
217 .name =
"opendous_type",
218 .handler = &opendous_handle_opendous_type_command,
220 .help =
"set opendous type",
221 .usage =
"[usbvlab|usbprog-jtag|opendous]",
251 LOG_DEBUG_IO(
"runtest %i cycles, end in %i",
cmd->cmd.runtest->num_cycles,
252 cmd->cmd.runtest->end_state);
254 if (
cmd->cmd.runtest->end_state != -1)
262 if (
cmd->cmd.statemove->end_state != -1)
269 cmd->cmd.pathmove->num_states,
270 cmd->cmd.pathmove->path[
cmd->cmd.pathmove->num_states - 1]);
278 if (
cmd->cmd.scan->end_state != -1)
284 #ifdef _DEBUG_USB_COMMS_
285 opendous_debug_buffer(
buffer, (scan_size + 7) / 8);
296 if (
cmd->cmd.reset->trst == 1)
308 LOG_ERROR(
"BUG: unknown JTAG command type encountered");
325 LOG_WARNING(
"No opendous_type specified, using default 'opendous'");
328 while (cur_opendous_probe->
name) {
333 cur_opendous_probe++;
351 LOG_ERROR(
"Cannot find opendous Interface! Please check connection and permissions.");
356 while (check_cnt < 3) {
366 LOG_INFO(
"opendous JTAG Interface ready");
414 for (i = 0; i < tms_scan_bits; i++) {
415 tms = (tms_scan >> i) & 1;
426 for (i = 0; i < num_states; i++) {
432 LOG_ERROR(
"BUG: %s -> %s isn't a valid TAP transition",
456 for (i = 0; i < num_cycles; i++)
495 LOG_DEBUG(
"trst: %i, srst: %i", trst, srst);
561 if ((scans > available_scans) || (
bits > available_bits))
568 unsigned char _tms = tms ? 1 : 0;
569 unsigned char _tdi = tdi ? 1 : 0;
583 LOG_ERROR(
"opendous_tap_append_step, overflow");
598 for (i = 0; i <
length; i++)
611 #ifdef _DEBUG_USB_COMMS_
621 #ifdef _DEBUG_USB_COMMS_
623 LOG_DEBUG(
"opendous is sending %d bytes", byte_length);
626 for (j = 0, i = 0; j < byte_length;) {
629 int transmit = byte_length - j;
636 receive = (transmit + 1) / 2;
643 if (result != receive) {
644 LOG_ERROR(
"opendous_tap_execute, wrong result %d, expected %d", result, receive);
653 #ifdef _DEBUG_USB_COMMS_
654 LOG_DEBUG(
"opendous tap result %d", byte_length_out);
655 opendous_debug_buffer(
tdo_buffer, byte_length_out);
672 #ifdef _DEBUG_USB_COMMS_
673 opendous_debug_buffer(
buffer, byte_length_out);
697 struct libusb_device_handle *
devh;
702 libusb_claim_interface(
devh, 0);
704 result = malloc(
sizeof(*result));
721 if (result == out_length) {
723 if (result == in_length)
726 LOG_ERROR(
"usb_bulk_read failed (requested=%d, result=%d)", in_length, result);
730 LOG_ERROR(
"usb_bulk_write failed (requested=%d, result=%d)", out_length, result);
745 #ifdef _DEBUG_USB_COMMS_
750 LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT,
756 #ifdef _DEBUG_USB_COMMS_
757 LOG_DEBUG(
"USB write end: %d bytes", result);
760 LOG_DEBUG_IO(
"opendous_usb_write, out_length = %d, result = %d", out_length, result);
762 #ifdef _DEBUG_USB_COMMS_
771 #ifdef _DEBUG_USB_COMMS_
777 LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_IN,
783 #ifdef _DEBUG_USB_COMMS_
784 LOG_DEBUG(
"USB read end: %d bytes", result);
788 #ifdef _DEBUG_USB_COMMS_
794 #ifdef _DEBUG_USB_COMMS_
795 #define BYTES_PER_LINE 16
802 int n = snprintf(line, 9,
"%04x", i);
804 n += snprintf(line + n, 4,
" %02x",
buffer[j]);
const char *const jtag_only[]
void * buf_set_buf(const void *_src, unsigned src_start, void *_dst, unsigned dst_start, unsigned len)
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_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)
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_s structure, indicating whether the command has the host scan in ...
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 tap_set_state(new_state)
This function sets the state of a "state follower" which tracks the state of the TAPs connected to th...
static struct jaylink_device_handle * devh
void jtag_sleep(uint32_t us)
#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_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 jtag_libusb_set_configuration(struct libusb_device_handle *devh, int configuration)
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)
#define LOG_DEBUG_IO(expr ...)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
#define JTAG_CMD_TAP_OUTPUT
static void opendous_tap_append_step(int tms, int tdi)
static int opendous_quit(void)
#define MAX_PENDING_SCAN_RESULTS
static void opendous_tap_init(void)
static void opendous_reset(int trst, int srst)
#define OPENDOUS_TAP_BUFFER_SIZE
static int opendous_usb_message(struct opendous_jtag *opendous_jtag, int out_length, int in_length)
#define OPENDOUS_USB_TIMEOUT
static int opendous_get_version_info(void)
static int opendous_init(void)
static const struct opendous_probe * opendous_probe
static void opendous_runtest(int num_cycles)
static char * opendous_type
#define OPENDOUS_OUT_BUFFER_SIZE
static uint8_t tdo_buffer[OPENDOUS_TAP_BUFFER_SIZE]
static struct opendous_jtag * opendous_usb_open(void)
#define OPENDOUS_MAX_TAP_TRANSMIT
struct adapter_driver opendous_adapter_driver
static struct jtag_interface opendous_interface
static void opendous_end_state(tap_state_t state)
#define OPENDOUS_MAX_VIDS_PIDS
static int opendous_tap_execute(void)
static void opendous_tap_append_scan(int length, uint8_t *buffer, struct scan_command *command)
COMMAND_HANDLER(opendous_handle_opendous_type_command)
static uint8_t * usb_out_buffer
#define JTAG_CMD_SET_SRST
#define JTAG_CMD_SET_TRST
#define OPENDOUS_IN_BUFFER_SIZE
static void opendous_usb_close(struct opendous_jtag *opendous_jtag)
#define OPENDOUS_WRITE_ENDPOINT
static const struct command_registration opendous_command_handlers[]
static void opendous_tap_ensure_space(int scans, int bits)
static int opendous_usb_write(struct opendous_jtag *opendous_jtag, int out_length)
static uint8_t tms_buffer[OPENDOUS_TAP_BUFFER_SIZE]
#define OPENDOUS_READ_ENDPOINT
static struct opendous_jtag * opendous_jtag_handle
static const struct opendous_probe opendous_probes[]
static struct pending_scan_result * pending_scan_results_buffer
static uint8_t * usb_in_buffer
static void opendous_simple_command(uint8_t command, uint8_t _data)
static void opendous_scan(int ir_scan, enum scan_type type, uint8_t *buffer, int scan_size, struct scan_command *command)
static void opendous_path_move(int num_states, tap_state_t *path)
static int opendous_execute_queue(void)
static unsigned int opendous_hw_jtag_version
static int pending_scan_results_length
static int opendous_usb_read(struct opendous_jtag *opendous_jtag)
static int opendous_get_status(void)
static void opendous_state_move(void)
#define JTAG_CMD_SET_SRST_TRST
Represents a driver for a debugging interface.
const char *const name
The name of the interface driver.
Represents a driver for a debugging interface.
int(* execute_queue)(void)
Execute queued commands.
struct libusb_device_handle * usb_handle
uint16_t PID[OPENDOUS_MAX_VIDS_PIDS]
uint16_t VID[OPENDOUS_MAX_VIDS_PIDS]
int first
First bit position in tdo_buffer to read.
int length
Number of bits to read.
uint8_t * buffer
Location to store the result.
struct scan_command * command
The scan_command provide a means of encapsulating a set of scan_field_s structures that should be sca...