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

Go to the source code of this file.

Data Structures

struct  pending_scan_result
 

Macros

#define B1000000   0010010
 
#define BUSPIRATE_BUFFER_SIZE   1024
 
#define BUSPIRATE_MAX_PENDING_SCANS   128
 
#define BYTES_PER_LINE   16
 
#define CMD_ENTER_OOCD   0x06
 
#define CMD_ENTER_RWIRE   0x05
 
#define CMD_FEATURE   0x02
 
#define CMD_JTAG_SPEED   0x08
 
#define CMD_PORT_MODE   0x01
 
#define CMD_RAW_CONFIG_2W   0x00
 
#define CMD_RAW_CONFIG_3V3   0x08
 
#define CMD_RAW_CONFIG_3W   0x04
 
#define CMD_RAW_CONFIG_HIZ   0x00
 
#define CMD_RAW_CONFIG_LSB   0x02
 
#define CMD_RAW_CONFIG_MSB   0x00
 
#define CMD_RAW_MODE   0x80
 
#define CMD_RAW_PERIPH   0x40
 
#define CMD_RAW_SPEED   0x60
 
#define CMD_READ_ADCS   0x03
 
#define CMD_TAP_SHIFT   0x05
 
#define CMD_TAP_SHIFT_HEADER_LEN   3
 
#define CMD_UART_SPEED   0x07
 
#define CMD_UNKNOWN   0x00
 
#define LINE_SIZE   81
 
#define NORMAL_TIMEOUT   10
 
#define SHORT_TIMEOUT   1 /* Must be at least 1. */
 

Enumerations

enum  { MODE_HIZ = 0 , MODE_JTAG = 1 , MODE_JTAG_OD = 2 }
 
enum  {
  FEATURE_LED = 0x01 , FEATURE_VREG = 0x02 , FEATURE_TRST = 0x04 , FEATURE_SRST = 0x08 ,
  FEATURE_PULLUP = 0x10
}
 
enum  { ACTION_DISABLE = 0 , ACTION_ENABLE = 1 }
 
enum  { SERIAL_NORMAL = 0 , SERIAL_FAST = 1 }
 
enum  { SPEED_RAW_5_KHZ = 0x0 , SPEED_RAW_50_KHZ = 0x1 , SPEED_RAW_100_KHZ = 0x2 , SPEED_RAW_400_KHZ = 0x3 }
 

Functions

static void buspirate_bbio_enable (int)
 
static void buspirate_end_state (tap_state_t state)
 
static int buspirate_execute_queue (struct jtag_command *cmd_queue)
 
static int buspirate_init (void)
 
static unsigned char buspirate_jtag_command (int, uint8_t *, int)
 
static void buspirate_jtag_get_adcs (int)
 
static void buspirate_jtag_reset (int)
 
static void buspirate_jtag_set_feature (int, char, char)
 
static void buspirate_jtag_set_mode (int, char)
 
static void buspirate_jtag_set_speed (int, char)
 
static void buspirate_path_move (unsigned int num_states, tap_state_t *path)
 
static void buspirate_print_buffer (uint8_t *buf, int size)
 
static int buspirate_quit (void)
 
static int buspirate_reset (int trst, int srst)
 
static void buspirate_runtest (unsigned int num_cycles)
 
static void buspirate_scan (bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size, struct scan_command *command)
 
static void buspirate_serial_close (int fd)
 
static int buspirate_serial_open (char *port)
 
static int buspirate_serial_read (int fd, uint8_t *buf, int size)
 
static int buspirate_serial_setspeed (int fd, char speed, cc_t timeout)
 
static int buspirate_serial_write (int fd, uint8_t *buf, int size)
 
static void buspirate_set_feature (int, char, char)
 
static void buspirate_set_mode (int, char)
 
static void buspirate_set_speed (int, char)
 
static void buspirate_stableclocks (unsigned int num_cycles)
 
static void buspirate_state_move (void)
 
static void buspirate_swd_clear_sticky_errors (void)
 
static void buspirate_swd_idle_clocks (uint32_t no_bits)
 
static int buspirate_swd_init (void)
 
static void buspirate_swd_read_reg (uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
 
static int buspirate_swd_run_queue (void)
 
static void buspirate_swd_set_feature (int, char, char)
 
static void buspirate_swd_set_mode (int, char)
 
static void buspirate_swd_set_speed (int, char)
 
static int buspirate_swd_switch_seq (enum swd_special_seq seq)
 
static uint8_t buspirate_swd_write_header (uint8_t cmd)
 
static void buspirate_swd_write_reg (uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
 
static void buspirate_tap_append (int tms, int tdi)
 
static void buspirate_tap_append_scan (int length, uint8_t *buffer, struct scan_command *command)
 
static int buspirate_tap_execute (void)
 
static void buspirate_tap_init (void)
 
static void buspirate_tap_make_space (int scan, int bits)
 
 COMMAND_HANDLER (buspirate_handle_adc_command)
 
 COMMAND_HANDLER (buspirate_handle_led_command)
 
 COMMAND_HANDLER (buspirate_handle_mode_command)
 
 COMMAND_HANDLER (buspirate_handle_port_command)
 
 COMMAND_HANDLER (buspirate_handle_pullup_command)
 
 COMMAND_HANDLER (buspirate_handle_speed_command)
 
 COMMAND_HANDLER (buspirate_handle_vreg_command)
 
static bool read_and_discard_all_data (const int fd)
 

Variables

struct adapter_driver buspirate_adapter_driver
 
static int buspirate_baudrate = SERIAL_NORMAL
 
static const struct command_registration buspirate_command_handlers []
 
static int buspirate_fd = -1
 
static struct jtag_interface buspirate_interface
 
static int buspirate_pinmode = MODE_JTAG_OD
 
static char * buspirate_port
 
static int buspirate_pullup
 
static const struct command_registration buspirate_subcommand_handlers []
 
static const struct swd_driver buspirate_swd
 
static const char *const buspirate_transports [] = { "jtag", "swd", NULL }
 
static int buspirate_vreg
 
static enum tap_state last_tap_state = TAP_RESET
 
static int queued_retval
 
static char swd_features
 
static bool swd_mode
 
static int tap_chain_index
 
static struct pending_scan_result tap_pending_scans [BUSPIRATE_MAX_PENDING_SCANS]
 
static int tap_pending_scans_num
 
static uint8_t tdi_chain [BUSPIRATE_BUFFER_SIZE]
 
static uint8_t tms_chain [BUSPIRATE_BUFFER_SIZE]
 

Macro Definition Documentation

◆ B1000000

#define B1000000   0010010

Definition at line 62 of file buspirate.c.

◆ BUSPIRATE_BUFFER_SIZE

#define BUSPIRATE_BUFFER_SIZE   1024

Definition at line 671 of file buspirate.c.

◆ BUSPIRATE_MAX_PENDING_SCANS

#define BUSPIRATE_MAX_PENDING_SCANS   128

Definition at line 682 of file buspirate.c.

◆ BYTES_PER_LINE

#define BYTES_PER_LINE   16

Definition at line 1267 of file buspirate.c.

◆ CMD_ENTER_OOCD

#define CMD_ENTER_OOCD   0x06

Definition at line 43 of file buspirate.c.

◆ CMD_ENTER_RWIRE

#define CMD_ENTER_RWIRE   0x05

Definition at line 42 of file buspirate.c.

◆ CMD_FEATURE

#define CMD_FEATURE   0x02

Definition at line 38 of file buspirate.c.

◆ CMD_JTAG_SPEED

#define CMD_JTAG_SPEED   0x08

Definition at line 45 of file buspirate.c.

◆ CMD_PORT_MODE

#define CMD_PORT_MODE   0x01

Definition at line 37 of file buspirate.c.

◆ CMD_RAW_CONFIG_2W

#define CMD_RAW_CONFIG_2W   0x00

Definition at line 55 of file buspirate.c.

◆ CMD_RAW_CONFIG_3V3

#define CMD_RAW_CONFIG_3V3   0x08

Definition at line 54 of file buspirate.c.

◆ CMD_RAW_CONFIG_3W

#define CMD_RAW_CONFIG_3W   0x04

Definition at line 56 of file buspirate.c.

◆ CMD_RAW_CONFIG_HIZ

#define CMD_RAW_CONFIG_HIZ   0x00

Definition at line 53 of file buspirate.c.

◆ CMD_RAW_CONFIG_LSB

#define CMD_RAW_CONFIG_LSB   0x02

Definition at line 58 of file buspirate.c.

◆ CMD_RAW_CONFIG_MSB

#define CMD_RAW_CONFIG_MSB   0x00

Definition at line 57 of file buspirate.c.

◆ CMD_RAW_MODE

#define CMD_RAW_MODE   0x80

Definition at line 48 of file buspirate.c.

◆ CMD_RAW_PERIPH

#define CMD_RAW_PERIPH   0x40

Definition at line 46 of file buspirate.c.

◆ CMD_RAW_SPEED

#define CMD_RAW_SPEED   0x60

Definition at line 47 of file buspirate.c.

◆ CMD_READ_ADCS

#define CMD_READ_ADCS   0x03

Definition at line 39 of file buspirate.c.

◆ CMD_TAP_SHIFT

#define CMD_TAP_SHIFT   0x05

Definition at line 41 of file buspirate.c.

◆ CMD_TAP_SHIFT_HEADER_LEN

#define CMD_TAP_SHIFT_HEADER_LEN   3

Definition at line 50 of file buspirate.c.

◆ CMD_UART_SPEED

#define CMD_UART_SPEED   0x07

Definition at line 44 of file buspirate.c.

◆ CMD_UNKNOWN

#define CMD_UNKNOWN   0x00

Definition at line 36 of file buspirate.c.

◆ LINE_SIZE

#define LINE_SIZE   81

Definition at line 1266 of file buspirate.c.

◆ NORMAL_TIMEOUT

#define NORMAL_TIMEOUT   10

Definition at line 66 of file buspirate.c.

◆ SHORT_TIMEOUT

#define SHORT_TIMEOUT   1 /* Must be at least 1. */

Definition at line 65 of file buspirate.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
MODE_HIZ 
MODE_JTAG 
MODE_JTAG_OD 

Definition at line 68 of file buspirate.c.

◆ anonymous enum

anonymous enum
Enumerator
FEATURE_LED 
FEATURE_VREG 
FEATURE_TRST 
FEATURE_SRST 
FEATURE_PULLUP 

Definition at line 74 of file buspirate.c.

◆ anonymous enum

anonymous enum
Enumerator
ACTION_DISABLE 
ACTION_ENABLE 

Definition at line 82 of file buspirate.c.

◆ anonymous enum

anonymous enum
Enumerator
SERIAL_NORMAL 
SERIAL_FAST 

Definition at line 87 of file buspirate.c.

◆ anonymous enum

anonymous enum
Enumerator
SPEED_RAW_5_KHZ 
SPEED_RAW_50_KHZ 
SPEED_RAW_100_KHZ 
SPEED_RAW_400_KHZ 

Definition at line 92 of file buspirate.c.

Function Documentation

◆ buspirate_bbio_enable()

static void buspirate_bbio_enable ( int  fd)
static

◆ buspirate_end_state()

static void buspirate_end_state ( tap_state_t  state)
static

◆ buspirate_execute_queue()

◆ buspirate_init()

◆ buspirate_jtag_command()

static unsigned char buspirate_jtag_command ( int  fd,
uint8_t *  cmd,
int  cmdlen 
)
static

◆ buspirate_jtag_get_adcs()

static void buspirate_jtag_get_adcs ( int  fd)
static

Definition at line 1105 of file buspirate.c.

References buspirate_jtag_command(), CMD_READ_ADCS, and LOG_INFO.

Referenced by COMMAND_HANDLER().

◆ buspirate_jtag_reset()

static void buspirate_jtag_reset ( int  fd)
static

Definition at line 1038 of file buspirate.c.

References buspirate_serial_read(), buspirate_serial_write(), and LOG_ERROR.

Referenced by buspirate_quit().

◆ buspirate_jtag_set_feature()

static void buspirate_jtag_set_feature ( int  fd,
char  feat,
char  action 
)
static

Definition at line 1096 of file buspirate.c.

References buspirate_jtag_command(), and CMD_FEATURE.

Referenced by buspirate_set_feature().

◆ buspirate_jtag_set_mode()

static void buspirate_jtag_set_mode ( int  fd,
char  mode 
)
static

Definition at line 1088 of file buspirate.c.

References buspirate_jtag_command(), CMD_PORT_MODE, and mode.

Referenced by buspirate_set_mode().

◆ buspirate_jtag_set_speed()

static void buspirate_jtag_set_speed ( int  fd,
char  speed 
)
static

◆ buspirate_path_move()

static void buspirate_path_move ( unsigned int  num_states,
tap_state_t path 
)
static

◆ buspirate_print_buffer()

static void buspirate_print_buffer ( uint8_t *  buf,
int  size 
)
static

Definition at line 1268 of file buspirate.c.

References BYTES_PER_LINE, LINE_SIZE, LOG_DEBUG, offset, and size.

Referenced by buspirate_serial_read(), and buspirate_serial_write().

◆ buspirate_quit()

static int buspirate_quit ( void  )
static

◆ buspirate_reset()

static int buspirate_reset ( int  trst,
int  srst 
)
static

◆ buspirate_runtest()

static void buspirate_runtest ( unsigned int  num_cycles)
static

◆ buspirate_scan()

static void buspirate_scan ( bool  ir_scan,
enum scan_type  type,
uint8_t *  buffer,
int  scan_size,
struct scan_command command 
)
static

◆ buspirate_serial_close()

static void buspirate_serial_close ( int  fd)
static

Definition at line 1261 of file buspirate.c.

Referenced by buspirate_quit().

◆ buspirate_serial_open()

static int buspirate_serial_open ( char *  port)
static

Definition at line 1159 of file buspirate.c.

References buspirate_port.

Referenced by buspirate_init().

◆ buspirate_serial_read()

◆ buspirate_serial_setspeed()

static int buspirate_serial_setspeed ( int  fd,
char  speed,
cc_t  timeout 
)
static

Definition at line 1169 of file buspirate.c.

References B1000000, and SERIAL_FAST.

Referenced by buspirate_init(), and buspirate_jtag_set_speed().

◆ buspirate_serial_write()

◆ buspirate_set_feature()

static void buspirate_set_feature ( int  fd,
char  feat,
char  action 
)
static

◆ buspirate_set_mode()

static void buspirate_set_mode ( int  fd,
char  mode 
)
static

Definition at line 876 of file buspirate.c.

References buspirate_jtag_set_mode(), buspirate_swd_set_mode(), mode, and swd_mode.

Referenced by buspirate_init(), and buspirate_quit().

◆ buspirate_set_speed()

static void buspirate_set_speed ( int  fd,
char  speed 
)
static

Definition at line 884 of file buspirate.c.

References buspirate_jtag_set_speed(), buspirate_swd_set_speed(), and swd_mode.

Referenced by buspirate_init(), and buspirate_quit().

◆ buspirate_stableclocks()

static void buspirate_stableclocks ( unsigned int  num_cycles)
static

◆ buspirate_state_move()

static void buspirate_state_move ( void  )
static

◆ buspirate_swd_clear_sticky_errors()

static void buspirate_swd_clear_sticky_errors ( void  )
static

◆ buspirate_swd_idle_clocks()

static void buspirate_swd_idle_clocks ( uint32_t  no_bits)
static

◆ buspirate_swd_init()

static int buspirate_swd_init ( void  )
static

Definition at line 1293 of file buspirate.c.

References ERROR_OK, LOG_INFO, and swd_mode.

◆ buspirate_swd_read_reg()

◆ buspirate_swd_run_queue()

static int buspirate_swd_run_queue ( void  )
static

Definition at line 1522 of file buspirate.c.

References buspirate_swd_idle_clocks(), ERROR_OK, LOG_DEBUG, and queued_retval.

◆ buspirate_swd_set_feature()

static void buspirate_swd_set_feature ( int  fd,
char  feat,
char  action 
)
static

◆ buspirate_swd_set_mode()

static void buspirate_swd_set_mode ( int  fd,
char  mode 
)
static

◆ buspirate_swd_set_speed()

static void buspirate_swd_set_speed ( int  fd,
char  speed 
)
static

◆ buspirate_swd_switch_seq()

◆ buspirate_swd_write_header()

static uint8_t buspirate_swd_write_header ( uint8_t  cmd)
static

◆ buspirate_swd_write_reg()

◆ buspirate_tap_append()

◆ buspirate_tap_append_scan()

static void buspirate_tap_append_scan ( int  length,
uint8_t *  buffer,
struct scan_command command 
)
static

◆ buspirate_tap_execute()

◆ buspirate_tap_init()

static void buspirate_tap_init ( void  )
static

Definition at line 700 of file buspirate.c.

References tap_chain_index, and tap_pending_scans_num.

Referenced by buspirate_init(), and buspirate_tap_execute().

◆ buspirate_tap_make_space()

static void buspirate_tap_make_space ( int  scan,
int  bits 
)
static

◆ COMMAND_HANDLER() [1/7]

COMMAND_HANDLER ( buspirate_handle_adc_command  )

Definition at line 352 of file buspirate.c.

References buspirate_fd, buspirate_jtag_get_adcs(), ERROR_OK, and swd_mode.

◆ COMMAND_HANDLER() [2/7]

COMMAND_HANDLER ( buspirate_handle_led_command  )

◆ COMMAND_HANDLER() [3/7]

COMMAND_HANDLER ( buspirate_handle_mode_command  )

◆ COMMAND_HANDLER() [4/7]

COMMAND_HANDLER ( buspirate_handle_port_command  )

Definition at line 453 of file buspirate.c.

◆ COMMAND_HANDLER() [5/7]

COMMAND_HANDLER ( buspirate_handle_pullup_command  )

◆ COMMAND_HANDLER() [6/7]

COMMAND_HANDLER ( buspirate_handle_speed_command  )

◆ COMMAND_HANDLER() [7/7]

COMMAND_HANDLER ( buspirate_handle_vreg_command  )

Definition at line 368 of file buspirate.c.

References buspirate_vreg, CMD_ARGC, CMD_ARGV, ERROR_COMMAND_SYNTAX_ERROR, ERROR_OK, and LOG_ERROR.

◆ read_and_discard_all_data()

static bool read_and_discard_all_data ( const int  fd)
static

Definition at line 230 of file buspirate.c.

References buffer, and LOG_INFO.

Referenced by buspirate_init().

Variable Documentation

◆ buspirate_adapter_driver

struct adapter_driver buspirate_adapter_driver
Initial value:
= {
.name = "buspirate",
.transports = buspirate_transports,
.init = buspirate_init,
.quit = buspirate_quit,
.reset = buspirate_reset,
.jtag_ops = &buspirate_interface,
.swd_ops = &buspirate_swd,
}
static const char *const buspirate_transports[]
Definition: buspirate.c:537
static const struct swd_driver buspirate_swd
Definition: buspirate.c:529
static const struct command_registration buspirate_command_handlers[]
Definition: buspirate.c:518
static struct jtag_interface buspirate_interface
Definition: buspirate.c:539
static int buspirate_quit(void)
Definition: buspirate.c:336
static int buspirate_init(void)
Definition: buspirate.c:275
static int buspirate_reset(int trst, int srst)
Definition: buspirate.c:851

Definition at line 537 of file buspirate.c.

◆ buspirate_baudrate

int buspirate_baudrate = SERIAL_NORMAL
static

Definition at line 106 of file buspirate.c.

Referenced by buspirate_init(), and COMMAND_HANDLER().

◆ buspirate_command_handlers

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

Definition at line 453 of file buspirate.c.

◆ buspirate_fd

◆ buspirate_interface

struct jtag_interface buspirate_interface
static
Initial value:
= {
.execute_queue = buspirate_execute_queue,
}
static int buspirate_execute_queue(struct jtag_command *cmd_queue)
Definition: buspirate.c:154

Definition at line 537 of file buspirate.c.

◆ buspirate_pinmode

int buspirate_pinmode = MODE_JTAG_OD
static

Definition at line 105 of file buspirate.c.

Referenced by buspirate_init(), and COMMAND_HANDLER().

◆ buspirate_port

char* buspirate_port
static

Definition at line 109 of file buspirate.c.

Referenced by buspirate_init(), buspirate_quit(), and buspirate_serial_open().

◆ buspirate_pullup

int buspirate_pullup
static

Definition at line 108 of file buspirate.c.

Referenced by buspirate_init(), and COMMAND_HANDLER().

◆ buspirate_subcommand_handlers

const struct command_registration buspirate_subcommand_handlers[]
static

Definition at line 453 of file buspirate.c.

◆ buspirate_swd

const struct swd_driver buspirate_swd
static
Initial value:
= {
.switch_seq = buspirate_swd_switch_seq,
}
static int buspirate_swd_init(void)
Definition: buspirate.c:1293
static void buspirate_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
Definition: buspirate.c:1471
static int buspirate_swd_run_queue(void)
Definition: buspirate.c:1522
static void buspirate_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
Definition: buspirate.c:1404
static int buspirate_swd_switch_seq(enum swd_special_seq seq)
Definition: buspirate.c:1301

Definition at line 453 of file buspirate.c.

◆ buspirate_transports

const char* const buspirate_transports[] = { "jtag", "swd", NULL }
static

Definition at line 537 of file buspirate.c.

◆ buspirate_vreg

int buspirate_vreg
static

Definition at line 107 of file buspirate.c.

Referenced by buspirate_init(), and COMMAND_HANDLER().

◆ last_tap_state

enum tap_state last_tap_state = TAP_RESET
static

Definition at line 109 of file buspirate.c.

Referenced by buspirate_tap_execute().

◆ queued_retval

int queued_retval
static

◆ swd_features

char swd_features
static

Definition at line 102 of file buspirate.c.

Referenced by buspirate_swd_set_feature().

◆ swd_mode

◆ tap_chain_index

◆ tap_pending_scans

struct pending_scan_result tap_pending_scans[BUSPIRATE_MAX_PENDING_SCANS]
static

Definition at line 686 of file buspirate.c.

Referenced by buspirate_tap_append_scan(), and buspirate_tap_execute().

◆ tap_pending_scans_num

int tap_pending_scans_num
static

◆ tdi_chain

uint8_t tdi_chain[BUSPIRATE_BUFFER_SIZE]
static

Definition at line 685 of file buspirate.c.

Referenced by buspirate_tap_append(), and buspirate_tap_execute().

◆ tms_chain

uint8_t tms_chain[BUSPIRATE_BUFFER_SIZE]
static

Definition at line 684 of file buspirate.c.

Referenced by buspirate_tap_append(), and buspirate_tap_execute().