You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

181 lines
4.8 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2011 by Mathias Kuester *
  3. * Mathias Kuester <kesmtp@freenet.de> *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #ifdef HAVE_CONFIG_H
  21. #include "config.h"
  22. #endif
  23. /* project specific includes */
  24. #include <jtag/interface.h>
  25. #include <jtag/tcl.h>
  26. #include <transport/transport.h>
  27. #include <helper/time_support.h>
  28. #include <target/target.h>
  29. #include <jtag/stlink/stlink_tcl.h>
  30. #include <jtag/stlink/stlink_interface.h>
  31. COMMAND_HANDLER(stlink_transport_jtag_command)
  32. {
  33. LOG_DEBUG("stlink_transport_jtag_command");
  34. return ERROR_OK;
  35. }
  36. static const struct command_registration
  37. stlink_transport_stlink_subcommand_handlers[] = {
  38. {
  39. .name = "newtap",
  40. .mode = COMMAND_CONFIG,
  41. .jim_handler = jim_stlink_newtap,
  42. .help = "Create a new TAP instance named basename.tap_type, "
  43. "and appends it to the scan chain.",
  44. .usage = "basename tap_type '-irlen' count "
  45. "['-expected_id' number] ",
  46. },
  47. COMMAND_REGISTRATION_DONE
  48. };
  49. static const struct command_registration
  50. stlink_transport_jtag_subcommand_handlers[] = {
  51. {
  52. .name = "init",
  53. .mode = COMMAND_ANY,
  54. .handler = stlink_transport_jtag_command,
  55. },
  56. {
  57. .name = "arp_init",
  58. .mode = COMMAND_ANY,
  59. .handler = stlink_transport_jtag_command,
  60. },
  61. {
  62. .name = "arp_init-reset",
  63. .mode = COMMAND_ANY,
  64. .handler = stlink_transport_jtag_command,
  65. },
  66. {
  67. .name = "tapisenabled",
  68. .mode = COMMAND_EXEC,
  69. .jim_handler = jim_jtag_tap_enabler,
  70. },
  71. {
  72. .name = "tapenable",
  73. .mode = COMMAND_EXEC,
  74. .jim_handler = jim_jtag_tap_enabler,
  75. },
  76. {
  77. .name = "tapdisable",
  78. .mode = COMMAND_EXEC,
  79. .handler = stlink_transport_jtag_command,
  80. },
  81. {
  82. .name = "configure",
  83. .mode = COMMAND_EXEC,
  84. .handler = stlink_transport_jtag_command,
  85. },
  86. {
  87. .name = "cget",
  88. .mode = COMMAND_EXEC,
  89. .jim_handler = jim_jtag_configure,
  90. },
  91. {
  92. .name = "names",
  93. .mode = COMMAND_ANY,
  94. .handler = stlink_transport_jtag_command,
  95. },
  96. COMMAND_REGISTRATION_DONE
  97. };
  98. static const struct command_registration stlink_transport_command_handlers[] = {
  99. {
  100. .name = "stlink",
  101. .mode = COMMAND_ANY,
  102. .help = "perform stlink actions",
  103. .chain = stlink_transport_stlink_subcommand_handlers,
  104. },
  105. {
  106. .name = "jtag",
  107. .mode = COMMAND_ANY,
  108. .chain = stlink_transport_jtag_subcommand_handlers,
  109. },
  110. COMMAND_REGISTRATION_DONE
  111. };
  112. static int stlink_transport_register_commands(struct command_context *cmd_ctx)
  113. {
  114. return register_commands(cmd_ctx, NULL,
  115. stlink_transport_command_handlers);
  116. }
  117. static int stlink_transport_init(struct command_context *cmd_ctx)
  118. {
  119. LOG_DEBUG("stlink_transport_init");
  120. struct target *t = get_current_target(cmd_ctx);
  121. if (!t) {
  122. LOG_ERROR("stlink_transport_init: no current target");
  123. return ERROR_FAIL;
  124. }
  125. stlink_interface_open();
  126. return stlink_interface_init_target(t);
  127. }
  128. static int stlink_transport_select(struct command_context *ctx)
  129. {
  130. LOG_DEBUG("stlink_transport_select");
  131. int retval;
  132. /* NOTE: interface init must already have been done.
  133. * That works with only C code ... no Tcl glue required.
  134. */
  135. retval = stlink_transport_register_commands(ctx);
  136. if (retval != ERROR_OK)
  137. return retval;
  138. return ERROR_OK;
  139. }
  140. static struct transport stlink_transport = {
  141. .name = "stlink",
  142. .select = stlink_transport_select,
  143. .init = stlink_transport_init,
  144. };
  145. const char *stlink_transports[] = { "stlink", NULL };
  146. static void stlink_constructor(void) __attribute__ ((constructor));
  147. static void stlink_constructor(void)
  148. {
  149. transport_register(&stlink_transport);
  150. }
  151. bool transport_is_stlink(void)
  152. {
  153. return get_current_transport() == &stlink_transport;
  154. }