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.
 
 
 
 
 
 

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