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

Go to the source code of this file.

Data Structures

struct  openjtag_scan_result
 

Macros

#define CY7C65215_JTAG_CLASS   0xff
 
#define CY7C65215_JTAG_DISABLE   0xD1 /* bRequest: disable JTAG */
 
#define CY7C65215_JTAG_ENABLE   0xD0 /* bRequest: enable JTAG */
 
#define CY7C65215_JTAG_READ   0xD2 /* bRequest: read buffer */
 
#define CY7C65215_JTAG_REQUEST   0x40 /* bmRequestType: vendor host-to-device */
 
#define CY7C65215_JTAG_SUBCLASS   0x04
 
#define CY7C65215_JTAG_WRITE   0xD3 /* bRequest: write buffer */
 
#define CY7C65215_USB_TIMEOUT   100
 
#define OPENJTAG_BUFFER_SIZE   504
 
#define OPENJTAG_MAX_PENDING_RESULTS   256
 

Typedefs

typedef enum openjtag_tap_state openjtag_tap_state_t
 

Enumerations

enum  { OPENJTAG_VARIANT_STANDARD , OPENJTAG_VARIANT_CY7C65215 }
 
enum  openjtag_tap_state {
  OPENJTAG_TAP_INVALID = -1 , OPENJTAG_TAP_RESET = 0 , OPENJTAG_TAP_IDLE = 1 , OPENJTAG_TAP_SELECT_DR = 2 ,
  OPENJTAG_TAP_CAPTURE_DR = 3 , OPENJTAG_TAP_SHIFT_DR = 4 , OPENJTAG_TAP_EXIT1_DR = 5 , OPENJTAG_TAP_PAUSE_DR = 6 ,
  OPENJTAG_TAP_EXIT2_DR = 7 , OPENJTAG_TAP_UPDATE_DR = 8 , OPENJTAG_TAP_SELECT_IR = 9 , OPENJTAG_TAP_CAPURE_IR = 10 ,
  OPENJTAG_TAP_SHIFT_IR = 11 , OPENJTAG_TAP_EXIT1_IR = 12 , OPENJTAG_TAP_PAUSE_IR = 13 , OPENJTAG_TAP_EXIT2_IR = 14 ,
  OPENJTAG_TAP_UPDATE_IR = 15
}
 

Functions

 COMMAND_HANDLER (openjtag_handle_device_desc_command)
 
 COMMAND_HANDLER (openjtag_handle_variant_command)
 
static void openjtag_add_byte (char buf)
 
static void openjtag_add_scan (uint8_t *buffer, int length, struct scan_command *scan_cmd)
 
static int openjtag_buf_read (uint8_t *buf, uint32_t qty, uint32_t *bytes_read)
 
static int openjtag_buf_read_cy7c65215 (uint8_t *buf, uint32_t qty, uint32_t *bytes_read)
 
static int openjtag_buf_read_standard (uint8_t *buf, uint32_t qty, uint32_t *bytes_read)
 
static int openjtag_buf_write (uint8_t *buf, int size, uint32_t *bytes_written)
 
static int openjtag_buf_write_cy7c65215 (uint8_t *buf, int size, uint32_t *bytes_written)
 
static int openjtag_buf_write_standard (uint8_t *buf, int size, uint32_t *bytes_written)
 
static void openjtag_execute_command (struct jtag_command *cmd)
 
static int openjtag_execute_queue (void)
 
static void openjtag_execute_reset (struct jtag_command *cmd)
 
static void openjtag_execute_runtest (struct jtag_command *cmd)
 
static void openjtag_execute_scan (struct jtag_command *cmd)
 
static void openjtag_execute_sleep (struct jtag_command *cmd)
 
static void openjtag_execute_statemove (struct jtag_command *cmd)
 
static int openjtag_execute_tap_queue (void)
 
static int8_t openjtag_get_tap_state (int8_t state)
 
static int openjtag_init (void)
 
static int openjtag_init_cy7c65215 (void)
 
static int openjtag_init_standard (void)
 
static int openjtag_khz (int khz, int *jtag_speed)
 
static int openjtag_quit (void)
 
static int openjtag_quit_cy7c65215 (void)
 
static int openjtag_quit_standard (void)
 
static int openjtag_sendcommand (uint8_t cmd)
 
static void openjtag_set_state (uint8_t openocd_state)
 
static int openjtag_speed (int speed)
 
static int openjtag_speed_div (int speed, int *khz)
 
static void openjtag_write_tap_buffer (void)
 

Variables

static const uint16_t cy7c65215_pids [] = {0x0007, 0}
 
static const uint16_t cy7c65215_vids [] = {0x04b4, 0}
 
static unsigned int ep_in
 
static unsigned int ep_out
 
static struct ftdi_context ftdic
 
struct adapter_driver openjtag_adapter_driver
 
static const struct command_registration openjtag_command_handlers []
 
static char * openjtag_device_desc
 
static struct jtag_interface openjtag_interface
 
static uint16_t openjtag_pid = 0x6001
 
static struct openjtag_scan_result openjtag_scan_result_buffer [OPENJTAG_MAX_PENDING_RESULTS]
 
static int openjtag_scan_result_count
 
static const struct command_registration openjtag_subcommand_handlers []
 
static enum { ... }  openjtag_variant = OPENJTAG_VARIANT_STANDARD
 
static const char *const openjtag_variant_names []
 
static uint16_t openjtag_vid = 0x0403
 
static uint8_t usb_rx_buf [OPENJTAG_BUFFER_SIZE]
 
static uint32_t usb_rx_buf_len
 
static uint8_t usb_tx_buf [OPENJTAG_BUFFER_SIZE]
 
static int usb_tx_buf_offs
 
static struct libusb_device_handle * usbh
 

Macro Definition Documentation

◆ CY7C65215_JTAG_CLASS

#define CY7C65215_JTAG_CLASS   0xff

Definition at line 117 of file openjtag.c.

◆ CY7C65215_JTAG_DISABLE

#define CY7C65215_JTAG_DISABLE   0xD1 /* bRequest: disable JTAG */

Definition at line 108 of file openjtag.c.

◆ CY7C65215_JTAG_ENABLE

#define CY7C65215_JTAG_ENABLE   0xD0 /* bRequest: enable JTAG */

Definition at line 107 of file openjtag.c.

◆ CY7C65215_JTAG_READ

#define CY7C65215_JTAG_READ   0xD2 /* bRequest: read buffer */

Definition at line 109 of file openjtag.c.

◆ CY7C65215_JTAG_REQUEST

#define CY7C65215_JTAG_REQUEST   0x40 /* bmRequestType: vendor host-to-device */

Definition at line 106 of file openjtag.c.

◆ CY7C65215_JTAG_SUBCLASS

#define CY7C65215_JTAG_SUBCLASS   0x04

Definition at line 118 of file openjtag.c.

◆ CY7C65215_JTAG_WRITE

#define CY7C65215_JTAG_WRITE   0xD3 /* bRequest: write buffer */

Definition at line 110 of file openjtag.c.

◆ CY7C65215_USB_TIMEOUT

#define CY7C65215_USB_TIMEOUT   100

Definition at line 112 of file openjtag.c.

◆ OPENJTAG_BUFFER_SIZE

#define OPENJTAG_BUFFER_SIZE   504

Definition at line 84 of file openjtag.c.

◆ OPENJTAG_MAX_PENDING_RESULTS

#define OPENJTAG_MAX_PENDING_RESULTS   256

Definition at line 85 of file openjtag.c.

Typedef Documentation

◆ openjtag_tap_state_t

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
OPENJTAG_VARIANT_STANDARD 
OPENJTAG_VARIANT_CY7C65215 

Definition at line 39 of file openjtag.c.

◆ openjtag_tap_state

Enumerator
OPENJTAG_TAP_INVALID 
OPENJTAG_TAP_RESET 
OPENJTAG_TAP_IDLE 
OPENJTAG_TAP_SELECT_DR 
OPENJTAG_TAP_CAPTURE_DR 
OPENJTAG_TAP_SHIFT_DR 
OPENJTAG_TAP_EXIT1_DR 
OPENJTAG_TAP_PAUSE_DR 
OPENJTAG_TAP_EXIT2_DR 
OPENJTAG_TAP_UPDATE_DR 
OPENJTAG_TAP_SELECT_IR 
OPENJTAG_TAP_CAPURE_IR 
OPENJTAG_TAP_SHIFT_IR 
OPENJTAG_TAP_EXIT1_IR 
OPENJTAG_TAP_PAUSE_IR 
OPENJTAG_TAP_EXIT2_IR 
OPENJTAG_TAP_UPDATE_IR 

Definition at line 53 of file openjtag.c.

Function Documentation

◆ COMMAND_HANDLER() [1/2]

COMMAND_HANDLER ( openjtag_handle_device_desc_command  )

Definition at line 833 of file openjtag.c.

References CMD_ARGC, CMD_ARGV, ERROR_OK, LOG_ERROR, and openjtag_device_desc.

◆ COMMAND_HANDLER() [2/2]

COMMAND_HANDLER ( openjtag_handle_variant_command  )

Definition at line 843 of file openjtag.c.

References CMD_ARGC, CMD_ARGV, ERROR_OK, LOG_ERROR, name, openjtag_variant, and openjtag_variant_names.

◆ openjtag_add_byte()

static void openjtag_add_byte ( char  buf)
static

◆ openjtag_add_scan()

◆ openjtag_buf_read()

static int openjtag_buf_read ( uint8_t *  buf,
uint32_t  qty,
uint32_t *  bytes_read 
)
static

◆ openjtag_buf_read_cy7c65215()

static int openjtag_buf_read_cy7c65215 ( uint8_t *  buf,
uint32_t  qty,
uint32_t *  bytes_read 
)
static

◆ openjtag_buf_read_standard()

static int openjtag_buf_read_standard ( uint8_t *  buf,
uint32_t  qty,
uint32_t *  bytes_read 
)
static

Definition at line 269 of file openjtag.c.

References ERROR_JTAG_DEVICE_ERROR, ERROR_OK, ftdic, and LOG_DEBUG_IO.

Referenced by openjtag_buf_read().

◆ openjtag_buf_write()

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

◆ openjtag_buf_write_cy7c65215()

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

◆ openjtag_buf_write_standard()

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

Definition at line 206 of file openjtag.c.

References ERROR_JTAG_DEVICE_ERROR, ERROR_OK, ftdic, LOG_ERROR, and size.

Referenced by openjtag_buf_write().

◆ openjtag_execute_command()

◆ openjtag_execute_queue()

static int openjtag_execute_queue ( void  )
static

◆ openjtag_execute_reset()

static void openjtag_execute_reset ( struct jtag_command cmd)
static

Definition at line 655 of file openjtag.c.

References cmd, LOG_DEBUG_IO, and openjtag_add_byte().

Referenced by openjtag_execute_command().

◆ openjtag_execute_runtest()

static void openjtag_execute_runtest ( struct jtag_command cmd)
static

◆ openjtag_execute_scan()

◆ openjtag_execute_sleep()

static void openjtag_execute_sleep ( struct jtag_command cmd)
static

Definition at line 673 of file openjtag.c.

References cmd, and jtag_sleep().

Referenced by openjtag_execute_command().

◆ openjtag_execute_statemove()

static void openjtag_execute_statemove ( struct jtag_command cmd)
static

◆ openjtag_execute_tap_queue()

◆ openjtag_get_tap_state()

◆ openjtag_init()

◆ openjtag_init_cy7c65215()

◆ openjtag_init_standard()

static int openjtag_init_standard ( void  )
static

◆ openjtag_khz()

static int openjtag_khz ( int  khz,
int *  jtag_speed 
)
static

Definition at line 810 of file openjtag.c.

References ERROR_OK.

◆ openjtag_quit()

static int openjtag_quit ( void  )
static

◆ openjtag_quit_cy7c65215()

static int openjtag_quit_cy7c65215 ( void  )
static

◆ openjtag_quit_standard()

static int openjtag_quit_standard ( void  )
static

Definition at line 496 of file openjtag.c.

References ERROR_OK, and ftdic.

Referenced by openjtag_quit().

◆ openjtag_sendcommand()

static int openjtag_sendcommand ( uint8_t  cmd)
static

Definition at line 340 of file openjtag.c.

References cmd, and openjtag_buf_write().

Referenced by openjtag_init(), and openjtag_speed().

◆ openjtag_set_state()

static void openjtag_set_state ( uint8_t  openocd_state)
static

◆ openjtag_speed()

static int openjtag_speed ( int  speed)
static

Definition at line 346 of file openjtag.c.

References ERROR_OK, LOG_WARNING, and openjtag_sendcommand().

Referenced by openjtag_init().

◆ openjtag_speed_div()

static int openjtag_speed_div ( int  speed,
int *  khz 
)
static

Definition at line 803 of file openjtag.c.

References ERROR_OK.

◆ openjtag_write_tap_buffer()

static void openjtag_write_tap_buffer ( void  )
static

Variable Documentation

◆ cy7c65215_pids

const uint16_t cy7c65215_pids[] = {0x0007, 0}
static

Definition at line 115 of file openjtag.c.

Referenced by openjtag_init_cy7c65215().

◆ cy7c65215_vids

const uint16_t cy7c65215_vids[] = {0x04b4, 0}
static

Definition at line 114 of file openjtag.c.

Referenced by openjtag_init_cy7c65215().

◆ ep_in

unsigned int ep_in
static

◆ ep_out

unsigned int ep_out
static

◆ ftdic

◆ openjtag_adapter_driver

struct adapter_driver openjtag_adapter_driver
Initial value:
= {
.name = "openjtag",
.transports = jtag_only,
.init = openjtag_init,
.quit = openjtag_quit,
.speed = openjtag_speed,
.khz = openjtag_khz,
.speed_div = openjtag_speed_div,
.jtag_ops = &openjtag_interface,
}
const char *const jtag_only[]
Definition: adapter.c:31
static int openjtag_khz(int khz, int *jtag_speed)
Definition: openjtag.c:810
static int openjtag_quit(void)
Definition: openjtag.c:520
static struct jtag_interface openjtag_interface
Definition: openjtag.c:891
static const struct command_registration openjtag_command_handlers[]
Definition: openjtag.c:880
static int openjtag_speed_div(int speed, int *khz)
Definition: openjtag.c:803
static int openjtag_speed(int speed)
Definition: openjtag.c:346
static int openjtag_init(void)
Definition: openjtag.c:472

Definition at line 843 of file openjtag.c.

◆ openjtag_command_handlers

const struct command_registration openjtag_command_handlers[]
static
Initial value:
= {
{
.name = "openjtag",
.mode = COMMAND_ANY,
.help = "perform openjtag 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
static const struct command_registration openjtag_subcommand_handlers[]
Definition: openjtag.c:862
const char * usage
a string listing the options and arguments, required or optional
Definition: command.h:235

Definition at line 843 of file openjtag.c.

◆ openjtag_device_desc

char* openjtag_device_desc
static

Definition at line 80 of file openjtag.c.

Referenced by COMMAND_HANDLER(), and openjtag_init_standard().

◆ openjtag_interface

struct jtag_interface openjtag_interface
static
Initial value:
= {
.execute_queue = openjtag_execute_queue,
}
static int openjtag_execute_queue(void)
Definition: openjtag.c:791

Definition at line 843 of file openjtag.c.

◆ openjtag_pid

uint16_t openjtag_pid = 0x6001
static

Definition at line 78 of file openjtag.c.

Referenced by openjtag_init_standard().

◆ openjtag_scan_result_buffer

struct openjtag_scan_result openjtag_scan_result_buffer[OPENJTAG_MAX_PENDING_RESULTS]
static

Definition at line 97 of file openjtag.c.

Referenced by openjtag_add_scan(), and openjtag_execute_tap_queue().

◆ openjtag_scan_result_count

int openjtag_scan_result_count
static

Definition at line 101 of file openjtag.c.

Referenced by openjtag_add_scan(), openjtag_execute_tap_queue(), and openjtag_init().

◆ openjtag_subcommand_handlers

const struct command_registration openjtag_subcommand_handlers[]
static
Initial value:
= {
{
.name = "device_desc",
.handler = openjtag_handle_device_desc_command,
.mode = COMMAND_CONFIG,
.help = "set the USB device description of the OpenJTAG",
.usage = "description-string",
},
{
.name = "variant",
.handler = openjtag_handle_variant_command,
.mode = COMMAND_CONFIG,
.help = "set the OpenJTAG variant",
.usage = "variant-string",
},
}
@ COMMAND_CONFIG
Definition: command.h:41

Definition at line 843 of file openjtag.c.

◆ 

◆ openjtag_variant_names

const char* const openjtag_variant_names[]
static
Initial value:
= {
"standard",
"cy7c65215",
}
#define NULL
Definition: usb.h:16

Definition at line 44 of file openjtag.c.

Referenced by COMMAND_HANDLER().

◆ openjtag_vid

uint16_t openjtag_vid = 0x0403
static

Definition at line 77 of file openjtag.c.

Referenced by openjtag_init_standard().

◆ usb_rx_buf

uint8_t usb_rx_buf[OPENJTAG_BUFFER_SIZE]
static

Definition at line 97 of file openjtag.c.

Referenced by openjtag_execute_tap_queue(), and openjtag_write_tap_buffer().

◆ usb_rx_buf_len

uint32_t usb_rx_buf_len
static

Definition at line 96 of file openjtag.c.

Referenced by openjtag_execute_tap_queue(), openjtag_init(), and openjtag_write_tap_buffer().

◆ usb_tx_buf

uint8_t usb_tx_buf[OPENJTAG_BUFFER_SIZE]
static

Definition at line 95 of file openjtag.c.

Referenced by openjtag_add_byte(), and openjtag_write_tap_buffer().

◆ usb_tx_buf_offs

int usb_tx_buf_offs
static

◆ usbh

struct libusb_device_handle* usbh
static