OpenOCD
adapter.c File Reference

Holds support for configuring debug adapters from TCl scripts. More...

Include dependency graph for adapter.c:

Go to the source code of this file.

Data Structures

struct  gpio_map
 

Macros

#define DEFAULT_CLOCK_SPEED_KHZ   100U
 
#define USB_MAX_LOCATION_LENGTH   16
 

Enumerations

enum  adapter_clk_mode { CLOCK_MODE_UNSELECTED = 0 , CLOCK_MODE_KHZ , CLOCK_MODE_RCLK }
 

Functions

int adapter_config_khz (unsigned int khz)
 Attempt to configure the adapter for the specified kHz. More...
 
int adapter_config_rclk (unsigned int fallback_speed_khz)
 Attempt to enable RTCK/RCLK. More...
 
static void adapter_driver_gpios_init (void)
 
const char * adapter_get_required_serial (void)
 Retrieves the serial number set with command 'adapter serial'. More...
 
int adapter_get_speed (int *speed)
 
unsigned int adapter_get_speed_khz (void)
 Retrieves the clock speed of the adapter in kHz. More...
 
int adapter_get_speed_readable (int *khz)
 Given a speed setting, use the interface speed_div callback to adjust the setting. More...
 
const struct adapter_gpio_configadapter_gpio_get_config (void)
 Retrieves gpio configuration set with command "adapter gpio <signal_name>". More...
 
const char * adapter_gpio_get_name (enum adapter_gpio_config_index idx)
 Retrieves gpio name. More...
 
int adapter_init (struct command_context *cmd_ctx)
 Do low-level setup like initializing registers, output signals, and clocking. More...
 
static int adapter_khz_to_speed (unsigned int khz, int *speed)
 
int adapter_quit (void)
 Shutdown the debug adapter upon program exit. More...
 
static int adapter_rclk_to_speed (unsigned int fallback_speed_khz, int *speed)
 
int adapter_register_commands (struct command_context *ctx)
 Register the commands which deal with arbitrary debug adapter drivers. More...
 
static int adapter_set_speed (int speed)
 
const char * adapter_usb_get_location (void)
 
bool adapter_usb_location_equal (uint8_t dev_bus, uint8_t *port_path, size_t path_len)
 
 COMMAND_HANDLER (adapter_gpio_config_handler)
 
 COMMAND_HANDLER (adapter_transports_command)
 
 COMMAND_HANDLER (handle_adapter_driver_command)
 
 COMMAND_HANDLER (handle_adapter_list_command)
 
 COMMAND_HANDLER (handle_adapter_name)
 
 COMMAND_HANDLER (handle_adapter_reset_de_assert)
 
 COMMAND_HANDLER (handle_adapter_serial_command)
 
 COMMAND_HANDLER (handle_adapter_speed_command)
 
 COMMAND_HANDLER (handle_adapter_srst_delay_command)
 
 COMMAND_HANDLER (handle_adapter_srst_pulse_width_command)
 
 COMMAND_HANDLER (handle_reset_config_command)
 
 COMMAND_HANDLER (helper_adapter_gpio_print_all_configs)
 
static COMMAND_HELPER (helper_adapter_gpio_print_config, enum adapter_gpio_config_index gpio_idx)
 
static int get_gpio_index (const char *signal_name)
 
bool is_adapter_initialized (void)
 
static void sync_adapter_reset_with_gpios (void)
 

Variables

static const struct command_registration adapter_command_handlers []
 
struct {
   bool   adapter_initialized
 
   enum adapter_clk_mode   clock_mode
 
   struct adapter_gpio_config   gpios [ADAPTER_GPIO_IDX_NUM]
 
   bool   gpios_initialized
 
   int   rclk_fallback_speed_khz
 
   char *   serial
 
   int   speed_khz
 
   char *   usb_location
 
adapter_config
 Adapter configuration. More...
 
struct adapter_driveradapter_driver
 
static const struct command_registration adapter_srst_command_handlers []
 
static const struct command_registration adapter_usb_command_handlers []
 
static const struct gpio_map gpio_map [ADAPTER_GPIO_IDX_NUM]
 
static const struct command_registration interface_command_handlers []
 
const char *const jtag_only [] = { "jtag", NULL }
 

Detailed Description

Holds support for configuring debug adapters from TCl scripts.

Definition in file adapter.c.

Macro Definition Documentation

◆ DEFAULT_CLOCK_SPEED_KHZ

#define DEFAULT_CLOCK_SPEED_KHZ   100U

Definition at line 35 of file adapter.c.

◆ USB_MAX_LOCATION_LENGTH

#define USB_MAX_LOCATION_LENGTH   16

Definition at line 310 of file adapter.c.

Enumeration Type Documentation

◆ adapter_clk_mode

Enumerator
CLOCK_MODE_UNSELECTED 
CLOCK_MODE_KHZ 
CLOCK_MODE_RCLK 

Definition at line 29 of file adapter.c.

Function Documentation

◆ adapter_config_khz()

int adapter_config_khz ( unsigned int  khz)

Attempt to configure the adapter for the specified kHz.

Definition at line 248 of file adapter.c.

References adapter_config, adapter_khz_to_speed(), adapter_set_speed(), CLOCK_MODE_KHZ, ERROR_OK, and LOG_DEBUG.

Referenced by adapter_init(), and COMMAND_HANDLER().

◆ adapter_config_rclk()

int adapter_config_rclk ( unsigned int  fallback_speed_khz)

Attempt to enable RTCK/RCLK.

If that fails, fallback to the specified frequency.

Definition at line 257 of file adapter.c.

References adapter_config, adapter_rclk_to_speed(), adapter_set_speed(), CLOCK_MODE_RCLK, ERROR_OK, and LOG_DEBUG.

Referenced by COMMAND_HANDLER().

◆ adapter_driver_gpios_init()

◆ adapter_get_required_serial()

const char* adapter_get_required_serial ( void  )

Retrieves the serial number set with command 'adapter serial'.

Definition at line 298 of file adapter.c.

References adapter_config.

Referenced by cmsis_dap_open(), ft232r_init(), ftdi_initialize(), jlink_init(), jtag_libusb_open(), presto_jtag_init(), stlink_open(), usb_connect(), vsllink_check_usb_strings(), and xds110_show_info().

◆ adapter_get_speed()

int adapter_get_speed ( int *  speed)

◆ adapter_get_speed_khz()

◆ adapter_get_speed_readable()

int adapter_get_speed_readable ( int *  speed)

Given a speed setting, use the interface speed_div callback to adjust the setting.

Parameters
speedThe speed setting to convert back to readable kHz.
Returns
ERROR_OK if the interface has not been initialized or on success; otherwise, the error code produced by the speed_div callback.

Definition at line 283 of file adapter.c.

References adapter_get_speed(), ERROR_FAIL, ERROR_OK, is_adapter_initialized(), LOG_ERROR, and adapter_driver::speed_div.

Referenced by adapter_init(), and COMMAND_HANDLER().

◆ adapter_gpio_get_config()

const struct adapter_gpio_config* adapter_gpio_get_config ( void  )

Retrieves gpio configuration set with command "adapter gpio <signal_name>".

Definition at line 1221 of file adapter.c.

References adapter_config.

Referenced by am335xgpio_init(), bcm2835gpio_init(), and linuxgpiod_init().

◆ adapter_gpio_get_name()

const char* adapter_gpio_get_name ( enum adapter_gpio_config_index  idx)

Retrieves gpio name.

Definition at line 1215 of file adapter.c.

References gpio_map::name.

Referenced by helper_get_line(), and initialize_gpio().

◆ adapter_init()

◆ adapter_khz_to_speed()

static int adapter_khz_to_speed ( unsigned int  khz,
int *  speed 
)
static

◆ adapter_quit()

int adapter_quit ( void  )

Shutdown the debug adapter upon program exit.

Definition at line 185 of file adapter.c.

References adapter_config, ERROR_OK, is_adapter_initialized(), jtag_all_taps(), jtag_tap_free(), LOG_ERROR, jtag_tap::next_tap, and adapter_driver::quit.

Referenced by openocd_main().

◆ adapter_rclk_to_speed()

static int adapter_rclk_to_speed ( unsigned int  fallback_speed_khz,
int *  speed 
)
static

Definition at line 231 of file adapter.c.

References adapter_khz_to_speed(), ERROR_OK, and LOG_DEBUG.

Referenced by adapter_config_rclk(), and adapter_get_speed().

◆ adapter_register_commands()

int adapter_register_commands ( struct command_context ctx)

Register the commands which deal with arbitrary debug adapter drivers.

Register the adapter's commands.

Todo:
Remove internal assumptions that all debug adapters use JTAG for transport. Various types and data structures are not named generically.

Definition at line 1210 of file adapter.c.

References interface_command_handlers, NULL, and register_commands().

Referenced by setup_command_handler().

◆ adapter_set_speed()

static int adapter_set_speed ( int  speed)
static

Definition at line 241 of file adapter.c.

References ERROR_OK, is_adapter_initialized(), and adapter_driver::speed.

Referenced by adapter_config_khz(), and adapter_config_rclk().

◆ adapter_usb_get_location()

const char* adapter_usb_get_location ( void  )
Returns
USB location string set with command 'adapter usb location'

Definition at line 324 of file adapter.c.

References adapter_config.

Referenced by adapter_usb_location_equal(), ftdi_initialize(), jlink_open_device(), and jtag_libusb_open().

◆ adapter_usb_location_equal()

bool adapter_usb_location_equal ( uint8_t  dev_bus,
uint8_t *  port_path,
size_t  path_len 
)
Returns
true if USB location string is "<dev_bus>-<port_path[0]>[.<port_path[1]>[...]]"

Definition at line 329 of file adapter.c.

References adapter_usb_get_location(), LOG_WARNING, NULL, strndup(), strnlen(), and USB_MAX_LOCATION_LENGTH.

Referenced by jlink_usb_location_equal().

◆ COMMAND_HANDLER() [1/12]

COMMAND_HANDLER ( adapter_gpio_config_handler  )

Definition at line 923 of file adapter.c.

◆ COMMAND_HANDLER() [2/12]

COMMAND_HANDLER ( adapter_transports_command  )

Definition at line 392 of file adapter.c.

References allow_transports(), CALL_COMMAND_HANDLER, CMD_CTX, and ERROR_OK.

◆ COMMAND_HANDLER() [3/12]

◆ COMMAND_HANDLER() [4/12]

COMMAND_HANDLER ( handle_adapter_list_command  )

◆ COMMAND_HANDLER() [5/12]

COMMAND_HANDLER ( handle_adapter_name  )

◆ COMMAND_HANDLER() [6/12]

◆ COMMAND_HANDLER() [7/12]

COMMAND_HANDLER ( handle_adapter_serial_command  )

Definition at line 738 of file adapter.c.

References adapter_config, CMD_ARGC, CMD_ARGV, ERROR_COMMAND_SYNTAX_ERROR, and ERROR_OK.

◆ COMMAND_HANDLER() [8/12]

COMMAND_HANDLER ( handle_adapter_speed_command  )

◆ COMMAND_HANDLER() [9/12]

COMMAND_HANDLER ( handle_adapter_srst_delay_command  )

◆ COMMAND_HANDLER() [10/12]

COMMAND_HANDLER ( handle_adapter_srst_pulse_width_command  )

◆ COMMAND_HANDLER() [11/12]

◆ COMMAND_HANDLER() [12/12]

COMMAND_HANDLER ( helper_adapter_gpio_print_all_configs  )

Definition at line 916 of file adapter.c.

References ADAPTER_GPIO_IDX_NUM, CALL_COMMAND_HANDLER, and ERROR_OK.

◆ COMMAND_HELPER()

◆ get_gpio_index()

static int get_gpio_index ( const char *  signal_name)
static

Definition at line 834 of file adapter.c.

References ADAPTER_GPIO_IDX_NUM, and name.

◆ is_adapter_initialized()

bool is_adapter_initialized ( void  )
Returns
true if adapter has been initialized

Definition at line 69 of file adapter.c.

References adapter_config.

Referenced by adapter_get_speed_readable(), adapter_init(), adapter_khz_to_speed(), adapter_quit(), adapter_set_speed(), default_interface_jtag_execute_queue(), and jtag_power_dropout().

◆ sync_adapter_reset_with_gpios()

Variable Documentation

◆ adapter_command_handlers

const struct command_registration adapter_command_handlers[]
static

Definition at line 923 of file adapter.c.

◆ 

◆ adapter_driver

Definition at line 26 of file adapter.c.

Referenced by swd_select().

◆ adapter_initialized

bool adapter_initialized

Definition at line 41 of file adapter.c.

◆ adapter_srst_command_handlers

const struct command_registration adapter_srst_command_handlers[]
static
Initial value:
= {
{
.name = "delay",
.handler = handle_adapter_srst_delay_command,
.mode = COMMAND_ANY,
.help = "delay after deasserting SRST in ms",
.usage = "[milliseconds]",
},
{
.name = "pulse_width",
.handler = handle_adapter_srst_pulse_width_command,
.mode = COMMAND_ANY,
.help = "SRST assertion pulse width in ms",
.usage = "[milliseconds]",
},
}
#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

Definition at line 923 of file adapter.c.

◆ adapter_usb_command_handlers

const struct command_registration adapter_usb_command_handlers[]
static
Initial value:

Definition at line 923 of file adapter.c.

◆ clock_mode

enum adapter_clk_mode clock_mode

Definition at line 43 of file adapter.c.

◆ gpio_map

const struct gpio_map gpio_map[ADAPTER_GPIO_IDX_NUM]
static
Initial value:
= {
[ADAPTER_GPIO_IDX_TDO] = { "tdo", ADAPTER_GPIO_DIRECTION_INPUT, false, true, },
[ADAPTER_GPIO_IDX_SWDIO_DIR] = { "swdio_dir", ADAPTER_GPIO_DIRECTION_OUTPUT, true, false, },
}
@ ADAPTER_GPIO_IDX_LED
Definition: adapter.h:54
@ ADAPTER_GPIO_IDX_SWCLK
Definition: adapter.h:52
@ ADAPTER_GPIO_IDX_SWDIO_DIR
Definition: adapter.h:51
@ ADAPTER_GPIO_IDX_SRST
Definition: adapter.h:53
@ ADAPTER_GPIO_IDX_TRST
Definition: adapter.h:49
@ ADAPTER_GPIO_IDX_TDI
Definition: adapter.h:46
@ ADAPTER_GPIO_IDX_TMS
Definition: adapter.h:47
@ ADAPTER_GPIO_IDX_TCK
Definition: adapter.h:48
@ ADAPTER_GPIO_IDX_TDO
Definition: adapter.h:45
@ ADAPTER_GPIO_IDX_SWDIO
Definition: adapter.h:50
@ ADAPTER_GPIO_DIRECTION_OUTPUT
Definition: adapter.h:25
@ ADAPTER_GPIO_DIRECTION_INPUT
Definition: adapter.h:24
@ ADAPTER_GPIO_DIRECTION_BIDIRECTIONAL
Definition: adapter.h:26

◆ gpios

Definition at line 46 of file adapter.c.

◆ gpios_initialized

bool gpios_initialized

Definition at line 48 of file adapter.c.

◆ interface_command_handlers

const struct command_registration interface_command_handlers[]
static
Initial value:
= {
{
.name = "adapter",
.mode = COMMAND_ANY,
.help = "adapter command group",
.usage = "",
},
{
.name = "reset_config",
.handler = handle_reset_config_command,
.mode = COMMAND_ANY,
.help = "configure adapter reset behavior",
.usage = "[none|trst_only|srst_only|trst_and_srst] "
"[srst_pulls_trst|trst_pulls_srst|combined|separate] "
"[srst_gates_jtag|srst_nogate] "
"[trst_push_pull|trst_open_drain] "
"[srst_push_pull|srst_open_drain] "
"[connect_deassert_srst|connect_assert_srst]",
},
}
static const struct command_registration adapter_command_handlers[]
Definition: adapter.c:1090
const char * name
Definition: command.h:235

Definition at line 923 of file adapter.c.

Referenced by adapter_register_commands().

◆ jtag_only

const char* const jtag_only[] = { "jtag", NULL }

Definition at line 27 of file adapter.c.

◆ rclk_fallback_speed_khz

int rclk_fallback_speed_khz

Definition at line 46 of file adapter.c.

◆ serial

◆ speed_khz

int speed_khz

Definition at line 45 of file adapter.c.

◆ usb_location

char* usb_location

Definition at line 42 of file adapter.c.