adapter: switch from struct jtag_interface to adapter_driver

To reorganize the adapters code, introduce an adapter_driver
struct that contains all the adapter generic part, while
keeping in two separate struct the specific API jtag_ops and
swd_ops.
Move the allocation of *adapter_driver from the JTAG-specific
file core.c to the more adapter-specific file adapter.c
While splitting the old jtag_interface for every driver, put
the fields in the same order as in the struct declaration so
we keep a consistent code across all the drivers.

While other transport specific API could/would be added as
separate ops, nothing is done here for HLA.

Change-Id: I2d60f97ac514c0dd2d93a6ec9be66fd9d388dad5
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4900
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
This commit is contained in:
Antonio Borneo 2019-01-22 16:31:18 +01:00 committed by Tomas Vanek
parent 7268ff22c3
commit efd1d64222
39 changed files with 441 additions and 268 deletions

View File

@ -46,7 +46,7 @@
* Holds support for configuring debug adapters from TCl scripts.
*/
extern struct jtag_interface *jtag_interface;
struct adapter_driver *adapter_driver;
const char * const jtag_only[] = { "jtag", NULL };
static int jim_adapter_name(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
@ -61,7 +61,7 @@ static int jim_adapter_name(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
Jim_WrongNumArgs(goi.interp, 1, goi.argv-1, "(no params)");
return JIM_ERR;
}
const char *name = jtag_interface ? jtag_interface->name : NULL;
const char *name = adapter_driver ? adapter_driver->name : NULL;
Jim_SetResultString(goi.interp, name ? : "undefined", -1);
return JIM_OK;
}
@ -91,8 +91,8 @@ COMMAND_HANDLER(handle_interface_list_command)
return ERROR_COMMAND_SYNTAX_ERROR;
command_print(CMD, "The following debug interfaces are available:");
for (unsigned i = 0; NULL != jtag_interfaces[i]; i++) {
const char *name = jtag_interfaces[i]->name;
for (unsigned i = 0; NULL != adapter_drivers[i]; i++) {
const char *name = adapter_drivers[i]->name;
command_print(CMD, "%u: %s", i + 1, name);
}
@ -104,7 +104,7 @@ COMMAND_HANDLER(handle_interface_command)
int retval;
/* check whether the interface is already configured */
if (jtag_interface) {
if (adapter_driver) {
LOG_WARNING("Interface already configured, ignoring");
return ERROR_OK;
}
@ -113,20 +113,20 @@ COMMAND_HANDLER(handle_interface_command)
if (CMD_ARGC != 1 || CMD_ARGV[0][0] == '\0')
return ERROR_COMMAND_SYNTAX_ERROR;
for (unsigned i = 0; NULL != jtag_interfaces[i]; i++) {
if (strcmp(CMD_ARGV[0], jtag_interfaces[i]->name) != 0)
for (unsigned i = 0; NULL != adapter_drivers[i]; i++) {
if (strcmp(CMD_ARGV[0], adapter_drivers[i]->name) != 0)
continue;
if (NULL != jtag_interfaces[i]->commands) {
if (NULL != adapter_drivers[i]->commands) {
retval = register_commands(CMD_CTX, NULL,
jtag_interfaces[i]->commands);
adapter_drivers[i]->commands);
if (ERROR_OK != retval)
return retval;
}
jtag_interface = jtag_interfaces[i];
adapter_driver = adapter_drivers[i];
return allow_transports(CMD_CTX, jtag_interface->transports);
return allow_transports(CMD_CTX, adapter_driver->transports);
}
/* no valid interface was found (i.e. the configuration option,

View File

@ -518,14 +518,20 @@ static const struct command_registration aice_command_handlers[] = {
/***************************************************************************/
/* End of Command handlers */
struct jtag_interface aice_interface = {
static struct jtag_interface aice_interface = {
.execute_queue = aice_execute_queue,
};
struct adapter_driver aice_adapter_driver = {
.name = "aice",
.commands = aice_command_handlers,
.transports = aice_transports,
.commands = aice_command_handlers,
.init = aice_init,
.quit = aice_quit,
.execute_queue = aice_execute_queue,
.speed = aice_speed, /* set interface speed */
.speed_div = aice_speed_div, /* return readable value */
.khz = aice_khz, /* convert khz to interface speed value */
.speed_div = aice_speed_div, /* return readable value */
.jtag_ops = &aice_interface,
};

View File

@ -126,10 +126,10 @@ static int rclk_fallback_speed_khz;
static enum {CLOCK_MODE_UNSELECTED, CLOCK_MODE_KHZ, CLOCK_MODE_RCLK} clock_mode;
static int jtag_speed;
static struct jtag_interface *jtag;
/* FIXME: change name to this variable, it is not anymore JTAG only */
static struct adapter_driver *jtag;
/* configuration */
struct jtag_interface *jtag_interface;
extern struct adapter_driver *adapter_driver;
void jtag_set_flush_queue_sleep(int ms)
{
@ -503,7 +503,7 @@ int jtag_add_tms_seq(unsigned nbits, const uint8_t *seq, enum tap_state state)
{
int retval;
if (!(jtag->supported & DEBUG_CAP_TMS_SEQ))
if (!(jtag->jtag_ops->supported & DEBUG_CAP_TMS_SEQ))
return ERROR_JTAG_NOT_IMPLEMENTED;
jtag_checks();
@ -946,11 +946,11 @@ int default_interface_jtag_execute_queue(void)
* The fix can be applied immediately after next release (v0.11.0 ?)
*/
LOG_ERROR("JTAG API jtag_execute_queue() called on non JTAG interface");
if (!jtag->execute_queue)
if (!jtag->jtag_ops || !jtag->jtag_ops->execute_queue)
return ERROR_OK;
}
int result = jtag->execute_queue();
int result = jtag->jtag_ops->execute_queue();
#if !BUILD_ZY1000
/* Only build this if we use a regular driver with a command queue.
@ -1518,7 +1518,7 @@ int adapter_init(struct command_context *cmd_ctx)
if (jtag)
return ERROR_OK;
if (!jtag_interface) {
if (!adapter_driver) {
/* nothing was previously specified by "interface" command */
LOG_ERROR("Debug Adapter has to be specified, "
"see \"interface\" command");
@ -1526,10 +1526,10 @@ int adapter_init(struct command_context *cmd_ctx)
}
int retval;
retval = jtag_interface->init();
retval = adapter_driver->init();
if (retval != ERROR_OK)
return retval;
jtag = jtag_interface;
jtag = adapter_driver;
if (jtag->speed == NULL) {
LOG_INFO("This adapter doesn't support configurable speed");

View File

@ -584,7 +584,11 @@ static const struct command_registration amtjtagaccel_command_handlers[] = {
COMMAND_REGISTRATION_DONE
};
struct jtag_interface amt_jtagaccel_interface = {
static struct jtag_interface amt_jtagaccel_interface = {
.execute_queue = amt_jtagaccel_execute_queue,
};
struct adapter_driver amt_jtagaccel_adapter_driver = {
.name = "amt_jtagaccel",
.transports = jtag_only,
.commands = amtjtagaccel_command_handlers,
@ -592,5 +596,6 @@ struct jtag_interface amt_jtagaccel_interface = {
.init = amt_jtagaccel_init,
.quit = amt_jtagaccel_quit,
.speed = amt_jtagaccel_speed,
.execute_queue = amt_jtagaccel_execute_queue,
.jtag_ops = &amt_jtagaccel_interface,
};

View File

@ -495,16 +495,22 @@ static const struct command_registration armjtagew_command_handlers[] = {
COMMAND_REGISTRATION_DONE
};
struct jtag_interface armjtagew_interface = {
.name = "arm-jtag-ew",
.commands = armjtagew_command_handlers,
.transports = jtag_only,
static struct jtag_interface armjtagew_interface = {
.execute_queue = armjtagew_execute_queue,
.speed = armjtagew_speed,
.speed_div = armjtagew_speed_div,
.khz = armjtagew_khz,
};
struct adapter_driver armjtagew_adapter_driver = {
.name = "arm-jtag-ew",
.transports = jtag_only,
.commands = armjtagew_command_handlers,
.init = armjtagew_init,
.quit = armjtagew_quit,
.speed = armjtagew_speed,
.khz = armjtagew_khz,
.speed_div = armjtagew_speed_div,
.jtag_ops = &armjtagew_interface,
};
/**************************************************************************

View File

@ -187,14 +187,20 @@ static const struct command_registration at91rm9200_command_handlers[] = {
COMMAND_REGISTRATION_DONE
};
struct jtag_interface at91rm9200_interface = {
.name = "at91rm9200",
static struct jtag_interface at91rm9200_interface = {
.execute_queue = bitbang_execute_queue,
};
struct adapter_driver at91rm9200_adapter_driver = {
.name = "at91rm9200",
.transports = jtag_only,
.commands = at91rm9200_command_handlers,
.init = at91rm9200_init,
.quit = at91rm9200_quit,
.reset = at91rm9200_reset,
.jtag_ops = &at91rm9200_interface,
};
static int at91rm9200_init(void)

View File

@ -405,19 +405,25 @@ static const struct command_registration bcm2835gpio_command_handlers[] = {
static const char * const bcm2835_transports[] = { "jtag", "swd", NULL };
struct jtag_interface bcm2835gpio_interface = {
.name = "bcm2835gpio",
static struct jtag_interface bcm2835gpio_interface = {
.supported = DEBUG_CAP_TMS_SEQ,
.execute_queue = bitbang_execute_queue,
};
struct adapter_driver bcm2835gpio_adapter_driver = {
.name = "bcm2835gpio",
.transports = bcm2835_transports,
.swd = &bitbang_swd,
.speed = bcm2835gpio_speed,
.khz = bcm2835gpio_khz,
.speed_div = bcm2835gpio_speed_div,
.commands = bcm2835gpio_command_handlers,
.init = bcm2835gpio_init,
.quit = bcm2835gpio_quit,
.reset = bcm2835gpio_reset,
.speed = bcm2835gpio_speed,
.khz = bcm2835gpio_khz,
.speed_div = bcm2835gpio_speed_div,
.jtag_ops = &bcm2835gpio_interface,
.swd_ops = &bitbang_swd,
};
static bool bcm2835gpio_jtag_mode_possible(void)

View File

@ -536,15 +536,21 @@ static const struct swd_driver buspirate_swd = {
static const char * const buspirate_transports[] = { "jtag", "swd", NULL };
struct jtag_interface buspirate_interface = {
.name = "buspirate",
static struct jtag_interface buspirate_interface = {
.execute_queue = buspirate_execute_queue,
.commands = buspirate_command_handlers,
};
struct adapter_driver buspirate_adapter_driver = {
.name = "buspirate",
.transports = buspirate_transports,
.swd = &buspirate_swd,
.commands = buspirate_command_handlers,
.init = buspirate_init,
.quit = buspirate_quit,
.reset = buspirate_reset,
.jtag_ops = &buspirate_interface,
.swd_ops = &buspirate_swd,
};
/*************** jtag execute commands **********************/

View File

@ -1786,18 +1786,23 @@ static const struct swd_driver cmsis_dap_swd_driver = {
static const char * const cmsis_dap_transport[] = { "swd", "jtag", NULL };
struct jtag_interface cmsis_dap_interface = {
.name = "cmsis-dap",
static struct jtag_interface cmsis_dap_interface = {
.supported = DEBUG_CAP_TMS_SEQ,
.commands = cmsis_dap_command_handlers,
.swd = &cmsis_dap_swd_driver,
.transports = cmsis_dap_transport,
.execute_queue = cmsis_dap_execute_queue,
.speed = cmsis_dap_speed,
.speed_div = cmsis_dap_speed_div,
.khz = cmsis_dap_khz,
};
struct adapter_driver cmsis_dap_adapter_driver = {
.name = "cmsis-dap",
.transports = cmsis_dap_transport,
.commands = cmsis_dap_command_handlers,
.init = cmsis_dap_init,
.quit = cmsis_dap_quit,
.reset = cmsis_dap_reset,
.speed = cmsis_dap_speed,
.khz = cmsis_dap_khz,
.speed_div = cmsis_dap_speed_div,
.jtag_ops = &cmsis_dap_interface,
.swd_ops = &cmsis_dap_swd_driver,
};

View File

@ -144,20 +144,22 @@ static const struct command_registration dummy_command_handlers[] = {
/* The dummy driver is used to easily check the code path
* where the target is unresponsive.
*/
struct jtag_interface dummy_interface = {
.name = "dummy",
static struct jtag_interface dummy_interface = {
.supported = DEBUG_CAP_TMS_SEQ,
.execute_queue = &bitbang_execute_queue,
};
.supported = DEBUG_CAP_TMS_SEQ,
.commands = dummy_command_handlers,
.transports = jtag_only,
struct adapter_driver dummy_adapter_driver = {
.name = "dummy",
.transports = jtag_only,
.commands = dummy_command_handlers,
.execute_queue = &bitbang_execute_queue,
.init = &dummy_init,
.quit = &dummy_quit,
.reset = &dummy_reset,
.speed = &dummy_speed,
.khz = &dummy_khz,
.speed_div = &dummy_speed_div,
.speed = &dummy_speed,
.khz = &dummy_khz,
.speed_div = &dummy_speed_div,
.init = &dummy_init,
.quit = &dummy_quit,
.reset = &dummy_reset,
};
.jtag_ops = &dummy_interface,
};

View File

@ -50,16 +50,20 @@ static int ep93xx_quit(void);
struct timespec ep93xx_zzzz;
struct jtag_interface ep93xx_interface = {
.name = "ep93xx",
static struct jtag_interface ep93xx_interface = {
.supported = DEBUG_CAP_TMS_SEQ,
.execute_queue = bitbang_execute_queue,
};
struct adapter_driver ep93xx_adapter_driver = {
.name = "ep93xx",
.transports = jtag_only,
.init = ep93xx_init,
.quit = ep93xx_quit,
.reset = ep93xx_reset,
.jtag_ops = &ep93xx_interface,
};
static struct bitbang_interface ep93xx_bitbang = {

View File

@ -914,17 +914,21 @@ static int syncbb_execute_queue(void)
return retval;
}
struct jtag_interface ft232r_interface = {
.name = "ft232r",
.commands = ft232r_command_handlers,
.transports = jtag_only,
static struct jtag_interface ft232r_interface = {
.supported = DEBUG_CAP_TMS_SEQ,
.execute_queue = syncbb_execute_queue,
};
struct adapter_driver ft232r_adapter_driver = {
.name = "ft232r",
.transports = jtag_only,
.commands = ft232r_command_handlers,
.speed = ft232r_speed,
.init = ft232r_init,
.quit = ft232r_quit,
.speed_div = ft232r_speed_div,
.speed = ft232r_speed,
.khz = ft232r_khz,
.speed_div = ft232r_speed_div,
.jtag_ops = &ft232r_interface,
};

View File

@ -1231,18 +1231,23 @@ static const struct swd_driver ftdi_swd = {
static const char * const ftdi_transports[] = { "jtag", "swd", NULL };
struct jtag_interface ftdi_interface = {
.name = "ftdi",
static struct jtag_interface ftdi_interface = {
.supported = DEBUG_CAP_TMS_SEQ,
.commands = ftdi_command_handlers,
.execute_queue = ftdi_execute_queue,
};
struct adapter_driver ftdi_adapter_driver = {
.name = "ftdi",
.transports = ftdi_transports,
.swd = &ftdi_swd,
.commands = ftdi_command_handlers,
.init = ftdi_initialize,
.quit = ftdi_quit,
.reset = ftdi_reset,
.speed = ftdi_speed,
.speed_div = ftdi_speed_div,
.khz = ftdi_khz,
.execute_queue = ftdi_execute_queue,
.speed_div = ftdi_speed_div,
.jtag_ops = &ftdi_interface,
.swd_ops = &ftdi_swd,
};

View File

@ -521,12 +521,17 @@ static const struct command_registration gw16012_command_handlers[] = {
COMMAND_REGISTRATION_DONE
};
struct jtag_interface gw16012_interface = {
static struct jtag_interface gw16012_interface = {
.execute_queue = gw16012_execute_queue,
};
struct adapter_driver gw16012_adapter_driver = {
.name = "gw16012",
.transports = jtag_only,
.commands = gw16012_command_handlers,
.init = gw16012_init,
.quit = gw16012_quit,
.execute_queue = gw16012_execute_queue,
.jtag_ops = &gw16012_interface,
};

View File

@ -427,19 +427,25 @@ static const struct command_registration imx_gpio_command_handlers[] = {
static const char * const imx_gpio_transports[] = { "jtag", "swd", NULL };
struct jtag_interface imx_gpio_interface = {
.name = "imx_gpio",
static struct jtag_interface imx_gpio_interface = {
.supported = DEBUG_CAP_TMS_SEQ,
.execute_queue = bitbang_execute_queue,
};
struct adapter_driver imx_gpio_adapter_driver = {
.name = "imx_gpio",
.transports = imx_gpio_transports,
.swd = &bitbang_swd,
.speed = imx_gpio_speed,
.khz = imx_gpio_khz,
.speed_div = imx_gpio_speed_div,
.commands = imx_gpio_command_handlers,
.init = imx_gpio_init,
.quit = imx_gpio_quit,
.reset = imx_gpio_reset,
.speed = imx_gpio_speed,
.khz = imx_gpio_khz,
.speed_div = imx_gpio_speed_div,
.jtag_ops = &imx_gpio_interface,
.swd_ops = &bitbang_swd,
};
static bool imx_gpio_jtag_mode_possible(void)

View File

@ -2267,18 +2267,24 @@ static const struct swd_driver jlink_swd = {
static const char * const jlink_transports[] = { "jtag", "swd", NULL };
struct jtag_interface jlink_interface = {
.name = "jlink",
.commands = jlink_command_handlers,
.transports = jlink_transports,
.swd = &jlink_swd,
static struct jtag_interface jlink_interface = {
.execute_queue = &jlink_execute_queue,
.speed = &jlink_speed,
.speed_div = &jlink_speed_div,
.khz = &jlink_khz,
};
struct adapter_driver jlink_adapter_driver = {
.name = "jlink",
.transports = jlink_transports,
.commands = jlink_command_handlers,
.init = &jlink_init,
.quit = &jlink_quit,
.reset = &jlink_reset_safe,
.speed = &jlink_speed,
.khz = &jlink_khz,
.speed_div = &jlink_speed_div,
.config_trace = &config_trace,
.poll_trace = &poll_trace,
.jtag_ops = &jlink_interface,
.swd_ops = &jlink_swd,
};

View File

@ -627,13 +627,18 @@ static const struct command_registration jtag_vpi_command_handlers[] = {
COMMAND_REGISTRATION_DONE
};
struct jtag_interface jtag_vpi_interface = {
.name = "jtag_vpi",
static struct jtag_interface jtag_vpi_interface = {
.supported = DEBUG_CAP_TMS_SEQ,
.commands = jtag_vpi_command_handlers,
.execute_queue = jtag_vpi_execute_queue,
};
struct adapter_driver jtag_vpi_adapter_driver = {
.name = "jtag_vpi",
.transports = jtag_only,
.commands = jtag_vpi_command_handlers,
.init = jtag_vpi_init,
.quit = jtag_vpi_quit,
.execute_queue = jtag_vpi_execute_queue,
.jtag_ops = &jtag_vpi_interface,
};

View File

@ -935,12 +935,14 @@ static const struct swd_driver kitprog_swd = {
static const char * const kitprog_transports[] = { "swd", NULL };
struct jtag_interface kitprog_interface = {
struct adapter_driver kitprog_adapter_driver = {
.name = "kitprog",
.commands = kitprog_command_handlers,
.transports = kitprog_transports,
.swd = &kitprog_swd,
.commands = kitprog_command_handlers,
.init = kitprog_init,
.quit = kitprog_quit,
.reset = kitprog_reset,
.swd_ops = &kitprog_swd,
};

View File

@ -234,13 +234,19 @@ static const struct command_registration opendous_command_handlers[] = {
COMMAND_REGISTRATION_DONE
};
struct jtag_interface opendous_interface = {
static struct jtag_interface opendous_interface = {
.execute_queue = opendous_execute_queue,
};
struct adapter_driver opendous_adapter_driver = {
.name = "opendous",
.transports = jtag_only,
.commands = opendous_command_handlers,
.execute_queue = opendous_execute_queue,
.init = opendous_init,
.quit = opendous_quit,
.jtag_ops = &opendous_interface,
};
static int opendous_execute_queue(void)

View File

@ -892,17 +892,20 @@ static const struct command_registration openjtag_command_handlers[] = {
COMMAND_REGISTRATION_DONE
};
struct jtag_interface openjtag_interface = {
static struct jtag_interface openjtag_interface = {
.execute_queue = openjtag_execute_queue,
};
struct adapter_driver openjtag_adapter_driver = {
.name = "openjtag",
.transports = jtag_only,
.commands = openjtag_command_handlers,
.execute_queue = openjtag_execute_queue,
.speed = openjtag_speed,
.speed_div = openjtag_speed_div,
.khz = openjtag_khz,
.init = openjtag_init,
.quit = openjtag_quit,
.speed = openjtag_speed,
.khz = openjtag_khz,
.speed_div = openjtag_speed_div,
.jtag_ops = &openjtag_interface,
};

View File

@ -688,12 +688,16 @@ static int osbdm_init(void)
return ERROR_OK;
}
struct jtag_interface osbdm_interface = {
.name = "osbdm",
.transports = jtag_only,
static struct jtag_interface osbdm_interface = {
.execute_queue = osbdm_execute_queue,
};
struct adapter_driver osbdm_adapter_driver = {
.name = "osbdm",
.transports = jtag_only,
.init = osbdm_init,
.quit = osbdm_quit
.quit = osbdm_quit,
.jtag_ops = &osbdm_interface,
};

View File

@ -513,17 +513,22 @@ static const struct command_registration parport_command_handlers[] = {
COMMAND_REGISTRATION_DONE
};
struct jtag_interface parport_interface = {
.name = "parport",
static struct jtag_interface parport_interface = {
.supported = DEBUG_CAP_TMS_SEQ,
.execute_queue = bitbang_execute_queue,
};
struct adapter_driver parport_adapter_driver = {
.name = "parport",
.transports = jtag_only,
.commands = parport_command_handlers,
.init = parport_init,
.quit = parport_quit,
.reset = parport_reset,
.speed = parport_speed,
.khz = parport_khz,
.speed_div = parport_speed_div,
.speed = parport_speed,
.execute_queue = bitbang_execute_queue,
.jtag_ops = &parport_interface,
};

View File

@ -561,15 +561,20 @@ static int presto_jtag_quit(void)
return ERROR_OK;
}
struct jtag_interface presto_interface = {
static struct jtag_interface presto_interface = {
.execute_queue = bitq_execute_queue,
};
struct adapter_driver presto_adapter_driver = {
.name = "presto",
.transports = jtag_only,
.commands = presto_command_handlers,
.execute_queue = bitq_execute_queue,
.init = presto_jtag_init,
.quit = presto_jtag_quit,
.speed = presto_jtag_speed,
.khz = presto_adapter_khz,
.speed_div = presto_jtag_speed_div,
.init = presto_jtag_init,
.quit = presto_jtag_quit,
.jtag_ops = &presto_interface,
};

View File

@ -341,12 +341,18 @@ static const struct command_registration remote_bitbang_command_handlers[] = {
COMMAND_REGISTRATION_DONE,
};
struct jtag_interface remote_bitbang_interface = {
.name = "remote_bitbang",
static struct jtag_interface remote_bitbang_interface = {
.execute_queue = &bitbang_execute_queue,
};
struct adapter_driver remote_bitbang_adapter_driver = {
.name = "remote_bitbang",
.transports = jtag_only,
.commands = remote_bitbang_command_handlers,
.init = &remote_bitbang_init,
.quit = &remote_bitbang_quit,
.reset = &remote_bitbang_reset,
.jtag_ops = &remote_bitbang_interface,
};

View File

@ -1660,13 +1660,19 @@ static int rlink_quit(void)
return ERROR_OK;
}
struct jtag_interface rlink_interface = {
static struct jtag_interface rlink_interface = {
.execute_queue = rlink_execute_queue,
};
struct adapter_driver rlink_adapter_driver = {
.name = "rlink",
.transports = jtag_only,
.init = rlink_init,
.quit = rlink_quit,
.speed = rlink_speed,
.speed_div = rlink_speed_div,
.khz = rlink_khz,
.execute_queue = rlink_execute_queue,
.speed_div = rlink_speed_div,
.jtag_ops = &rlink_interface,
};

View File

@ -551,16 +551,22 @@ static int sysfsgpio_quit(void);
static const char * const sysfsgpio_transports[] = { "jtag", "swd", NULL };
struct jtag_interface sysfsgpio_interface = {
.name = "sysfsgpio",
static struct jtag_interface sysfsgpio_interface = {
.supported = DEBUG_CAP_TMS_SEQ,
.execute_queue = bitbang_execute_queue,
};
struct adapter_driver sysfsgpio_adapter_driver = {
.name = "sysfsgpio",
.transports = sysfsgpio_transports,
.swd = &bitbang_swd,
.commands = sysfsgpio_command_handlers,
.init = sysfsgpio_init,
.quit = sysfsgpio_quit,
.reset = sysfsgpio_reset,
.jtag_ops = &sysfsgpio_interface,
.swd_ops = &bitbang_swd,
};
static struct bitbang_interface sysfsgpio_bitbang = {

View File

@ -235,7 +235,7 @@ int ulink_queue_stableclocks(struct ulink *device, struct jtag_command *cmd);
int ulink_post_process_scan(struct ulink_cmd *ulink_cmd);
int ulink_post_process_queue(struct ulink *device);
/* JTAG driver functions (registered in struct jtag_interface) */
/* adapter driver functions */
static int ulink_execute_queue(void);
static int ulink_khz(int khz, int *jtag_speed);
static int ulink_speed(int speed);
@ -2272,17 +2272,20 @@ static const struct command_registration ulink_command_handlers[] = {
COMMAND_REGISTRATION_DONE,
};
struct jtag_interface ulink_interface = {
.name = "ulink",
.commands = ulink_command_handlers,
.transports = jtag_only,
static struct jtag_interface ulink_interface = {
.execute_queue = ulink_execute_queue,
.khz = ulink_khz,
.speed = ulink_speed,
.speed_div = ulink_speed_div,
};
struct adapter_driver ulink_adapter_driver = {
.name = "ulink",
.transports = jtag_only,
.commands = ulink_command_handlers,
.init = ulink_init,
.quit = ulink_quit
.quit = ulink_quit,
.speed = ulink_speed,
.khz = ulink_khz,
.speed_div = ulink_speed_div,
.jtag_ops = &ulink_interface,
};

View File

@ -1071,13 +1071,18 @@ static const struct command_registration ublast_command_handlers[] = {
COMMAND_REGISTRATION_DONE
};
struct jtag_interface usb_blaster_interface = {
static struct jtag_interface usb_blaster_interface = {
.supported = DEBUG_CAP_TMS_SEQ,
.execute_queue = ublast_execute_queue,
};
struct adapter_driver usb_blaster_adapter_driver = {
.name = "usb_blaster",
.transports = jtag_only,
.commands = ublast_command_handlers,
.supported = DEBUG_CAP_TMS_SEQ,
.execute_queue = ublast_execute_queue,
.init = ublast_init,
.quit = ublast_quit,
.jtag_ops = &usb_blaster_interface,
};

View File

@ -596,11 +596,16 @@ static void usbprog_jtag_tms_send(struct usbprog_jtag *usbprog_jtag)
}
}
struct jtag_interface usbprog_interface = {
static struct jtag_interface usbprog_interface = {
.execute_queue = usbprog_execute_queue,
};
struct adapter_driver usbprog_adapter_driver = {
.name = "usbprog",
.transports = jtag_only,
.execute_queue = usbprog_execute_queue,
.init = usbprog_init,
.quit = usbprog_quit
.quit = usbprog_quit,
.jtag_ops = &usbprog_interface,
};

View File

@ -948,18 +948,23 @@ static const struct swd_driver vsllink_swd_driver = {
.run = vsllink_swd_run_queue,
};
struct jtag_interface vsllink_interface = {
.name = "vsllink",
static struct jtag_interface vsllink_interface = {
.supported = DEBUG_CAP_TMS_SEQ,
.commands = vsllink_command_handlers,
.execute_queue = vsllink_execute_queue,
};
struct adapter_driver vsllink_adapter_driver = {
.name = "vsllink",
.transports = vsllink_transports,
.swd = &vsllink_swd_driver,
.commands = vsllink_command_handlers,
.init = vsllink_init,
.quit = vsllink_quit,
.reset = vsllink_reset,
.khz = vsllink_khz,
.speed = vsllink_speed,
.khz = vsllink_khz,
.speed_div = vsllink_speed_div,
.execute_queue = vsllink_execute_queue,
.jtag_ops = &vsllink_interface,
.swd_ops = &vsllink_swd_driver,
};

View File

@ -2038,17 +2038,22 @@ static const struct swd_driver xds110_swd_driver = {
static const char * const xds110_transport[] = { "swd", "jtag", NULL };
struct jtag_interface xds110_interface = {
.name = "xds110",
.commands = xds110_command_handlers,
.swd = &xds110_swd_driver,
.transports = xds110_transport,
static struct jtag_interface xds110_interface = {
.execute_queue = xds110_execute_queue,
.speed = xds110_speed,
.speed_div = xds110_speed_div,
.khz = xds110_khz,
};
struct adapter_driver xds110_adapter_driver = {
.name = "xds110",
.transports = xds110_transport,
.commands = xds110_command_handlers,
.init = xds110_init,
.quit = xds110_quit,
.reset = xds110_reset,
.speed = xds110_speed,
.khz = xds110_khz,
.speed_div = xds110_speed_div,
.jtag_ops = &xds110_interface,
.swd_ops = &xds110_swd_driver,
};

View File

@ -346,10 +346,11 @@ static const struct command_registration hl_interface_command_handlers[] = {
COMMAND_REGISTRATION_DONE
};
struct jtag_interface hl_interface = {
struct adapter_driver hl_adapter_driver = {
.name = "hla",
.commands = hl_interface_command_handlers,
.transports = hl_transports,
.commands = hl_interface_command_handlers,
.init = hl_interface_init,
.quit = hl_interface_quit,
.reset = hl_interface_reset,
@ -358,4 +359,6 @@ struct jtag_interface hl_interface = {
.speed_div = &hl_interface_speed_div,
.config_trace = &hl_interface_config_trace,
.poll_trace = &hl_interface_poll_trace,
/* no ops for HLA, targets hla_target and stm8 intercept them all */
};

View File

@ -192,32 +192,34 @@ static inline tap_state_t jtag_debug_state_machine(const void *tms_buf,
* debugging interface.
*/
struct jtag_interface {
/** The name of the JTAG interface driver. */
const char * const name;
/**
* Bit vector listing capabilities exposed by this driver.
*/
unsigned supported;
#define DEBUG_CAP_TMS_SEQ (1 << 0)
/** transports supported in C code (NULL terminated vector) */
const char * const *transports;
const struct swd_driver *swd;
/**
* Execute queued commands.
* @returns ERROR_OK on success, or an error code on failure.
*/
int (*execute_queue)(void);
};
/**
* Set the interface speed.
* @param speed The new interface speed setting.
* @returns ERROR_OK on success, or an error code on failure.
*/
int (*speed)(int speed);
/**
* Represents a driver for a debugging interface
*
* @todo We need a per-instance structure too, and changes to pass
* that structure to the driver. Instances can for example be in
* either SWD or JTAG modes. This will help remove globals, and
* eventually to cope with systems which have more than one such
* debugging interface.
*/
struct adapter_driver {
/** The name of the interface driver. */
const char * const name;
/** transports supported in C code (NULL terminated vector) */
const char * const *transports;
/**
* The interface driver may register additional commands to expose
@ -260,6 +262,13 @@ struct jtag_interface {
*/
int (*reset)(int srst, int trst);
/**
* Set the interface speed.
* @param speed The new interface speed setting.
* @returns ERROR_OK on success, or an error code on failure.
*/
int (*speed)(int speed);
/**
* Returns JTAG maxium speed for KHz. 0 = RTCK. The function returns
* a failure if it can't support the KHz/RTCK.
@ -336,6 +345,12 @@ struct jtag_interface {
* @returns ERROR_OK on success, an error code on failure.
*/
int (*poll_trace)(uint8_t *buf, size_t *size);
/** Low-level JTAG APIs */
struct jtag_interface *jtag_ops;
/** Low-level SWD APIs */
const struct swd_driver *swd_ops;
};
extern const char * const jtag_only[];

View File

@ -34,106 +34,106 @@
/** @file
* This file includes declarations for all built-in jtag interfaces,
* which are then listed in the jtag_interfaces array.
* which are then listed in the adapter_drivers array.
*
* Dynamic loading can be implemented be searching for shared libraries
* that contain a jtag_interface structure that can added to this list.
* that contain an adapter_driver structure that can added to this list.
*/
#if BUILD_ZY1000 == 1
extern struct jtag_interface zy1000_interface;
extern struct adapter_driver zy1000_adapter_driver;
#elif defined(BUILD_MINIDRIVER_DUMMY)
extern struct jtag_interface minidummy_interface;
extern struct adapter_driver minidummy_adapter_driver;
#else /* standard drivers */
#if BUILD_PARPORT == 1
extern struct jtag_interface parport_interface;
extern struct adapter_driver parport_adapter_driver;
#endif
#if BUILD_DUMMY == 1
extern struct jtag_interface dummy_interface;
extern struct adapter_driver dummy_adapter_driver;
#endif
#if BUILD_FTDI == 1
extern struct jtag_interface ftdi_interface;
extern struct adapter_driver ftdi_adapter_driver;
#endif
#if BUILD_USB_BLASTER == 1 || BUILD_USB_BLASTER_2 == 1
extern struct jtag_interface usb_blaster_interface;
extern struct adapter_driver usb_blaster_adapter_driver;
#endif
#if BUILD_JTAG_VPI == 1
extern struct jtag_interface jtag_vpi_interface;
extern struct adapter_driver jtag_vpi_adapter_driver;
#endif
#if BUILD_FT232R == 1
extern struct jtag_interface ft232r_interface;
extern struct adapter_driver ft232r_adapter_driver;
#endif
#if BUILD_AMTJTAGACCEL == 1
extern struct jtag_interface amt_jtagaccel_interface;
extern struct adapter_driver amt_jtagaccel_adapter_driver;
#endif
#if BUILD_EP93XX == 1
extern struct jtag_interface ep93xx_interface;
extern struct adapter_driver ep93xx_adapter_driver;
#endif
#if BUILD_AT91RM9200 == 1
extern struct jtag_interface at91rm9200_interface;
extern struct adapter_driver at91rm9200_adapter_driver;
#endif
#if BUILD_GW16012 == 1
extern struct jtag_interface gw16012_interface;
extern struct adapter_driver gw16012_adapter_driver;
#endif
#if BUILD_PRESTO
extern struct jtag_interface presto_interface;
extern struct adapter_driver presto_adapter_driver;
#endif
#if BUILD_USBPROG == 1
extern struct jtag_interface usbprog_interface;
extern struct adapter_driver usbprog_adapter_driver;
#endif
#if BUILD_OPENJTAG == 1
extern struct jtag_interface openjtag_interface;
extern struct adapter_driver openjtag_adapter_driver;
#endif
#if BUILD_JLINK == 1
extern struct jtag_interface jlink_interface;
extern struct adapter_driver jlink_adapter_driver;
#endif
#if BUILD_VSLLINK == 1
extern struct jtag_interface vsllink_interface;
extern struct adapter_driver vsllink_adapter_driver;
#endif
#if BUILD_RLINK == 1
extern struct jtag_interface rlink_interface;
extern struct adapter_driver rlink_adapter_driver;
#endif
#if BUILD_ULINK == 1
extern struct jtag_interface ulink_interface;
extern struct adapter_driver ulink_adapter_driver;
#endif
#if BUILD_ARMJTAGEW == 1
extern struct jtag_interface armjtagew_interface;
extern struct adapter_driver armjtagew_adapter_driver;
#endif
#if BUILD_BUSPIRATE == 1
extern struct jtag_interface buspirate_interface;
extern struct adapter_driver buspirate_adapter_driver;
#endif
#if BUILD_REMOTE_BITBANG == 1
extern struct jtag_interface remote_bitbang_interface;
extern struct adapter_driver remote_bitbang_adapter_driver;
#endif
#if BUILD_HLADAPTER == 1
extern struct jtag_interface hl_interface;
extern struct adapter_driver hl_adapter_driver;
#endif
#if BUILD_OSBDM == 1
extern struct jtag_interface osbdm_interface;
extern struct adapter_driver osbdm_adapter_driver;
#endif
#if BUILD_OPENDOUS == 1
extern struct jtag_interface opendous_interface;
extern struct adapter_driver opendous_adapter_driver;
#endif
#if BUILD_SYSFSGPIO == 1
extern struct jtag_interface sysfsgpio_interface;
extern struct adapter_driver sysfsgpio_adapter_driver;
#endif
#if BUILD_AICE == 1
extern struct jtag_interface aice_interface;
extern struct adapter_driver aice_adapter_driver;
#endif
#if BUILD_BCM2835GPIO == 1
extern struct jtag_interface bcm2835gpio_interface;
extern struct adapter_driver bcm2835gpio_adapter_driver;
#endif
#if BUILD_CMSIS_DAP == 1
extern struct jtag_interface cmsis_dap_interface;
extern struct adapter_driver cmsis_dap_adapter_driver;
#endif
#if BUILD_KITPROG == 1
extern struct jtag_interface kitprog_interface;
extern struct adapter_driver kitprog_adapter_driver;
#endif
#if BUILD_IMX_GPIO == 1
extern struct jtag_interface imx_gpio_interface;
extern struct adapter_driver imx_gpio_adapter_driver;
#endif
#if BUILD_XDS110 == 1
extern struct jtag_interface xds110_interface;
extern struct adapter_driver xds110_adapter_driver;
#endif
#endif /* standard drivers */
@ -144,107 +144,107 @@ extern struct jtag_interface xds110_interface;
* The list should be defined to contain either one minidriver interface
* or some number of standard driver interfaces, never both.
*/
struct jtag_interface *jtag_interfaces[] = {
struct adapter_driver *adapter_drivers[] = {
#if BUILD_ZY1000 == 1
&zy1000_interface,
&zy1000_adapter_driver,
#elif defined(BUILD_MINIDRIVER_DUMMY)
&minidummy_interface,
&minidummy_adapter_driver,
#else /* standard drivers */
#if BUILD_PARPORT == 1
&parport_interface,
&parport_adapter_driver,
#endif
#if BUILD_DUMMY == 1
&dummy_interface,
&dummy_adapter_driver,
#endif
#if BUILD_FTDI == 1
&ftdi_interface,
&ftdi_adapter_driver,
#endif
#if BUILD_USB_BLASTER || BUILD_USB_BLASTER_2 == 1
&usb_blaster_interface,
&usb_blaster_adapter_driver,
#endif
#if BUILD_JTAG_VPI == 1
&jtag_vpi_interface,
&jtag_vpi_adapter_driver,
#endif
#if BUILD_FT232R == 1
&ft232r_interface,
&ft232r_adapter_driver,
#endif
#if BUILD_AMTJTAGACCEL == 1
&amt_jtagaccel_interface,
&amt_jtagaccel_adapter_driver,
#endif
#if BUILD_EP93XX == 1
&ep93xx_interface,
&ep93xx_adapter_driver,
#endif
#if BUILD_AT91RM9200 == 1
&at91rm9200_interface,
&at91rm9200_adapter_driver,
#endif
#if BUILD_GW16012 == 1
&gw16012_interface,
&gw16012_adapter_driver,
#endif
#if BUILD_PRESTO
&presto_interface,
&presto_adapter_driver,
#endif
#if BUILD_USBPROG == 1
&usbprog_interface,
&usbprog_adapter_driver,
#endif
#if BUILD_OPENJTAG == 1
&openjtag_interface,
&openjtag_adapter_driver,
#endif
#if BUILD_JLINK == 1
&jlink_interface,
&jlink_adapter_driver,
#endif
#if BUILD_VSLLINK == 1
&vsllink_interface,
&vsllink_adapter_driver,
#endif
#if BUILD_RLINK == 1
&rlink_interface,
&rlink_adapter_driver,
#endif
#if BUILD_ULINK == 1
&ulink_interface,
&ulink_adapter_driver,
#endif
#if BUILD_ARMJTAGEW == 1
&armjtagew_interface,
&armjtagew_adapter_driver,
#endif
#if BUILD_BUSPIRATE == 1
&buspirate_interface,
&buspirate_adapter_driver,
#endif
#if BUILD_REMOTE_BITBANG == 1
&remote_bitbang_interface,
&remote_bitbang_adapter_driver,
#endif
#if BUILD_HLADAPTER == 1
&hl_interface,
&hl_adapter_driver,
#endif
#if BUILD_OSBDM == 1
&osbdm_interface,
&osbdm_adapter_driver,
#endif
#if BUILD_OPENDOUS == 1
&opendous_interface,
&opendous_adapter_driver,
#endif
#if BUILD_SYSFSGPIO == 1
&sysfsgpio_interface,
&sysfsgpio_adapter_driver,
#endif
#if BUILD_AICE == 1
&aice_interface,
&aice_adapter_driver,
#endif
#if BUILD_BCM2835GPIO == 1
&bcm2835gpio_interface,
&bcm2835gpio_adapter_driver,
#endif
#if BUILD_CMSIS_DAP == 1
&cmsis_dap_interface,
&cmsis_dap_adapter_driver,
#endif
#if BUILD_KITPROG == 1
&kitprog_interface,
&kitprog_adapter_driver,
#endif
#if BUILD_IMX_GPIO == 1
&imx_gpio_interface,
&imx_gpio_adapter_driver,
#endif
#if BUILD_XDS110 == 1
&xds110_interface,
&xds110_adapter_driver,
#endif
#endif /* standard drivers */
NULL,
};
void jtag_interface_modules_load(const char *path)
void adapter_driver_modules_load(const char *path)
{
/* @todo: implement dynamic module loading for JTAG interface drivers */
/* @todo: implement dynamic module loading for adapter drivers */
}

View File

@ -36,9 +36,9 @@
#include <jtag/interface.h>
/** Dynamically load all JTAG interface modules from specified directory. */
void jtag_interface_modules_load(const char *path);
/** Dynamically load all adapter driver modules from specified directory. */
void adapter_driver_modules_load(const char *path);
extern struct jtag_interface *jtag_interfaces[];
extern struct adapter_driver *adapter_drivers[];
#endif /* OPENOCD_JTAG_INTERFACES_H */

View File

@ -24,18 +24,24 @@
#include <jtag/minidriver.h>
#include <jtag/interface.h>
struct jtag_interface minidummy_interface = {
.name = "minidummy",
static struct jtag_interface minidummy_interface = {
.execute_queue = NULL,
.speed = NULL,
};
struct adapter_driver minidummy_adapter_driver = {
.name = "minidummy",
.transports = jtag_only,
.commands = NULL,
.init = NULL,
.quit = NULL,
.speed = NULL,
.khz = NULL,
.speed_div = NULL,
.power_dropout = NULL,
.srst_asserted = NULL,
.jtag_ops = &minidummy_interface,
};
int interface_jtag_execute_queue(void)

View File

@ -1237,17 +1237,23 @@ int zy1000_init(void)
return ERROR_OK;
}
struct jtag_interface zy1000_interface = {
.name = "ZY1000",
static struct jtag_interface zy1000_interface = {
.supported = DEBUG_CAP_TMS_SEQ,
.execute_queue = NULL,
.speed = zy1000_speed,
};
struct adapter_driver zy1000_adapter_driver = {
.name = "ZY1000",
.transports = jtag_only,
.commands = zy1000_commands,
.init = zy1000_init,
.quit = zy1000_quit,
.speed = zy1000_speed,
.khz = zy1000_khz,
.speed_div = zy1000_speed_div,
.power_dropout = zy1000_power_dropout,
.srst_asserted = zy1000_srst_asserted,
.jtag_ops = &zy1000_interface,
};

View File

@ -368,9 +368,9 @@ static const struct command_registration swd_handlers[] = {
static int swd_select(struct command_context *ctx)
{
/* FIXME: only place where global 'jtag_interface' is still needed */
extern struct jtag_interface *jtag_interface;
const struct swd_driver *swd = jtag_interface->swd;
/* FIXME: only place where global 'adapter_driver' is still needed */
extern struct adapter_driver *adapter_driver;
const struct swd_driver *swd = adapter_driver->swd_ops;
int retval;
retval = register_commands(ctx, NULL, swd_handlers);

View File

@ -34,7 +34,7 @@ static LIST_HEAD(all_dap);
extern const struct dap_ops swd_dap_ops;
extern const struct dap_ops jtag_dp_ops;
extern struct jtag_interface *jtag_interface;
extern struct adapter_driver *adapter_driver;
/* DAP command support */
struct arm_dap_object {
@ -118,7 +118,7 @@ static int dap_init_all(void)
if (transport_is_swd()) {
dap->ops = &swd_dap_ops;
obj->swd = jtag_interface->swd;
obj->swd = adapter_driver->swd_ops;
} else
dap->ops = &jtag_dp_ops;