2
0

tap.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #include "common.h"
  2. #include "jtag.h"
  3. const uint8_t tap_state_next[16][2] = {
  4. [TAP_TEST_LOGIC_RESET] = { TAP_RUN_TEST_IDLE, TAP_TEST_LOGIC_RESET },
  5. [TAP_RUN_TEST_IDLE ] = { TAP_RUN_TEST_IDLE, TAP_SELECT_DR_SCAN },
  6. [TAP_SELECT_DR_SCAN ] = { TAP_CAPTURE_DR, TAP_SELECT_IR_SCAN },
  7. [TAP_CAPTURE_DR ] = { TAP_SHIFT_DR, TAP_EXIT1_DR },
  8. [TAP_SHIFT_DR ] = { TAP_SHIFT_DR, TAP_EXIT1_DR },
  9. [TAP_EXIT1_DR ] = { TAP_PAUSE_DR, TAP_UPDATE_DR },
  10. [TAP_PAUSE_DR ] = { TAP_PAUSE_DR, TAP_EXIT2_DR },
  11. [TAP_EXIT2_DR ] = { TAP_SHIFT_DR, TAP_UPDATE_DR },
  12. [TAP_UPDATE_DR ] = { TAP_RUN_TEST_IDLE, TAP_SELECT_DR_SCAN },
  13. [TAP_SELECT_IR_SCAN ] = { TAP_CAPTURE_IR, TAP_TEST_LOGIC_RESET },
  14. [TAP_CAPTURE_IR ] = { TAP_SHIFT_IR, TAP_EXIT1_IR },
  15. [TAP_SHIFT_IR ] = { TAP_SHIFT_IR, TAP_EXIT1_IR },
  16. [TAP_EXIT1_IR ] = { TAP_PAUSE_IR, TAP_UPDATE_IR },
  17. [TAP_PAUSE_IR ] = { TAP_PAUSE_IR, TAP_EXIT2_IR },
  18. [TAP_EXIT2_IR ] = { TAP_SHIFT_IR, TAP_UPDATE_IR },
  19. [TAP_UPDATE_IR ] = { TAP_RUN_TEST_IDLE, TAP_SELECT_DR_SCAN }
  20. };
  21. const char tap_state_names[16][4] =
  22. {
  23. "TLR", "RTI", "SDS", "CDR", "SDR", "EDR", "PDR", "ED2",
  24. "UDR", "SIS", "CIR", "SIR", "EIR", "PIR", "EI2", "UIR"
  25. };
  26. #ifdef MAKE_TAPROUTE_C /* Generate taproute.c */
  27. #include <stdio.h>
  28. #include <limits.h>
  29. int main(void)
  30. {
  31. int dir[16][16];
  32. unsigned int distance[16][16];
  33. memset(dir, 0, sizeof dir);
  34. memset(distance, 0x55, sizeof distance); /* Just don't wrap */
  35. for (unsigned int fs = 0; fs < 16; fs++) {
  36. distance[fs][fs] = 0;
  37. dir[fs][fs] = tap_state_next[fs][0] != fs;
  38. }
  39. bool better;
  40. do {
  41. better = false;
  42. for (unsigned int fs = 0; fs < 16; fs++) {
  43. for (unsigned int ts = 0; ts < 16; ts++) {
  44. for (unsigned int d = 0; d < 2; d++) {
  45. unsigned int next = tap_state_next[fs][d];
  46. unsigned int next_cost = distance[next][ts]+1;
  47. if (distance[fs][ts] > next_cost) {
  48. distance[fs][ts] = next_cost;
  49. dir[fs][ts] = d;
  50. better = true;
  51. }
  52. }
  53. }
  54. }
  55. } while (better);
  56. printf("/*\n"
  57. " * This is a generated file!\n"
  58. " *\n"
  59. " * JTAG state routing table: to get from the horizontal\n"
  60. " * axis state to the vertical axis state, go in the given\n"
  61. " * direction. The table in this comment also shows the number\n"
  62. " * of transitions needed.\n"
  63. " *\n");
  64. printf(" * from:");
  65. for (unsigned int fs = 0; fs < 16; fs++)
  66. printf(" %3s", tap_state_names[fs]);
  67. printf("\n *\n");
  68. for (unsigned int ts = 0; ts < 16; ts++) {
  69. printf(" * %3s: ", tap_state_names[ts]);
  70. for (unsigned int fs = 0; fs < 16; fs++) {
  71. printf(" %d/%d", dir[fs][ts], distance[fs][ts]);
  72. }
  73. printf("\n");
  74. }
  75. printf(" *\n");
  76. for (unsigned int d = 0; d < 2; d++) {
  77. printf(" * [%u] ", d);
  78. for (unsigned int fs = 0; fs < 16; fs++)
  79. printf(" %3s", tap_state_names[tap_state_next[fs][d]]);
  80. printf("\n");
  81. }
  82. printf(" */\n\n");
  83. printf("#include \"jtag.h\"\n\n");
  84. printf("const uint16_t tap_state_route[16] = {\n");
  85. for (unsigned int ts = 0; ts < 16; ts++) {
  86. unsigned int dirmask = 0;
  87. for (unsigned int fs = 0; fs < 16; fs++) {
  88. dirmask |= dir[fs][ts] << fs;
  89. }
  90. printf("\t0x%04x,\n", dirmask);
  91. }
  92. printf("};\n");
  93. return 0;
  94. }
  95. #endif /* MAKE_TAPROUTE_C */