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.
 
 
 
 
 
 

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