diff options
Diffstat (limited to 'src/jtag/hla')
-rw-r--r-- | src/jtag/hla/Makefile.am | 23 | ||||
-rw-r--r-- | src/jtag/hla/hla_interface.c | 286 | ||||
-rw-r--r-- | src/jtag/hla/hla_interface.h | 65 | ||||
-rw-r--r-- | src/jtag/hla/hla_layout.c | 86 | ||||
-rw-r--r-- | src/jtag/hla/hla_layout.h | 93 | ||||
-rw-r--r-- | src/jtag/hla/hla_tcl.c | 139 | ||||
-rw-r--r-- | src/jtag/hla/hla_tcl.h | 30 | ||||
-rw-r--r-- | src/jtag/hla/hla_transport.c | 229 | ||||
-rw-r--r-- | src/jtag/hla/hla_transport.h | 34 |
9 files changed, 985 insertions, 0 deletions
diff --git a/src/jtag/hla/Makefile.am b/src/jtag/hla/Makefile.am new file mode 100644 index 00000000..4fbc70e9 --- /dev/null +++ b/src/jtag/hla/Makefile.am @@ -0,0 +1,23 @@ +include $(top_srcdir)/common.mk + +noinst_LTLIBRARIES = libocdhla.la + +libocdhla_la_SOURCES = \ + $(HLFILES) + +HLFILES = + +if HLADAPTER +HLFILES += hla_transport.c +HLFILES += hla_tcl.c +HLFILES += hla_interface.c +HLFILES += hla_layout.c +endif + +noinst_HEADERS = \ + hla_interface.h \ + hla_layout.h \ + hla_tcl.h \ + hla_transport.h + +MAINTAINERCLEANFILES = $(srcdir)/Makefile.in diff --git a/src/jtag/hla/hla_interface.c b/src/jtag/hla/hla_interface.c new file mode 100644 index 00000000..397eeeae --- /dev/null +++ b/src/jtag/hla/hla_interface.c @@ -0,0 +1,286 @@ +/*************************************************************************** + * Copyright (C) 2011 by Mathias Kuester * + * Mathias Kuester <kesmtp@freenet.de> * + * * + * Copyright (C) 2012 by Spencer Oliver * + * spen@spen-soft.co.uk * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +/* project specific includes */ +#include <jtag/interface.h> +#include <transport/transport.h> +#include <helper/time_support.h> + +#include <jtag/hla/hla_tcl.h> +#include <jtag/hla/hla_layout.h> +#include <jtag/hla/hla_transport.h> +#include <jtag/hla/hla_interface.h> + +#include <target/target.h> + +static struct hl_interface_s hl_if = { {0, 0, 0, 0, 0, 0}, 0, 0 }; + +int hl_interface_open(enum hl_transports tr) +{ + LOG_DEBUG("hl_interface_open"); + + /* set transport mode */ + hl_if.param.transport = tr; + + int result = hl_if.layout->open(&hl_if); + if (result != ERROR_OK) + return result; + + return hl_interface_init_reset(); +} + +int hl_interface_init_target(struct target *t) +{ + int res; + + LOG_DEBUG("hl_interface_init_target"); + + /* this is the interface for the current target and we + * can setup the private pointer in the tap structure + * if the interface match the tap idcode + */ + res = hl_if.layout->api->idcode(hl_if.fd, &t->tap->idcode); + + if (res != ERROR_OK) + return res; + + unsigned ii, limit = t->tap->expected_ids_cnt; + int found = 0; + + for (ii = 0; ii < limit; ii++) { + uint32_t expected = t->tap->expected_ids[ii]; + + /* treat "-expected-id 0" as a "don't-warn" wildcard */ + if (!expected || (t->tap->idcode == expected)) { + found = 1; + break; + } + } + + if (found == 0) { + LOG_ERROR("hl_interface_init_target: target not found: idcode: 0x%08x", + t->tap->idcode); + return ERROR_FAIL; + } + + t->tap->priv = &hl_if; + t->tap->hasidcode = 1; + + return ERROR_OK; +} + +static int hl_interface_init(void) +{ + LOG_DEBUG("hl_interface_init"); + + /* here we can initialize the layout */ + return hl_layout_init(&hl_if); +} + +static int hl_interface_quit(void) +{ + LOG_DEBUG("hl_interface_quit"); + + return ERROR_OK; +} + +static int hl_interface_speed(int speed) +{ + LOG_DEBUG("hl_interface_speed: ignore speed %d", speed); + + return ERROR_OK; +} + +static int hl_speed_div(int speed, int *khz) +{ + *khz = speed; + return ERROR_OK; +} + +static int hl_khz(int khz, int *jtag_speed) +{ + *jtag_speed = khz; + return ERROR_OK; +} + +static int hl_interface_execute_queue(void) +{ + LOG_DEBUG("hl_interface_execute_queue: ignored"); + + return ERROR_OK; +} + +int hl_interface_init_reset(void) +{ + enum reset_types jtag_reset_config = jtag_get_reset_config(); + + if (jtag_reset_config & RESET_CNCT_UNDER_SRST) { + if (jtag_reset_config & RESET_SRST_NO_GATING) { + jtag_add_reset(0, 1); + hl_if.layout->api->assert_srst(hl_if.fd, 0); + } else + LOG_WARNING("\'srst_nogate\' reset_config option is required"); + } + + return ERROR_OK; +} + +COMMAND_HANDLER(hl_interface_handle_device_desc_command) +{ + LOG_DEBUG("hl_interface_handle_device_desc_command"); + + if (CMD_ARGC == 1) { + hl_if.param.device_desc = strdup(CMD_ARGV[0]); + } else { + LOG_ERROR("expected exactly one argument to hl_device_desc <description>"); + } + + return ERROR_OK; +} + +COMMAND_HANDLER(hl_interface_handle_serial_command) +{ + LOG_DEBUG("hl_interface_handle_serial_command"); + + if (CMD_ARGC == 1) { + hl_if.param.serial = strdup(CMD_ARGV[0]); + } else { + LOG_ERROR("expected exactly one argument to hl_serial <serial-number>"); + } + + return ERROR_OK; +} + +COMMAND_HANDLER(hl_interface_handle_layout_command) +{ + LOG_DEBUG("hl_interface_handle_layout_command"); + + if (CMD_ARGC != 1) { + LOG_ERROR("Need exactly one argument to stlink_layout"); + return ERROR_COMMAND_SYNTAX_ERROR; + } + + if (hl_if.layout) { + LOG_ERROR("already specified hl_layout %s", + hl_if.layout->name); + return (strcmp(hl_if.layout->name, CMD_ARGV[0]) != 0) + ? ERROR_FAIL : ERROR_OK; + } + + for (const struct hl_layout *l = hl_layout_get_list(); l->name; + l++) { + if (strcmp(l->name, CMD_ARGV[0]) == 0) { + hl_if.layout = l; + return ERROR_OK; + } + } + + LOG_ERROR("No adapter layout '%s' found", CMD_ARGV[0]); + return ERROR_FAIL; +} + +COMMAND_HANDLER(hl_interface_handle_vid_pid_command) +{ + LOG_DEBUG("hl_interface_handle_vid_pid_command"); + + if (CMD_ARGC != 2) { + LOG_WARNING("ignoring extra IDs in hl_vid_pid (maximum is 1 pair)"); + return ERROR_COMMAND_SYNTAX_ERROR; + } + + COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], hl_if.param.vid); + COMMAND_PARSE_NUMBER(u16, CMD_ARGV[1], hl_if.param.pid); + + return ERROR_OK; +} + +COMMAND_HANDLER(hl_interface_handle_api_command) +{ + if (CMD_ARGC != 1) + return ERROR_COMMAND_SYNTAX_ERROR; + + unsigned new_api; + COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], new_api); + if ((new_api == 0) || (new_api > 2)) + return ERROR_COMMAND_SYNTAX_ERROR; + + hl_if.param.api = new_api; + + return ERROR_OK; +} + +static const struct command_registration hl_interface_command_handlers[] = { + { + .name = "stlink_device_desc", + .handler = &hl_interface_handle_device_desc_command, + .mode = COMMAND_CONFIG, + .help = "set the a device description of the adapter", + .usage = "description_string", + }, + { + .name = "stlink_serial", + .handler = &hl_interface_handle_serial_command, + .mode = COMMAND_CONFIG, + .help = "set the serial number of the adapter", + .usage = "serial_string", + }, + { + .name = "stlink_layout", + .handler = &hl_interface_handle_layout_command, + .mode = COMMAND_CONFIG, + .help = "set the layout of the adapter", + .usage = "layout_name", + }, + { + .name = "stlink_vid_pid", + .handler = &hl_interface_handle_vid_pid_command, + .mode = COMMAND_CONFIG, + .help = "the vendor and product ID of the adapter", + .usage = "(vid pid)* ", + }, + { + .name = "stlink_api", + .handler = &hl_interface_handle_api_command, + .mode = COMMAND_CONFIG, + .help = "set the desired stlink api level", + .usage = "api version 1 or 2", + }, + COMMAND_REGISTRATION_DONE +}; + +struct jtag_interface hl_interface = { + .name = "stlink", + .supported = 0, + .commands = hl_interface_command_handlers, + .transports = hl_transports, + .init = hl_interface_init, + .quit = hl_interface_quit, + .speed = hl_interface_speed, + .speed_div = hl_speed_div, + .khz = hl_khz, + .execute_queue = hl_interface_execute_queue, +}; diff --git a/src/jtag/hla/hla_interface.h b/src/jtag/hla/hla_interface.h new file mode 100644 index 00000000..cbeee5a1 --- /dev/null +++ b/src/jtag/hla/hla_interface.h @@ -0,0 +1,65 @@ +/*************************************************************************** + * Copyright (C) 2011 by Mathias Kuester * + * Mathias Kuester <kesmtp@freenet.de> * + * * + * Copyright (C) 2012 by Spencer Oliver * + * spen@spen-soft.co.uk * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef _HL_INTERFACE +#define _HL_INTERFACE + +/** */ +struct target; +/** */ +enum e_hl_transports; +/** */ +extern const char *hl_transports[]; + +struct hl_interface_param_s { + /** */ + char *device_desc; + /** */ + char *serial; + /** */ + uint16_t vid; + /** */ + uint16_t pid; + /** */ + unsigned api; + /** */ + enum hl_transports transport; +}; + +struct hl_interface_s { + /** */ + struct hl_interface_param_s param; + /** */ + const struct hl_layout *layout; + /** */ + void *fd; +}; + +/** */ +int hl_interface_open(enum hl_transports tr); +/** */ + +int hl_interface_init_target(struct target *t); +int hl_interface_init_reset(void); + +#endif /* _HL_INTERFACE */ diff --git a/src/jtag/hla/hla_layout.c b/src/jtag/hla/hla_layout.c new file mode 100644 index 00000000..04b50d7f --- /dev/null +++ b/src/jtag/hla/hla_layout.c @@ -0,0 +1,86 @@ +/*************************************************************************** + * Copyright (C) 2011 by Mathias Kuester * + * Mathias Kuester <kesmtp@freenet.de> * + * * + * Copyright (C) 2012 by Spencer Oliver * + * spen@spen-soft.co.uk * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +/* project specific includes */ +#include <jtag/interface.h> +#include <transport/transport.h> +#include <helper/time_support.h> + +#include <jtag/hla/hla_layout.h> +#include <jtag/hla/hla_tcl.h> +#include <jtag/hla/hla_transport.h> +#include <jtag/hla/hla_interface.h> + +static int hl_layout_open(struct hl_interface_s *adapter) +{ + int res; + + LOG_DEBUG("hl_layout_open"); + + adapter->fd = NULL; + + res = adapter->layout->api->open(&adapter->param, &adapter->fd); + + if (res != ERROR_OK) { + LOG_DEBUG("failed"); + return res; + } + + return ERROR_OK; +} + +static int hl_layout_close(struct hl_interface_s *adapter) +{ + return ERROR_OK; +} + +static const struct hl_layout hl_layouts[] = { + { + .name = "stlink", + .open = hl_layout_open, + .close = hl_layout_close, + .api = &stlink_usb_layout_api, + }, + {.name = NULL, /* END OF TABLE */ }, +}; + +/** */ +const struct hl_layout *hl_layout_get_list(void) +{ + return hl_layouts; +} + +int hl_layout_init(struct hl_interface_s *adapter) +{ + LOG_DEBUG("hl_layout_init"); + + if (adapter->layout == NULL) { + LOG_ERROR("no layout specified"); + return ERROR_FAIL; + } + return ERROR_OK; +} diff --git a/src/jtag/hla/hla_layout.h b/src/jtag/hla/hla_layout.h new file mode 100644 index 00000000..982d71a8 --- /dev/null +++ b/src/jtag/hla/hla_layout.h @@ -0,0 +1,93 @@ +/*************************************************************************** + * Copyright (C) 2011 by Mathias Kuester * + * Mathias Kuester <kesmtp@freenet.de> * + * * + * Copyright (C) 2012 by Spencer Oliver * + * spen@spen-soft.co.uk * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef _HL_LAYOUT_H +#define _HL_LAYOUT_H + +/** */ +struct hl_interface_s; +struct hl_interface_param_s; + +/** */ +extern struct hl_layout_api_s stlink_usb_layout_api; + +/** */ +struct hl_layout_api_s { + /** */ + int (*open) (struct hl_interface_param_s *param, void **fd); + /** */ + int (*close) (void *fd); + /** */ + int (*reset) (void *fd); + /** */ + int (*assert_srst) (void *fd, int srst); + /** */ + int (*run) (void *fd); + /** */ + int (*halt) (void *fd); + /** */ + int (*step) (void *fd); + /** */ + int (*read_regs) (void *fd); + /** */ + int (*read_reg) (void *fd, int num, uint32_t *val); + /** */ + int (*write_reg) (void *fd, int num, uint32_t val); + /** */ + int (*read_mem8) (void *handle, uint32_t addr, uint16_t len, + uint8_t *buffer); + /** */ + int (*write_mem8) (void *handle, uint32_t addr, uint16_t len, + const uint8_t *buffer); + /** */ + int (*read_mem32) (void *handle, uint32_t addr, uint16_t len, + uint8_t *buffer); + /** */ + int (*write_mem32) (void *handle, uint32_t addr, uint16_t len, + const uint8_t *buffer); + /** */ + int (*write_debug_reg) (void *handle, uint32_t addr, uint32_t val); + /** */ + int (*idcode) (void *fd, uint32_t *idcode); + /** */ + enum target_state (*state) (void *fd); +}; + +/** */ +struct hl_layout { + /** */ + char *name; + /** */ + int (*open) (struct hl_interface_s *adapter); + /** */ + int (*close) (struct hl_interface_s *adapter); + /** */ + struct hl_layout_api_s *api; +}; + +/** */ +const struct hl_layout *hl_layout_get_list(void); +/** */ +int hl_layout_init(struct hl_interface_s *adapter); + +#endif /* _HL_LAYOUT_H */ diff --git a/src/jtag/hla/hla_tcl.c b/src/jtag/hla/hla_tcl.c new file mode 100644 index 00000000..86838b0c --- /dev/null +++ b/src/jtag/hla/hla_tcl.c @@ -0,0 +1,139 @@ +/*************************************************************************** + * Copyright (C) 2011 by Mathias Kuester * + * Mathias Kuester <kesmtp@freenet.de> * + * * + * Copyright (C) 2012 by Spencer Oliver * + * spen@spen-soft.co.uk * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +/* project specific includes */ +#include <jtag/interface.h> +#include <transport/transport.h> +#include <helper/time_support.h> + +static int jim_newtap_expected_id(Jim_Nvp *n, Jim_GetOptInfo *goi, + struct jtag_tap *pTap) +{ + jim_wide w; + int e = Jim_GetOpt_Wide(goi, &w); + if (e != JIM_OK) { + Jim_SetResultFormatted(goi->interp, "option: %s bad parameter", + n->name); + return e; + } + + unsigned expected_len = sizeof(uint32_t) * pTap->expected_ids_cnt; + uint32_t *new_expected_ids = malloc(expected_len + sizeof(uint32_t)); + if (new_expected_ids == NULL) { + Jim_SetResultFormatted(goi->interp, "no memory"); + return JIM_ERR; + } + + memcpy(new_expected_ids, pTap->expected_ids, expected_len); + + new_expected_ids[pTap->expected_ids_cnt] = w; + + free(pTap->expected_ids); + pTap->expected_ids = new_expected_ids; + pTap->expected_ids_cnt++; + + return JIM_OK; +} + +#define NTAP_OPT_EXPECTED_ID 0 + +static int jim_hl_newtap_cmd(Jim_GetOptInfo *goi) +{ + struct jtag_tap *pTap; + int x; + int e; + Jim_Nvp *n; + char *cp; + const Jim_Nvp opts[] = { + {.name = "-expected-id", .value = NTAP_OPT_EXPECTED_ID}, + {.name = NULL, .value = -1}, + }; + + pTap = calloc(1, sizeof(struct jtag_tap)); + if (!pTap) { + Jim_SetResultFormatted(goi->interp, "no memory"); + return JIM_ERR; + } + + /* + * we expect CHIP + TAP + OPTIONS + * */ + if (goi->argc < 3) { + Jim_SetResultFormatted(goi->interp, + "Missing CHIP TAP OPTIONS ...."); + free(pTap); + return JIM_ERR; + } + Jim_GetOpt_String(goi, &cp, NULL); + pTap->chip = strdup(cp); + + Jim_GetOpt_String(goi, &cp, NULL); + pTap->tapname = strdup(cp); + + /* name + dot + name + null */ + x = strlen(pTap->chip) + 1 + strlen(pTap->tapname) + 1; + cp = malloc(x); + sprintf(cp, "%s.%s", pTap->chip, pTap->tapname); + pTap->dotted_name = cp; + + LOG_DEBUG("Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params", + pTap->chip, pTap->tapname, pTap->dotted_name, goi->argc); + + while (goi->argc) { + e = Jim_GetOpt_Nvp(goi, opts, &n); + if (e != JIM_OK) { + Jim_GetOpt_NvpUnknown(goi, opts, 0); + free((void *)pTap->dotted_name); + free(pTap); + return e; + } + LOG_DEBUG("Processing option: %s", n->name); + switch (n->value) { + case NTAP_OPT_EXPECTED_ID: + e = jim_newtap_expected_id(n, goi, pTap); + if (JIM_OK != e) { + free((void *)pTap->dotted_name); + free(pTap); + return e; + } + break; + } /* switch (n->value) */ + } /* while (goi->argc) */ + + /* default is enabled-after-reset */ + pTap->enabled = !pTap->disabled_after_reset; + + jtag_tap_init(pTap); + return JIM_OK; +} + +int jim_hl_newtap(Jim_Interp *interp, int argc, Jim_Obj * const *argv) +{ + Jim_GetOptInfo goi; + Jim_GetOpt_Setup(&goi, interp, argc - 1, argv + 1); + return jim_hl_newtap_cmd(&goi); +} diff --git a/src/jtag/hla/hla_tcl.h b/src/jtag/hla/hla_tcl.h new file mode 100644 index 00000000..aa17a50c --- /dev/null +++ b/src/jtag/hla/hla_tcl.h @@ -0,0 +1,30 @@ +/*************************************************************************** + * Copyright (C) 2011 by Mathias Kuester * + * Mathias Kuester <kesmtp@freenet.de> * + * * + * Copyright (C) 2012 by Spencer Oliver * + * spen@spen-soft.co.uk * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef _HL_TCL_ +#define _HL_TCL_ + +/** */ +int jim_hl_newtap(Jim_Interp *interp, int argc, Jim_Obj * const *argv); + +#endif /* _HL_TCL_ */ diff --git a/src/jtag/hla/hla_transport.c b/src/jtag/hla/hla_transport.c new file mode 100644 index 00000000..177459bd --- /dev/null +++ b/src/jtag/hla/hla_transport.c @@ -0,0 +1,229 @@ +/*************************************************************************** + * Copyright (C) 2011 by Mathias Kuester * + * Mathias Kuester <kesmtp@freenet.de> * + * * + * Copyright (C) 2012 by Spencer Oliver * + * spen@spen-soft.co.uk * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +/* project specific includes */ +#include <jtag/interface.h> +#include <jtag/tcl.h> +#include <transport/transport.h> +#include <helper/time_support.h> +#include <target/target.h> +#include <jtag/hla/hla_tcl.h> +#include <jtag/hla/hla_transport.h> +#include <jtag/hla/hla_interface.h> + +COMMAND_HANDLER(hl_transport_jtag_command) +{ + LOG_DEBUG("hl_transport_jtag_command"); + + return ERROR_OK; +} + +COMMAND_HANDLER(hl_transport_reset_command) +{ + return hl_interface_init_reset(); +} + +static const struct command_registration +hl_transport_stlink_subcommand_handlers[] = { + { + .name = "newtap", + .mode = COMMAND_CONFIG, + .jim_handler = jim_hl_newtap, + .help = "Create a new TAP instance named basename.tap_type, " + "and appends it to the scan chain.", + .usage = "basename tap_type '-irlen' count " + "['-expected_id' number] ", + }, + + COMMAND_REGISTRATION_DONE +}; + +static const struct command_registration +hl_transport_jtag_subcommand_handlers[] = { + { + .name = "init", + .mode = COMMAND_ANY, + .handler = hl_transport_jtag_command, + .usage = "" + }, + { + .name = "arp_init", + .mode = COMMAND_ANY, + .handler = hl_transport_jtag_command, + .usage = "" + }, + { + .name = "arp_init-reset", + .mode = COMMAND_ANY, + .handler = hl_transport_reset_command, + .usage = "" + }, + { + .name = "tapisenabled", + .mode = COMMAND_EXEC, + .jim_handler = jim_jtag_tap_enabler, + }, + { + .name = "tapenable", + .mode = COMMAND_EXEC, + .jim_handler = jim_jtag_tap_enabler, + }, + { + .name = "tapdisable", + .mode = COMMAND_EXEC, + .handler = hl_transport_jtag_command, + .usage = "", + }, + { + .name = "configure", + .mode = COMMAND_EXEC, + .handler = hl_transport_jtag_command, + .usage = "", + }, + { + .name = "cget", + .mode = COMMAND_EXEC, + .jim_handler = jim_jtag_configure, + }, + { + .name = "names", + .mode = COMMAND_ANY, + .handler = hl_transport_jtag_command, + .usage = "", + }, + + COMMAND_REGISTRATION_DONE +}; + +static const struct command_registration stlink_transport_command_handlers[] = { + + { + .name = "stlink", + .mode = COMMAND_ANY, + .help = "perform stlink actions", + .usage = "", + .chain = hl_transport_stlink_subcommand_handlers, + }, + { + .name = "jtag", + .mode = COMMAND_ANY, + .usage = "", + .chain = hl_transport_jtag_subcommand_handlers, + }, + COMMAND_REGISTRATION_DONE +}; + +static int hl_transport_register_commands(struct command_context *cmd_ctx) +{ + return register_commands(cmd_ctx, NULL, + stlink_transport_command_handlers); +} + +static int hl_transport_init(struct command_context *cmd_ctx) +{ + LOG_DEBUG("hl_transport_init"); + struct target *t = get_current_target(cmd_ctx); + struct transport *transport; + enum hl_transports tr; + + if (!t) { + LOG_ERROR("no current target"); + return ERROR_FAIL; + } + + transport = get_current_transport(); + + if (!transport) { + LOG_ERROR("no transport selected"); + return ERROR_FAIL; + } + + LOG_DEBUG("current transport %s", transport->name); + + /* get selected transport as enum */ + tr = HL_TRANSPORT_UNKNOWN; + + if (strcmp(transport->name, "stlink_swd") == 0) + tr = HL_TRANSPORT_SWD; + else if (strcmp(transport->name, "stlink_jtag") == 0) + tr = HL_TRANSPORT_JTAG; + else if (strcmp(transport->name, "stlink_swim") == 0) + tr = HL_TRANSPORT_SWIM; + + int retval = hl_interface_open(tr); + + if (retval != ERROR_OK) + return retval; + + return hl_interface_init_target(t); +} + +static int hl_transport_select(struct command_context *ctx) +{ + LOG_DEBUG("hl_transport_select"); + + int retval; + + /* NOTE: interface init must already have been done. + * That works with only C code ... no Tcl glue required. + */ + + retval = hl_transport_register_commands(ctx); + + if (retval != ERROR_OK) + return retval; + + return ERROR_OK; +} + +static struct transport hl_swd_transport = { + .name = "stlink_swd", + .select = hl_transport_select, + .init = hl_transport_init, +}; + +static struct transport hl_jtag_transport = { + .name = "stlink_jtag", + .select = hl_transport_select, + .init = hl_transport_init, +}; + +static struct transport hl_swim_transport = { + .name = "stlink_swim", + .select = hl_transport_select, + .init = hl_transport_init, +}; + +const char *hl_transports[] = { "stlink_swd", "stlink_jtag", "stlink_swim", NULL }; + +static void hl_constructor(void) __attribute__ ((constructor)); +static void hl_constructor(void) +{ + transport_register(&hl_swd_transport); + transport_register(&hl_jtag_transport); + transport_register(&hl_swim_transport); +} diff --git a/src/jtag/hla/hla_transport.h b/src/jtag/hla/hla_transport.h new file mode 100644 index 00000000..bcd7ed13 --- /dev/null +++ b/src/jtag/hla/hla_transport.h @@ -0,0 +1,34 @@ +/*************************************************************************** + * Copyright (C) 2011 by Mathias Kuester * + * Mathias Kuester <kesmtp@freenet.de> * + * * + * Copyright (C) 2012 by Spencer Oliver * + * spen@spen-soft.co.uk * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef _HL_TRANSPORT +#define _HL_TRANSPORT + +enum hl_transports { + HL_TRANSPORT_UNKNOWN = 0, + HL_TRANSPORT_SWD, + HL_TRANSPORT_JTAG, + HL_TRANSPORT_SWIM +}; + +#endif /* _HL_TRANSPORT */ |