80 #define MAX_PACKET_SIZE 64
90 #define CMD_COPY_TDO_BUFFER 0x5F
122 .ublast_pid = 0x6001,
123 .lowlevel_name =
NULL,
124 .srst_asserted =
false,
125 .trst_asserted =
false,
139 #if BUILD_USB_BLASTER
142 #if BUILD_USB_BLASTER_2
154 char *str = calloc(
size * 2 + 1, 1);
156 for (i = 0; i <
size; i++)
157 sprintf(str + 2*i,
"%02x", buf[i]);
164 char *str =
hexdump(buf, *bytes_read);
175 char *str =
hexdump(buf, *bytes_written);
239 #define READ (1 << 6)
240 #define SHMODE (1 << 7)
241 #define READ_TDO (1 << 0)
418 LOG_ERROR(
"buggy code, should never queue more that %d bytes",
422 LOG_DEBUG_IO(
"(nb_bytes=%d, bytes=[0x%02x, ...])", nb_bytes,
423 bytes ? bytes[0] : 0);
450 for (i = skip; i < nb_bits; i++)
480 cmd->num_states,
cmd->path[
cmd->num_states - 1]);
481 for (i = 0; i <
cmd->num_states; i++) {
533 LOG_DEBUG_IO(
"%s(buf=%p, num_bits=%d)", __func__, buf, nb_bytes * 8);
535 while (ret ==
ERROR_OK && nb_bytes > 0) {
565 LOG_DEBUG_IO(
"%s(buf=%p, num_bits=%d)", __func__, buf, nb_bits);
574 for (i = 0; ret ==
ERROR_OK && i < nb1; i++)
603 int nb8 = nb_bits / 8;
604 int nb1 = nb_bits % 8;
605 int nbfree_in_packet, i, trans = 0, read_tdos;
606 uint8_t *tdos = calloc(1, nb_bits / 8 + 1);
618 if (nb8 > 0 && nb1 == 0) {
624 for (i = 0; i < nb8; i += trans) {
629 trans =
MIN(nbfree_in_packet - 1, nb8 - i);
655 for (i = 0; i < nb1; i++) {
656 int tdi =
bits ?
bits[nb8 + i / 8] & (1 << i) : 0;
657 if (
bits && i == nb1 - 1)
662 if (nb1 && read_tdos) {
707 static const char *
const type2str[] = {
"",
"SCAN_IN",
"SCAN_OUT",
"SCAN_IO" };
708 char *log_buf =
NULL;
719 LOG_DEBUG_IO(
"%s(scan=%s, type=%s, bits=%d, buf=[%s], end_state=%d)", __func__,
720 cmd->ir_scan ?
"IRSCAN" :
"DRSCAN",
722 scan_bits, log_buf,
cmd->end_state);
746 static uint8_t tms_reset = 0xff;
753 info.
buf[i] = out_value | ((i % 2) ?
TCK : 0);
771 static int first_call = 1;
787 cmd->cmd.runtest->end_state);
808 LOG_ERROR(
"BUG: unknown JTAG command type 0x%X",
837 LOG_ERROR(
"Error registering lowlevel driver \"%s\"",
854 LOG_ERROR(
"No lowlevel driver available");
901 LOG_WARNING(
"ignoring extra IDs in ublast_vid_pid "
902 "(maximum is 2 pairs)");
910 LOG_WARNING(
"incomplete ublast_vid_pid configuration");
917 LOG_WARNING(
"incomplete ublast_vid_pid configuration");
926 const char *
const pin_name =
CMD_ARGV[0];
928 static const char *
const pin_val_str[] = {
931 [
SRST] =
"SRST driven",
932 [
TRST] =
"TRST driven",
940 if (!strcmp(pin_name,
"pin6"))
942 if (!strcmp(pin_name,
"pin8"))
945 LOG_ERROR(
"%s: pin name must be \"pin6\" or \"pin8\"",
952 pin_val_str[*steer]);
956 const char *
const pin_value =
CMD_ARGV[1];
957 char val = pin_value[0];
959 if (strlen(pin_value) > 1)
961 switch (tolower((
unsigned char)val)) {
975 LOG_ERROR(
"%s: pin value must be 0, 1, s (SRST) or t (TRST)",
1013 .handler = ublast_handle_vid_pid_command,
1015 .help =
"the vendor ID and product ID of the USB-Blaster and "
1016 "vendor ID and product ID of the uninitialized device "
1017 "for USB-Blaster II",
1018 .usage =
"vid pid vid_uninit pid_uninit",
1021 .name =
"lowlevel_driver",
1022 .handler = ublast_handle_lowlevel_drv_command,
1024 .help =
"set the lowlevel access for the USB Blaster (ftdi, ublast2)",
1025 .usage =
"(ftdi|ublast2)",
1029 .handler = ublast_handle_pin_command,
1031 .help =
"show or set pin state for the unused GPIO pins",
1032 .usage =
"(pin6|pin8) (0|1|s|t)",
1036 .handler = &ublast_firmware_command,
1038 .help =
"configure the USB-Blaster II firmware location",
1039 .usage =
"path/to/blaster_xxxx.hex",
1046 .
name =
"usb_blaster",
1048 .help =
"perform usb_blaster management",
1061 .
name =
"usb_blaster",
const char *const jtag_only[]
#define CMD_NAME
Use this macro to access the name of the command being handled, rather than accessing the variable di...
#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.
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 ...
@ SCAN_IN
From device to host,.
@ SCAN_OUT
From host to device,.
@ SCAN_IO
Full-duplex scan.
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.
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)
#define ERROR_JTAG_DEVICE_ERROR
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
static struct scan_blk scan
#define LOG_DEBUG_IO(expr ...)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
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
struct ublast_lowlevel *(* drv_register)(void)
Represents a driver for a debugging interface.
unsigned supported
Bit vector listing capabilities exposed by this driver.
The scan_command provide a means of encapsulating a set of scan_field_s structures that should be sca...
Encapsulates a series of bits to be clocked out, affecting state and mode of the interface.
uint16_t ublast_pid_uninit
uint16_t ublast_vid_uninit
struct ublast_lowlevel * drv
uint16_t ublast_pid_uninit
int(* open)(struct ublast_lowlevel *low)
int(* write)(struct ublast_lowlevel *low, uint8_t *buf, int size, uint32_t *bytes_written)
uint16_t ublast_vid_uninit
int(* read)(struct ublast_lowlevel *low, uint8_t *buf, unsigned size, uint32_t *bytes_read)
int(* close)(struct ublast_lowlevel *low)
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
struct ublast_lowlevel * ublast2_register_libusb(void)
struct ublast_lowlevel * ublast_register_ftdi(void)
ublast_register_ftdi - get a lowlevel USB Blaster driver ublast2_register_libusb - get a lowlevel USB...
static int ublast_scan(struct scan_command *cmd)
ublast_scan - launches a DR-scan or IR-scan
static char * hexdump(uint8_t *buf, unsigned int size)
static void ublast_queue_tdi(uint8_t *bits, int nb_bits, enum scan_type scan)
ublast_queue_tdi - short description
struct adapter_driver usb_blaster_adapter_driver
static const struct command_registration ublast_subcommand_handlers[]
static const struct command_registration ublast_command_handlers[]
static int ublast_init(void)
ublast_init - Initialize the Altera device
static int ublast_read_byteshifted_tdos(uint8_t *buf, int nb_bytes)
ublast_read_byteshifted_tdos - read TDO of byteshift writes
static uint8_t ublast_build_out(enum scan_type type)
ublast_build_out - build bitbang mode output byte
#define CMD_COPY_TDO_BUFFER
static void ublast_tms(struct tms_command *cmd)
ublast_tms - write a tms command
static void ublast_initial_wipeout(void)
static void ublast_clock_tms(int tms)
ublast_clock_tms - clock a TMS transition
static int ublast_buf_write(uint8_t *buf, int size, uint32_t *bytes_written)
static int ublast_quit(void)
ublast_quit - Release the Altera device
static void ublast_tms_seq(const uint8_t *bits, int nb_bits, int skip)
ublast_tms_seq - write a TMS sequence transition to JTAG
static struct drvs_map lowlevel_drivers_map[]
static void ublast_path_move(struct pathmove_command *cmd)
ublast_path_move - write a TMS sequence transition to JTAG
static int ublast_read_bitbang_tdos(uint8_t *buf, int nb_bits)
ublast_read_bitbang_tdos - read TDO of bitbang writes
static void ublast_usleep(int us)
static struct jtag_interface usb_blaster_interface
static void ublast_flush_buffer(void)
static void ublast_reset(int trst, int srst)
ublast_reset - reset the JTAG device is possible
static void ublast_idle_clock(void)
ublast_idle_clock - put back TCK to low level
static void ublast_queue_bytes(uint8_t *bytes, int nb_bytes)
ublast_queue_bytes - queue bytes for the USB Blaster
static int ublast_buf_read(uint8_t *buf, unsigned size, uint32_t *bytes_read)
static void ublast_stableclocks(int cycles)
static void ublast_runtest(int cycles, tap_state_t state)
static struct ublast_info info
static int ublast_execute_queue(void)
static void ublast_clock_tdi(int tdi, enum scan_type type)
ublast_clock_tdi - Output a TDI with bitbang mode
static void ublast_state_move(tap_state_t state, int skip)
ublast_state_move - move JTAG state to the target state
static bool ublast_compute_pin(enum gpio_steer steer)
ublast_compute_pin - compute if gpio should be asserted
static void ublast_queue_byte(uint8_t abyte)
ublast_queue_byte - queue one 'bitbang mode' byte for USB Blaster
static void ublast_clock_tdi_flip_tms(int tdi, enum scan_type type)
ublast_clock_tdi_flip_tms - Output a TDI with bitbang mode, change JTAG state
COMMAND_HANDLER(ublast_handle_vid_pid_command)
static int nb_buf_remaining(void)