OpenOCD
usb_blaster.c File Reference
Include dependency graph for usb_blaster.c:

Go to the source code of this file.

Data Structures

struct  drvs_map
 
struct  ublast_info
 

Macros

#define BUF_LEN   4096
 
#define CMD_COPY_TDO_BUFFER   0x5F
 
#define LED   (1 << 5)
 
#define MAX_PACKET_SIZE   64
 
#define NCE   (1 << 2)
 
#define NCS   (1 << 3)
 
#define READ   (1 << 6)
 
#define READ_TDO   (1 << 0)
 
#define SHMODE   (1 << 7)
 
#define TCK   (1 << 0)
 
#define TDI   (1 << 4)
 
#define TMS   (1 << 1)
 

Enumerations

enum  gpio_steer { FIXED_0 = 0 , FIXED_1 , SRST , TRST }
 

Functions

 COMMAND_HANDLER (ublast_firmware_command)
 
 COMMAND_HANDLER (ublast_handle_lowlevel_drv_command)
 
 COMMAND_HANDLER (ublast_handle_pin_command)
 
 COMMAND_HANDLER (ublast_handle_vid_pid_command)
 
static char * hexdump (uint8_t *buf, unsigned int size)
 
static int nb_buf_remaining (void)
 
static int ublast_buf_read (uint8_t *buf, unsigned size, uint32_t *bytes_read)
 
static int ublast_buf_write (uint8_t *buf, int size, uint32_t *bytes_written)
 
static uint8_t ublast_build_out (enum scan_type type)
 ublast_build_out - build bitbang mode output byte More...
 
static void ublast_clock_tdi (int tdi, enum scan_type type)
 ublast_clock_tdi - Output a TDI with bitbang mode More...
 
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 More...
 
static void ublast_clock_tms (int tms)
 ublast_clock_tms - clock a TMS transition More...
 
static bool ublast_compute_pin (enum gpio_steer steer)
 ublast_compute_pin - compute if gpio should be asserted More...
 
static int ublast_execute_queue (void)
 
static void ublast_flush_buffer (void)
 
static void ublast_idle_clock (void)
 ublast_idle_clock - put back TCK to low level More...
 
static int ublast_init (void)
 ublast_init - Initialize the Altera device More...
 
static void ublast_initial_wipeout (void)
 
static void ublast_path_move (struct pathmove_command *cmd)
 ublast_path_move - write a TMS sequence transition to JTAG More...
 
static void ublast_queue_byte (uint8_t abyte)
 ublast_queue_byte - queue one 'bitbang mode' byte for USB Blaster More...
 
static void ublast_queue_bytes (uint8_t *bytes, int nb_bytes)
 ublast_queue_bytes - queue bytes for the USB Blaster More...
 
static void ublast_queue_tdi (uint8_t *bits, int nb_bits, enum scan_type scan)
 ublast_queue_tdi - short description More...
 
static int ublast_quit (void)
 ublast_quit - Release the Altera device More...
 
static int ublast_read_bitbang_tdos (uint8_t *buf, int nb_bits)
 ublast_read_bitbang_tdos - read TDO of bitbang writes More...
 
static int ublast_read_byteshifted_tdos (uint8_t *buf, int nb_bytes)
 ublast_read_byteshifted_tdos - read TDO of byteshift writes More...
 
static void ublast_reset (int trst, int srst)
 ublast_reset - reset the JTAG device is possible More...
 
static void ublast_runtest (int cycles, tap_state_t state)
 
static int ublast_scan (struct scan_command *cmd)
 ublast_scan - launches a DR-scan or IR-scan More...
 
static void ublast_stableclocks (int cycles)
 
static void ublast_state_move (tap_state_t state, int skip)
 ublast_state_move - move JTAG state to the target state More...
 
static void ublast_tms (struct tms_command *cmd)
 ublast_tms - write a tms command More...
 
static void ublast_tms_seq (const uint8_t *bits, int nb_bits, int skip)
 ublast_tms_seq - write a TMS sequence transition to JTAG More...
 
static void ublast_usleep (int us)
 

Variables

static struct ublast_info info
 
static struct drvs_map lowlevel_drivers_map []
 
static const struct command_registration ublast_command_handlers []
 
static const struct command_registration ublast_subcommand_handlers []
 
struct adapter_driver usb_blaster_adapter_driver
 
static struct jtag_interface usb_blaster_interface
 

Macro Definition Documentation

◆ BUF_LEN

#define BUF_LEN   4096

Definition at line 87 of file usb_blaster.c.

◆ CMD_COPY_TDO_BUFFER

#define CMD_COPY_TDO_BUFFER   0x5F

Definition at line 90 of file usb_blaster.c.

◆ LED

#define LED   (1 << 5)

Definition at line 238 of file usb_blaster.c.

◆ MAX_PACKET_SIZE

#define MAX_PACKET_SIZE   64

Definition at line 80 of file usb_blaster.c.

◆ NCE

#define NCE   (1 << 2)

Definition at line 235 of file usb_blaster.c.

◆ NCS

#define NCS   (1 << 3)

Definition at line 236 of file usb_blaster.c.

◆ READ

#define READ   (1 << 6)

Definition at line 239 of file usb_blaster.c.

◆ READ_TDO

#define READ_TDO   (1 << 0)

Definition at line 241 of file usb_blaster.c.

◆ SHMODE

#define SHMODE   (1 << 7)

Definition at line 240 of file usb_blaster.c.

◆ TCK

#define TCK   (1 << 0)

Definition at line 233 of file usb_blaster.c.

◆ TDI

#define TDI   (1 << 4)

Definition at line 237 of file usb_blaster.c.

◆ TMS

#define TMS   (1 << 1)

Definition at line 234 of file usb_blaster.c.

Enumeration Type Documentation

◆ gpio_steer

enum gpio_steer
Enumerator
FIXED_0 
FIXED_1 
SRST 
TRST 

Definition at line 92 of file usb_blaster.c.

Function Documentation

◆ COMMAND_HANDLER() [1/4]

COMMAND_HANDLER ( ublast_firmware_command  )

Definition at line 999 of file usb_blaster.c.

◆ COMMAND_HANDLER() [2/4]

COMMAND_HANDLER ( ublast_handle_lowlevel_drv_command  )

◆ COMMAND_HANDLER() [3/4]

◆ COMMAND_HANDLER() [4/4]

◆ hexdump()

static char* hexdump ( uint8_t *  buf,
unsigned int  size 
)
static

Definition at line 151 of file usb_blaster.c.

References size.

Referenced by ublast_buf_read(), ublast_buf_write(), and ublast_scan().

◆ nb_buf_remaining()

static int nb_buf_remaining ( void  )
static

Definition at line 183 of file usb_blaster.c.

References BUF_LEN, ublast_info::bufidx, and info.

Referenced by ublast_queue_byte(), and ublast_queue_bytes().

◆ ublast_buf_read()

static int ublast_buf_read ( uint8_t *  buf,
unsigned  size,
uint32_t *  bytes_read 
)
static

◆ ublast_buf_write()

static int ublast_buf_write ( uint8_t *  buf,
int  size,
uint32_t *  bytes_written 
)
static

◆ ublast_build_out()

static uint8_t ublast_build_out ( enum scan_type  type)
static

ublast_build_out - build bitbang mode output byte

Parameters
typesays if reading back TDO is required

Returns the compute bitbang mode byte

Definition at line 289 of file usb_blaster.c.

References info, LED, NCE, NCS, ublast_info::pin6, ublast_info::pin8, READ, SCAN_IN, SCAN_IO, ublast_info::tdi, TDI, ublast_info::tms, TMS, type, and ublast_compute_pin().

Referenced by COMMAND_HANDLER(), ublast_clock_tdi(), ublast_clock_tdi_flip_tms(), ublast_clock_tms(), ublast_idle_clock(), ublast_initial_wipeout(), and ublast_reset().

◆ ublast_clock_tdi()

static void ublast_clock_tdi ( int  tdi,
enum scan_type  type 
)
static

ublast_clock_tdi - Output a TDI with bitbang mode

Parameters
tdithe TDI bit to be shifted out
typescan type (ie. does a readback of TDO is required)

Output a TDI bit and assert clock to push it into the JTAG device :

  • writing out TCK=0, TMS=<old_state>=0, TDI=<tdi>
  • writing out TCK=1, TMS=<new_state>, TDI=<tdi> which triggers the JTAG device acquiring the data.

If a TDO is to be read back, the required read is requested (bitbang mode), and the USB Blaster will send back a byte with bit0 representing the TDO.

Definition at line 363 of file usb_blaster.c.

References info, LOG_DEBUG_IO, SCAN_OUT, TCK, ublast_info::tdi, type, ublast_build_out(), and ublast_queue_byte().

Referenced by ublast_queue_tdi().

◆ ublast_clock_tdi_flip_tms()

static void ublast_clock_tdi_flip_tms ( int  tdi,
enum scan_type  type 
)
static

ublast_clock_tdi_flip_tms - Output a TDI with bitbang mode, change JTAG state

Parameters
tdithe TDI bit to be shifted out
typescan type (ie. does a readback of TDO is required)

This function is the same as ublast_clock_tdi(), but it changes also the TMS while output the TDI. This should be the last TDI output of a TDI sequence, which will change state from :

  • IRSHIFT -> IREXIT1
  • or DRSHIFT -> DREXIT1

Definition at line 388 of file usb_blaster.c.

References info, LOG_DEBUG_IO, SCAN_OUT, TCK, ublast_info::tdi, ublast_info::tms, type, ublast_build_out(), and ublast_queue_byte().

Referenced by ublast_queue_tdi().

◆ ublast_clock_tms()

static void ublast_clock_tms ( int  tms)
static

ublast_clock_tms - clock a TMS transition

Parameters
tmsthe TMS to be sent

Triggers a TMS transition (ie. one JTAG TAP state move).

Definition at line 325 of file usb_blaster.c.

References info, LOG_DEBUG_IO, SCAN_OUT, TCK, ublast_info::tdi, ublast_info::tms, ublast_build_out(), and ublast_queue_byte().

Referenced by ublast_path_move(), and ublast_tms_seq().

◆ ublast_compute_pin()

static bool ublast_compute_pin ( enum gpio_steer  steer)
static

ublast_compute_pin - compute if gpio should be asserted

Parameters
steercontrol (ie. TRST driven, SRST driven, of fixed)

Returns pin value (1 means driven high, 0 mean driven low)

Definition at line 267 of file usb_blaster.c.

References FIXED_0, FIXED_1, info, SRST, ublast_info::srst_asserted, TRST, and ublast_info::trst_asserted.

Referenced by ublast_build_out().

◆ ublast_execute_queue()

◆ ublast_flush_buffer()

◆ ublast_idle_clock()

static void ublast_idle_clock ( void  )
static

ublast_idle_clock - put back TCK to low level

See ublast_queue_tdi() comment for the usage of this function.

Definition at line 342 of file usb_blaster.c.

References LOG_DEBUG_IO, SCAN_OUT, ublast_build_out(), and ublast_queue_byte().

Referenced by ublast_path_move(), ublast_queue_tdi(), and ublast_tms_seq().

◆ ublast_init()

static int ublast_init ( void  )
static

◆ ublast_initial_wipeout()

static void ublast_initial_wipeout ( void  )
static

◆ ublast_path_move()

static void ublast_path_move ( struct pathmove_command cmd)
static

ublast_path_move - write a TMS sequence transition to JTAG

Parameters
cmdpath transition

Write a series of TMS transitions, where each transition consists in :

  • writing out TCK=0, TMS=<new_state>, TDI=<???>
  • writing out TCK=1, TMS=<new_state>, TDI=<???> which triggers the transition The function ensures that at the end of the sequence, the clock (TCK) is put low.

Definition at line 475 of file usb_blaster.c.

References cmd, LOG_DEBUG_IO, tap_get_state(), tap_set_state, tap_state_transition(), ublast_clock_tms(), and ublast_idle_clock().

Referenced by ublast_execute_queue().

◆ ublast_queue_byte()

static void ublast_queue_byte ( uint8_t  abyte)
static

ublast_queue_byte - queue one 'bitbang mode' byte for USB Blaster

Parameters
abytethe byte to queue

Queues one byte in 'bitbang mode' to the USB Blaster. The byte is not actually sent, but stored in a buffer. The write is performed once the buffer is filled, or if an explicit ublast_flush_buffer() is called.

Definition at line 251 of file usb_blaster.c.

References ublast_info::buf, ublast_info::bufidx, info, LOG_DEBUG_IO, nb_buf_remaining(), and ublast_flush_buffer().

Referenced by COMMAND_HANDLER(), ublast_clock_tdi(), ublast_clock_tdi_flip_tms(), ublast_clock_tms(), ublast_idle_clock(), ublast_queue_tdi(), and ublast_reset().

◆ ublast_queue_bytes()

static void ublast_queue_bytes ( uint8_t *  bytes,
int  nb_bytes 
)
static

ublast_queue_bytes - queue bytes for the USB Blaster

Parameters
bytesbyte array
nb_bytesnumber of bytes

Queues bytes to be sent to the USB Blaster. The bytes are not actually sent, but stored in a buffer. The write is performed once the buffer is filled, or if an explicit ublast_flush_buffer() is called.

Definition at line 415 of file usb_blaster.c.

References ublast_info::buf, BUF_LEN, ublast_info::bufidx, info, LOG_DEBUG_IO, LOG_ERROR, nb_buf_remaining(), and ublast_flush_buffer().

Referenced by ublast_queue_tdi().

◆ ublast_queue_tdi()

static void ublast_queue_tdi ( uint8_t *  bits,
int  nb_bits,
enum scan_type  scan 
)
static

ublast_queue_tdi - short description

Parameters
bitsbits to be queued on TDI (or NULL if 0 are to be queued)
nb_bitsnumber of bits
scanscan type (ie. if TDO read back is required or not)

Outputs a series of TDI bits on TDI. As a side effect, the last TDI bit is sent along a TMS=1, and triggers a JTAG TAP state shift if input bits were non NULL.

In order to not saturate the USB Blaster queues, this method reads back TDO if the scan type requests it, and stores them back in bits.

As a side note, the state of TCK when entering this function must be low. This is because byteshift mode outputs TDI on rising TCK and reads TDO on falling TCK if and only if TCK is low before queuing byteshift mode bytes. If TCK was high, the USB blaster will queue TDI on falling edge, and read TDO on rising edge !!!

Definition at line 601 of file usb_blaster.c.

References bits, BUF_LEN, ublast_info::bufidx, CMD_COPY_TDO_BUFFER, COPY_TDO_BUFFER, DIV_ROUND_UP, ublast_info::flags, info, MAX_PACKET_SIZE, MIN, READ, scan, SCAN_IN, SCAN_IO, SHMODE, ublast_clock_tdi(), ublast_clock_tdi_flip_tms(), ublast_idle_clock(), ublast_queue_byte(), ublast_queue_bytes(), ublast_read_bitbang_tdos(), and ublast_read_byteshifted_tdos().

Referenced by ublast_runtest(), ublast_scan(), and ublast_stableclocks().

◆ ublast_quit()

static int ublast_quit ( void  )
static

ublast_quit - Release the Altera device

Releases the device :

  • put the device pins in 'high impedance' mode
  • close the USB device

Returns always ERROR_OK

Definition at line 889 of file usb_blaster.c.

References ublast_lowlevel::close, ublast_info::drv, info, and ublast_buf_write().

◆ ublast_read_bitbang_tdos()

static int ublast_read_bitbang_tdos ( uint8_t *  buf,
int  nb_bits 
)
static

ublast_read_bitbang_tdos - read TDO of bitbang writes

Parameters
bufthe buffer to store the bits
nb_bitsthe number of bits

Reads back from USB Blaster TDO bits, triggered by a 'bitbang write', ie. one bit per received byte from USB interface, and store them in buffer, where :

  • first bit is stored in byte0, bit0 (LSB)
  • second bit is stored in byte0, bit 1 ...
  • eight bit is stored in byte0, bit 7
  • ninth bit is stored in byte1, bit 0
  • etc ...

Returns ERROR_OK if OK, ERROR_xxx if a read error occurred

Definition at line 558 of file usb_blaster.c.

References ERROR_OK, LOG_DEBUG_IO, READ_TDO, ublast_buf_read(), and ublast_flush_buffer().

Referenced by ublast_queue_tdi().

◆ ublast_read_byteshifted_tdos()

static int ublast_read_byteshifted_tdos ( uint8_t *  buf,
int  nb_bytes 
)
static

ublast_read_byteshifted_tdos - read TDO of byteshift writes

Parameters
bufthe buffer to store the bits
nb_bytesthe number of bytes

Reads back from USB Blaster TDO bits, triggered by a 'byteshift write', ie. eight bits per received byte from USB interface, and store them in buffer.

As the USB blaster stores the TDO bits in LSB (ie. first bit in (byte0, bit0), second bit in (byte0, bit1), ...), which is what we want to return, simply read bytes from USB interface and store them.

Returns ERROR_OK if OK, ERROR_xxx if a read error occurred

Definition at line 528 of file usb_blaster.c.

References ERROR_OK, LOG_DEBUG_IO, ublast_buf_read(), and ublast_flush_buffer().

Referenced by ublast_queue_tdi().

◆ ublast_reset()

static void ublast_reset ( int  trst,
int  srst 
)
static

ublast_reset - reset the JTAG device is possible

Parameters
trst1 if TRST is to be asserted
srst1 if SRST is to be asserted

Definition at line 308 of file usb_blaster.c.

References info, SCAN_OUT, ublast_info::srst_asserted, ublast_info::trst_asserted, ublast_build_out(), ublast_flush_buffer(), and ublast_queue_byte().

Referenced by ublast_execute_queue().

◆ ublast_runtest()

static void ublast_runtest ( int  cycles,
tap_state_t  state 
)
static

Definition at line 678 of file usb_blaster.c.

References LOG_DEBUG_IO, NULL, SCAN_OUT, state, TAP_IDLE, ublast_queue_tdi(), and ublast_state_move().

Referenced by ublast_execute_queue().

◆ ublast_scan()

static int ublast_scan ( struct scan_command cmd)
static

ublast_scan - launches a DR-scan or IR-scan

Parameters
cmdthe command to launch

Launch a JTAG IR-scan or DR-scan

Returns ERROR_OK if OK, ERROR_xxx if a read/write error occurred.

Definition at line 701 of file usb_blaster.c.

References cmd, DIV_ROUND_UP, ERROR_OK, hexdump(), jtag_build_buffer(), jtag_read_buffer(), jtag_scan_type(), LOG_DEBUG_IO, NULL, TAP_DRSHIFT, TAP_IRSHIFT, type, ublast_queue_tdi(), and ublast_state_move().

Referenced by ublast_execute_queue().

◆ ublast_stableclocks()

static void ublast_stableclocks ( int  cycles)
static

Definition at line 687 of file usb_blaster.c.

References LOG_DEBUG_IO, NULL, SCAN_OUT, and ublast_queue_tdi().

Referenced by ublast_execute_queue().

◆ ublast_state_move()

static void ublast_state_move ( tap_state_t  state,
int  skip 
)
static

ublast_state_move - move JTAG state to the target state

Parameters
statethe target state
skipnumber of bits to skip at the beginning of the path

Input the correct TMS sequence to the JTAG TAP so that we end up in the target state. This assumes the current state (tap_get_state()) is correct.

Definition at line 499 of file usb_blaster.c.

References LOG_DEBUG_IO, state, tap_get_state(), tap_get_tms_path(), tap_get_tms_path_len(), tap_set_state, tap_state_name(), and ublast_tms_seq().

Referenced by ublast_execute_queue(), ublast_runtest(), and ublast_scan().

◆ ublast_tms()

static void ublast_tms ( struct tms_command cmd)
static

ublast_tms - write a tms command

Parameters
cmdtms command

Definition at line 459 of file usb_blaster.c.

References cmd, LOG_DEBUG_IO, and ublast_tms_seq().

Referenced by ublast_execute_queue().

◆ ublast_tms_seq()

static void ublast_tms_seq ( const uint8_t *  bits,
int  nb_bits,
int  skip 
)
static

ublast_tms_seq - write a TMS sequence transition to JTAG

Parameters
bitsTMS bits to be written (bit0, bit1 .. bitN)
nb_bitsnumber of TMS bits (between 1 and 8)
skipnumber of TMS bits to skip at the beginning of the series

Write a series of TMS transitions, where each transition consists in :

  • writing out TCK=0, TMS=<new_state>, TDI=<???>
  • writing out TCK=1, TMS=<new_state>, TDI=<???> which triggers the transition The function ensures that at the end of the sequence, the clock (TCK) is put low.

Definition at line 445 of file usb_blaster.c.

References bits, LOG_DEBUG_IO, ublast_clock_tms(), and ublast_idle_clock().

Referenced by ublast_initial_wipeout(), ublast_state_move(), and ublast_tms().

◆ ublast_usleep()

static void ublast_usleep ( int  us)
static

Definition at line 738 of file usb_blaster.c.

References jtag_sleep(), and LOG_DEBUG_IO.

Referenced by ublast_execute_queue().

Variable Documentation

◆ info

struct ublast_info info
static
Initial value:
= {
.ublast_vid = 0x09fb,
.ublast_pid = 0x6001,
.lowlevel_name = NULL,
.srst_asserted = false,
.trst_asserted = false,
.pin6 = FIXED_1,
.pin8 = FIXED_1,
}
#define NULL
Definition: usb.h:16
@ FIXED_1
Definition: usb_blaster.c:94

Definition at line 1 of file usb_blaster.c.

Referenced by COMMAND_HANDLER(), nb_buf_remaining(), ublast_buf_read(), ublast_buf_write(), ublast_build_out(), ublast_clock_tdi(), ublast_clock_tdi_flip_tms(), ublast_clock_tms(), ublast_compute_pin(), ublast_flush_buffer(), ublast_init(), ublast_initial_wipeout(), ublast_queue_byte(), ublast_queue_bytes(), ublast_queue_tdi(), ublast_quit(), and ublast_reset().

◆ lowlevel_drivers_map

struct drvs_map lowlevel_drivers_map[]
static
Initial value:
= {
{ NULL, NULL },
}

Definition at line 1 of file usb_blaster.c.

Referenced by ublast_init().

◆ ublast_command_handlers

const struct command_registration ublast_command_handlers[]
static
Initial value:
= {
{
.name = "usb_blaster",
.mode = COMMAND_ANY,
.help = "perform usb_blaster management",
.usage = "",
},
}
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:247
@ COMMAND_ANY
Definition: command.h:42
const char * usage
a string listing the options and arguments, required or optional
Definition: command.h:235
static const struct command_registration ublast_subcommand_handlers[]
Definition: usb_blaster.c:1010

Definition at line 999 of file usb_blaster.c.

◆ ublast_subcommand_handlers

const struct command_registration ublast_subcommand_handlers[]
static

Definition at line 999 of file usb_blaster.c.

◆ usb_blaster_adapter_driver

struct adapter_driver usb_blaster_adapter_driver
Initial value:
= {
.name = "usb_blaster",
.transports = jtag_only,
.init = ublast_init,
.quit = ublast_quit,
.jtag_ops = &usb_blaster_interface,
}
const char *const jtag_only[]
Definition: adapter.c:31
static const struct command_registration ublast_command_handlers[]
Definition: usb_blaster.c:1044
static int ublast_init(void)
ublast_init - Initialize the Altera device
Definition: usb_blaster.c:828
static int ublast_quit(void)
ublast_quit - Release the Altera device
Definition: usb_blaster.c:889
static struct jtag_interface usb_blaster_interface
Definition: usb_blaster.c:1055

Definition at line 999 of file usb_blaster.c.

◆ usb_blaster_interface

struct jtag_interface usb_blaster_interface
static
Initial value:
= {
.supported = DEBUG_CAP_TMS_SEQ,
.execute_queue = ublast_execute_queue,
}
#define DEBUG_CAP_TMS_SEQ
Definition: interface.h:189
static int ublast_execute_queue(void)
Definition: usb_blaster.c:768

Definition at line 999 of file usb_blaster.c.