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.
 
 
 
 
 
 

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