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.
 
 
 
 
 
 

177 lines
5.7 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, see <http://www.gnu.org/licenses/>. *
  23. ***************************************************************************/
  24. #ifndef OPENOCD_JTAG_COMMANDS_H
  25. #define OPENOCD_JTAG_COMMANDS_H
  26. /**
  27. * The inferred type of a scan_command_s structure, indicating whether
  28. * the command has the host scan in from the device, the host scan out
  29. * to the device, or both.
  30. */
  31. enum scan_type {
  32. /** From device to host, */
  33. SCAN_IN = 1,
  34. /** From host to device, */
  35. SCAN_OUT = 2,
  36. /** Full-duplex scan. */
  37. SCAN_IO = 3
  38. };
  39. /**
  40. * The scan_command provide a means of encapsulating a set of scan_field_s
  41. * structures that should be scanned in/out to the device.
  42. */
  43. struct scan_command {
  44. /** instruction/not data scan */
  45. bool ir_scan;
  46. /** number of fields in *fields array */
  47. int num_fields;
  48. /** pointer to an array of data scan fields */
  49. struct scan_field *fields;
  50. /** state in which JTAG commands should finish */
  51. tap_state_t end_state;
  52. };
  53. struct statemove_command {
  54. /** state in which JTAG commands should finish */
  55. tap_state_t end_state;
  56. };
  57. struct pathmove_command {
  58. /** number of states in *path */
  59. int num_states;
  60. /** states that have to be passed */
  61. tap_state_t *path;
  62. };
  63. struct runtest_command {
  64. /** number of cycles to spend in Run-Test/Idle state */
  65. int num_cycles;
  66. /** state in which JTAG commands should finish */
  67. tap_state_t end_state;
  68. };
  69. struct stableclocks_command {
  70. /** number of clock cycles that should be sent */
  71. int num_cycles;
  72. };
  73. struct reset_command {
  74. /** Set TRST output: 0 = deassert, 1 = assert, -1 = no change */
  75. int trst;
  76. /** Set SRST output: 0 = deassert, 1 = assert, -1 = no change */
  77. int srst;
  78. };
  79. struct end_state_command {
  80. /** state in which JTAG commands should finish */
  81. tap_state_t end_state;
  82. };
  83. struct sleep_command {
  84. /** number of microseconds to sleep */
  85. uint32_t us;
  86. };
  87. /**
  88. * Encapsulates a series of bits to be clocked out, affecting state
  89. * and mode of the interface.
  90. *
  91. * In JTAG mode these are clocked out on TMS, using TCK. They may be
  92. * used for link resets, transitioning between JTAG and SWD modes, or
  93. * to implement JTAG state machine transitions (implementing pathmove
  94. * or statemove operations).
  95. *
  96. * In SWD mode these are clocked out on SWDIO, using SWCLK, and are
  97. * used for link resets and transitioning between SWD and JTAG modes.
  98. */
  99. struct tms_command {
  100. /** How many bits should be clocked out. */
  101. unsigned num_bits;
  102. /** The bits to clock out; the LSB is bit 0 of bits[0]. */
  103. const uint8_t *bits;
  104. };
  105. /**
  106. * Defines a container type that hold a pointer to a JTAG command
  107. * structure of any defined type.
  108. */
  109. union jtag_command_container {
  110. struct scan_command *scan;
  111. struct statemove_command *statemove;
  112. struct pathmove_command *pathmove;
  113. struct runtest_command *runtest;
  114. struct stableclocks_command *stableclocks;
  115. struct reset_command *reset;
  116. struct end_state_command *end_state;
  117. struct sleep_command *sleep;
  118. struct tms_command *tms;
  119. };
  120. /**
  121. * The type of the @c jtag_command_container contained by a
  122. * @c jtag_command_s structure.
  123. */
  124. enum jtag_command_type {
  125. JTAG_SCAN = 1,
  126. /* JTAG_TLR_RESET's non-minidriver implementation is a
  127. * vestige from a statemove cmd. The statemove command
  128. * is obsolete and replaced by pathmove.
  129. *
  130. * pathmove does not support reset as one of it's states,
  131. * hence the need for an explicit statemove command.
  132. */
  133. JTAG_TLR_RESET = 2,
  134. JTAG_RUNTEST = 3,
  135. JTAG_RESET = 4,
  136. JTAG_PATHMOVE = 6,
  137. JTAG_SLEEP = 7,
  138. JTAG_STABLECLOCKS = 8,
  139. JTAG_TMS = 9,
  140. };
  141. struct jtag_command {
  142. union jtag_command_container cmd;
  143. enum jtag_command_type type;
  144. struct jtag_command *next;
  145. };
  146. /** The current queue of jtag_command_s structures. */
  147. extern struct jtag_command *jtag_command_queue;
  148. void *cmd_queue_alloc(size_t size);
  149. void jtag_queue_command(struct jtag_command *cmd);
  150. void jtag_command_queue_reset(void);
  151. enum scan_type jtag_scan_type(const struct scan_command *cmd);
  152. int jtag_scan_size(const struct scan_command *cmd);
  153. int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd);
  154. int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer);
  155. #endif /* OPENOCD_JTAG_COMMANDS_H */