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.
 
 
 
 
 
 

171 lines
5.5 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2005 by Dominic Rath *
  3. * Dominic.Rath@gmx.de *
  4. * *
  5. * Copyright (C) 2007,2008 Øyvind Harboe *
  6. * oyvind.harboe@zylin.com *
  7. * *
  8. * Copyright (C) 2009 Zachary T Welch *
  9. * zw@superlucidity.net *
  10. * *
  11. * This program is free software; you can redistribute it and/or modify *
  12. * it under the terms of the GNU General Public License as published by *
  13. * the Free Software Foundation; either version 2 of the License, or *
  14. * (at your option) any later version. *
  15. * *
  16. * This program is distributed in the hope that it will be useful, *
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  19. * GNU General Public License for more details. *
  20. * *
  21. * You should have received a copy of the GNU General Public License *
  22. * along with this program; if not, write to the *
  23. * Free Software Foundation, Inc., *
  24. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  25. ***************************************************************************/
  26. #ifndef JTAG_COMMANDS_H
  27. #define JTAG_COMMANDS_H
  28. /**
  29. * The inferred type of a scan_command_s structure, indicating whether
  30. * the command has the host scan in from the device, the host scan out
  31. * to the device, or both.
  32. */
  33. enum scan_type {
  34. /// From device to host,
  35. SCAN_IN = 1,
  36. /// From host to device,
  37. SCAN_OUT = 2,
  38. /// Full-duplex scan.
  39. SCAN_IO = 3
  40. };
  41. /**
  42. * The scan_command provide a means of encapsulating a set of scan_field_s
  43. * structures that should be scanned in/out to the device.
  44. */
  45. struct scan_command {
  46. /// instruction/not data scan
  47. bool ir_scan;
  48. /// number of fields in *fields array
  49. int num_fields;
  50. /// pointer to an array of data scan fields
  51. struct scan_field* fields;
  52. /// state in which JTAG commands should finish
  53. tap_state_t end_state;
  54. };
  55. struct statemove_command {
  56. /// state in which JTAG commands should finish
  57. tap_state_t end_state;
  58. };
  59. struct pathmove_command {
  60. /// number of states in *path
  61. int num_states;
  62. /// states that have to be passed
  63. tap_state_t* path;
  64. };
  65. struct runtest_command {
  66. /// number of cycles to spend in Run-Test/Idle state
  67. int num_cycles;
  68. /// state in which JTAG commands should finish
  69. tap_state_t end_state;
  70. };
  71. struct stableclocks_command {
  72. /// number of clock cycles that should be sent
  73. int num_cycles;
  74. };
  75. struct reset_command {
  76. /// Set TRST output: 0 = deassert, 1 = assert, -1 = no change
  77. int trst;
  78. /// Set SRST output: 0 = deassert, 1 = assert, -1 = no change
  79. int srst;
  80. };
  81. struct end_state_command {
  82. /// state in which JTAG commands should finish
  83. tap_state_t end_state;
  84. };
  85. struct sleep_command {
  86. /// number of microseconds to sleep
  87. uint32_t us;
  88. };
  89. /**
  90. * Encapsulates a series of bits to be clocked out, affecting state
  91. * and mode of the interface.
  92. *
  93. * In JTAG mode these are clocked out on TMS, using TCK. They may be
  94. * used for link resets, transitioning between JTAG and SWD modes, or
  95. * to implement JTAG state machine transitions (implementing pathmove
  96. * or statemove operations).
  97. *
  98. * In SWD mode these are clocked out on SWDIO, using SWCLK, and are
  99. * used for link resets and transitioning between SWD and JTAG modes.
  100. */
  101. struct tms_command {
  102. /** How many bits should be clocked out. */
  103. unsigned num_bits;
  104. /** The bits to clock out; the LSB is bit 0 of bits[0]. */
  105. const uint8_t *bits;
  106. };
  107. /**
  108. * Defines a container type that hold a pointer to a JTAG command
  109. * structure of any defined type.
  110. */
  111. union jtag_command_container {
  112. struct scan_command *scan;
  113. struct statemove_command *statemove;
  114. struct pathmove_command *pathmove;
  115. struct runtest_command *runtest;
  116. struct stableclocks_command *stableclocks;
  117. struct reset_command *reset;
  118. struct end_state_command *end_state;
  119. struct sleep_command *sleep;
  120. struct tms_command *tms;
  121. };
  122. /**
  123. * The type of the @c jtag_command_container contained by a
  124. * @c jtag_command_s structure.
  125. */
  126. enum jtag_command_type {
  127. JTAG_SCAN = 1,
  128. JTAG_STATEMOVE = 2,
  129. JTAG_RUNTEST = 3,
  130. JTAG_RESET = 4,
  131. JTAG_PATHMOVE = 6,
  132. JTAG_SLEEP = 7,
  133. JTAG_STABLECLOCKS = 8,
  134. JTAG_TMS = 9,
  135. };
  136. struct jtag_command {
  137. union jtag_command_container cmd;
  138. enum jtag_command_type type;
  139. struct jtag_command *next;
  140. };
  141. /// The current queue of jtag_command_s structures.
  142. extern struct jtag_command* jtag_command_queue;
  143. void* cmd_queue_alloc(size_t size);
  144. void jtag_queue_command(struct jtag_command *cmd);
  145. void jtag_command_queue_reset(void);
  146. enum scan_type jtag_scan_type(const struct scan_command* cmd);
  147. int jtag_scan_size(const struct scan_command* cmd);
  148. int jtag_read_buffer(uint8_t* buffer, const struct scan_command* cmd);
  149. int jtag_build_buffer(const struct scan_command* cmd, uint8_t** buffer);
  150. #endif // JTAG_COMMANDS_H