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.
 
 
 
 
 
 

163 lines
4.2 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2008 by Øyvind Harboe *
  3. * oyvind.harboe@zylin.com *
  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. #include <jtag/interface.h>
  24. #include "bitbang.h"
  25. #include "hello.h"
  26. /* my private tap controller state, which tracks state for calling code */
  27. static tap_state_t dummy_state = TAP_RESET;
  28. static int dummy_clock; /* edge detector */
  29. static int clock_count; /* count clocks in any stable state, only stable states */
  30. static uint32_t dummy_data;
  31. static int dummy_read(void)
  32. {
  33. int data = 1 & dummy_data;
  34. dummy_data = (dummy_data >> 1) | (1 << 31);
  35. return data;
  36. }
  37. static void dummy_write(int tck, int tms, int tdi)
  38. {
  39. /* TAP standard: "state transitions occur on rising edge of clock" */
  40. if (tck != dummy_clock) {
  41. if (tck) {
  42. tap_state_t old_state = dummy_state;
  43. dummy_state = tap_state_transition(old_state, tms);
  44. if (old_state != dummy_state) {
  45. if (clock_count) {
  46. LOG_DEBUG("dummy_tap: %d stable clocks", clock_count);
  47. clock_count = 0;
  48. }
  49. LOG_DEBUG("dummy_tap: %s", tap_state_name(dummy_state));
  50. #if defined(DEBUG)
  51. if (dummy_state == TAP_DRCAPTURE)
  52. dummy_data = 0x01255043;
  53. #endif
  54. } else {
  55. /* this is a stable state clock edge, no change of state here,
  56. * simply increment clock_count for subsequent logging
  57. */
  58. ++clock_count;
  59. }
  60. }
  61. dummy_clock = tck;
  62. }
  63. }
  64. static void dummy_reset(int trst, int srst)
  65. {
  66. dummy_clock = 0;
  67. if (trst || (srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST)))
  68. dummy_state = TAP_RESET;
  69. LOG_DEBUG("reset to: %s", tap_state_name(dummy_state));
  70. }
  71. static void dummy_led(int on)
  72. {
  73. }
  74. static struct bitbang_interface dummy_bitbang = {
  75. .read = &dummy_read,
  76. .write = &dummy_write,
  77. .reset = &dummy_reset,
  78. .blink = &dummy_led,
  79. };
  80. static int dummy_khz(int khz, int *jtag_speed)
  81. {
  82. if (khz == 0)
  83. *jtag_speed = 0;
  84. else
  85. *jtag_speed = 64000/khz;
  86. return ERROR_OK;
  87. }
  88. static int dummy_speed_div(int speed, int *khz)
  89. {
  90. if (speed == 0)
  91. *khz = 0;
  92. else
  93. *khz = 64000/speed;
  94. return ERROR_OK;
  95. }
  96. static int dummy_speed(int speed)
  97. {
  98. return ERROR_OK;
  99. }
  100. static int dummy_init(void)
  101. {
  102. bitbang_interface = &dummy_bitbang;
  103. return ERROR_OK;
  104. }
  105. static int dummy_quit(void)
  106. {
  107. return ERROR_OK;
  108. }
  109. static const struct command_registration dummy_command_handlers[] = {
  110. {
  111. .name = "dummy",
  112. .mode = COMMAND_ANY,
  113. .help = "dummy interface driver commands",
  114. .chain = hello_command_handlers,
  115. },
  116. COMMAND_REGISTRATION_DONE,
  117. };
  118. /* The dummy driver is used to easily check the code path
  119. * where the target is unresponsive.
  120. */
  121. struct jtag_interface dummy_interface = {
  122. .name = "dummy",
  123. .supported = DEBUG_CAP_TMS_SEQ,
  124. .commands = dummy_command_handlers,
  125. .transports = jtag_only,
  126. .execute_queue = &bitbang_execute_queue,
  127. .speed = &dummy_speed,
  128. .khz = &dummy_khz,
  129. .speed_div = &dummy_speed_div,
  130. .init = &dummy_init,
  131. .quit = &dummy_quit,
  132. };