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.
 
 
 
 
 
 

755 lines
23 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. * This program is free software; you can redistribute it and/or modify *
  9. * it under the terms of the GNU General Public License as published by *
  10. * the Free Software Foundation; either version 2 of the License, or *
  11. * (at your option) any later version. *
  12. * *
  13. * This program is distributed in the hope that it will be useful, *
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  16. * GNU General Public License for more details. *
  17. * *
  18. * You should have received a copy of the GNU General Public License *
  19. * along with this program; if not, write to the *
  20. * Free Software Foundation, Inc., *
  21. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  22. ***************************************************************************/
  23. #ifndef JTAG_H
  24. #define JTAG_H
  25. #include "binarybuffer.h"
  26. #include "log.h"
  27. #ifdef _DEBUG_JTAG_IO_
  28. #define DEBUG_JTAG_IO(expr ...) LOG_DEBUG(expr)
  29. #else
  30. #define DEBUG_JTAG_IO(expr ...)
  31. #endif
  32. #ifndef DEBUG_JTAG_IOZ
  33. #define DEBUG_JTAG_IOZ 64
  34. #endif
  35. /*-----<Macros>--------------------------------------------------*/
  36. /**
  37. * When given an array, compute its DIMension; in other words, the
  38. * number of elements in the array
  39. */
  40. #define DIM(x) (sizeof(x)/sizeof((x)[0]))
  41. /** Calculate the number of bytes required to hold @a n TAP scan bits */
  42. #define TAP_SCAN_BYTES(n) CEIL(n, 8)
  43. /*-----</Macros>-------------------------------------------------*/
  44. /**
  45. * Defines JTAG Test Access Port states.
  46. *
  47. * These definitions were gleaned from the ARM7TDMI-S Technical
  48. * Reference Manual and validated against several other ARM core
  49. * technical manuals. tap_get_tms_path() is sensitive to this numbering
  50. * and ordering of the TAP states; furthermore, some interfaces require
  51. * specific numbers be used, as they are handed-off directly to their
  52. * hardware implementations.
  53. */
  54. typedef enum tap_state
  55. {
  56. #if BUILD_ECOSBOARD
  57. /* These are the old numbers. Leave as-is for now... */
  58. TAP_RESET = 0, TAP_IDLE = 8,
  59. TAP_DRSELECT = 1, TAP_DRCAPTURE = 2, TAP_DRSHIFT = 3, TAP_DREXIT1 = 4,
  60. TAP_DRPAUSE = 5, TAP_DREXIT2 = 6, TAP_DRUPDATE = 7,
  61. TAP_IRSELECT = 9, TAP_IRCAPTURE = 10, TAP_IRSHIFT = 11, TAP_IREXIT1 = 12,
  62. TAP_IRPAUSE = 13, TAP_IREXIT2 = 14, TAP_IRUPDATE = 15,
  63. TAP_NUM_STATES = 16, TAP_INVALID = -1,
  64. #else
  65. /* Proper ARM recommended numbers */
  66. TAP_DREXIT2 = 0x0,
  67. TAP_DREXIT1 = 0x1,
  68. TAP_DRSHIFT = 0x2,
  69. TAP_DRPAUSE = 0x3,
  70. TAP_IRSELECT = 0x4,
  71. TAP_DRUPDATE = 0x5,
  72. TAP_DRCAPTURE = 0x6,
  73. TAP_DRSELECT = 0x7,
  74. TAP_IREXIT2 = 0x8,
  75. TAP_IREXIT1 = 0x9,
  76. TAP_IRSHIFT = 0xa,
  77. TAP_IRPAUSE = 0xb,
  78. TAP_IDLE = 0xc,
  79. TAP_IRUPDATE = 0xd,
  80. TAP_IRCAPTURE = 0xe,
  81. TAP_RESET = 0x0f,
  82. TAP_NUM_STATES = 0x10,
  83. TAP_INVALID = -1,
  84. #endif
  85. } tap_state_t;
  86. /**
  87. * Function tap_state_name
  88. * Returns a string suitable for display representing the JTAG tap_state
  89. */
  90. const char* tap_state_name(tap_state_t state);
  91. /// The current TAP state of the pending JTAG command queue.
  92. extern tap_state_t cmd_queue_cur_state;
  93. /// The TAP state in which DR scans should end.
  94. extern tap_state_t cmd_queue_end_state;
  95. /**
  96. * This structure defines a single scan field in the scan. It provides
  97. * fields for the field's width and pointers to scan input and output
  98. * values.
  99. *
  100. * In addition, this structure includes a value and mask that is used by
  101. * jtag_add_dr_scan_check() to validate the value that was scanned out.
  102. *
  103. * The allocated, modified, and intmp fields are internal work space.
  104. */
  105. typedef struct scan_field_s
  106. {
  107. /// A pointer to the tap structure to which this field refers.
  108. jtag_tap_t* tap;
  109. /// The number of bits this field specifies (up to 32)
  110. int num_bits;
  111. /// A pointer to value to be scanned into the device
  112. u8* out_value;
  113. /// A pointer to a 32-bit memory location for data scanned out
  114. u8* in_value;
  115. /// The value used to check the data scanned out.
  116. u8* check_value;
  117. /// The mask to go with check_value
  118. u8* check_mask;
  119. /// in_value has been allocated for the queue
  120. int allocated;
  121. /// Indicates we modified the in_value.
  122. int modified;
  123. /// temporary storage for performing value checks synchronously
  124. u8 intmp[4];
  125. } scan_field_t;
  126. #ifdef INCLUDE_JTAG_INTERFACE_H
  127. /**
  128. * The inferred type of a scan_command_s structure, indicating whether
  129. * the command has the host scan in from the device, the host scan out
  130. * to the device, or both.
  131. */
  132. enum scan_type {
  133. /// From device to host,
  134. SCAN_IN = 1,
  135. /// From host to device,
  136. SCAN_OUT = 2,
  137. /// Full-duplex scan.
  138. SCAN_IO = 3
  139. };
  140. /**
  141. * The scan_command provide a means of encapsulating a set of scan_field_s
  142. * structures that should be scanned in/out to the device.
  143. */
  144. typedef struct scan_command_s
  145. {
  146. /// instruction/not data scan
  147. bool ir_scan;
  148. /// number of fields in *fields array
  149. int num_fields;
  150. /// pointer to an array of data scan fields
  151. scan_field_t* fields;
  152. /// state in which JTAG commands should finish
  153. tap_state_t end_state;
  154. } scan_command_t;
  155. typedef struct statemove_command_s
  156. {
  157. /// state in which JTAG commands should finish
  158. tap_state_t end_state;
  159. } statemove_command_t;
  160. typedef struct pathmove_command_s
  161. {
  162. /// number of states in *path
  163. int num_states;
  164. /// states that have to be passed
  165. tap_state_t* path;
  166. } pathmove_command_t;
  167. typedef struct runtest_command_s
  168. {
  169. /// number of cycles to spend in Run-Test/Idle state
  170. int num_cycles;
  171. /// state in which JTAG commands should finish
  172. tap_state_t end_state;
  173. } runtest_command_t;
  174. typedef struct stableclocks_command_s
  175. {
  176. /// number of clock cycles that should be sent
  177. int num_cycles;
  178. } stableclocks_command_t;
  179. typedef struct reset_command_s
  180. {
  181. /// Set TRST output: 0=deassert, 1=assert, -1=no change
  182. int trst;
  183. /// Set SRST output: 0=deassert, 1=assert, -1=no change
  184. int srst;
  185. } reset_command_t;
  186. typedef struct end_state_command_s
  187. {
  188. /// state in which JTAG commands should finish
  189. tap_state_t end_state;
  190. } end_state_command_t;
  191. typedef struct sleep_command_s
  192. {
  193. /// number of microseconds to sleep
  194. u32 us;
  195. } sleep_command_t;
  196. /**
  197. * Defines a container type that hold a pointer to a JTAG command
  198. * structure of any defined type.
  199. */
  200. typedef union jtag_command_container_u
  201. {
  202. scan_command_t* scan;
  203. statemove_command_t* statemove;
  204. pathmove_command_t* pathmove;
  205. runtest_command_t* runtest;
  206. stableclocks_command_t* stableclocks;
  207. reset_command_t* reset;
  208. end_state_command_t* end_state;
  209. sleep_command_t* sleep;
  210. } jtag_command_container_t;
  211. /**
  212. * The type of the @c jtag_command_container_u contained by a
  213. * @c jtag_command_s structure.
  214. */
  215. enum jtag_command_type {
  216. JTAG_SCAN = 1,
  217. JTAG_STATEMOVE = 2,
  218. JTAG_RUNTEST = 3,
  219. JTAG_RESET = 4,
  220. JTAG_PATHMOVE = 6,
  221. JTAG_SLEEP = 7,
  222. JTAG_STABLECLOCKS = 8
  223. };
  224. typedef struct jtag_command_s
  225. {
  226. jtag_command_container_t cmd;
  227. enum jtag_command_type type;
  228. struct jtag_command_s* next;
  229. } jtag_command_t;
  230. /// The current queue of jtag_command_s structures.
  231. extern jtag_command_t* jtag_command_queue;
  232. extern void* cmd_queue_alloc(size_t size);
  233. extern void cmd_queue_free(void);
  234. extern void jtag_queue_command(jtag_command_t *cmd);
  235. extern void jtag_command_queue_reset(void);
  236. #endif // INCLUDE_JTAG_INTERFACE_H
  237. typedef struct jtag_tap_event_action_s jtag_tap_event_action_t;
  238. /* this is really: typedef jtag_tap_t */
  239. /* But - the typedef is done in "types.h" */
  240. /* due to "forward decloration reasons" */
  241. struct jtag_tap_s
  242. {
  243. const char* chip;
  244. const char* tapname;
  245. const char* dotted_name;
  246. int abs_chain_position;
  247. /// Is this TAP enabled?
  248. int enabled;
  249. int ir_length; /**< size of instruction register */
  250. u32 ir_capture_value;
  251. u8* expected; /**< Capture-IR expected value */
  252. u32 ir_capture_mask;
  253. u8* expected_mask; /**< Capture-IR expected mask */
  254. u32 idcode;
  255. /**< device identification code */
  256. /// Array of expected identification codes */
  257. u32* expected_ids;
  258. /// Number of expected identification codes
  259. u8 expected_ids_cnt;
  260. /// current instruction
  261. u8* cur_instr;
  262. /// Bypass register selected
  263. int bypass;
  264. jtag_tap_event_action_t *event_action;
  265. jtag_tap_t* next_tap;
  266. };
  267. extern jtag_tap_t* jtag_AllTaps(void);
  268. extern jtag_tap_t* jtag_TapByPosition(int n);
  269. extern jtag_tap_t* jtag_TapByString(const char* dotted_name);
  270. extern jtag_tap_t* jtag_TapByJimObj(Jim_Interp* interp, Jim_Obj* obj);
  271. extern jtag_tap_t* jtag_TapByAbsPosition(int abs_position);
  272. extern int jtag_NumEnabledTaps(void);
  273. extern int jtag_NumTotalTaps(void);
  274. static __inline__ jtag_tap_t* jtag_NextEnabledTap(jtag_tap_t* p)
  275. {
  276. if (p == NULL)
  277. {
  278. /* start at the head of list */
  279. p = jtag_AllTaps();
  280. }
  281. else
  282. {
  283. /* start *after* this one */
  284. p = p->next_tap;
  285. }
  286. while (p)
  287. {
  288. if (p->enabled)
  289. {
  290. break;
  291. }
  292. else
  293. {
  294. p = p->next_tap;
  295. }
  296. }
  297. return p;
  298. }
  299. enum reset_line_mode {
  300. LINE_OPEN_DRAIN = 0x0,
  301. LINE_PUSH_PULL = 0x1,
  302. };
  303. enum jtag_event {
  304. JTAG_TRST_ASSERTED
  305. };
  306. extern char* jtag_event_strings[];
  307. enum jtag_tap_event {
  308. JTAG_TAP_EVENT_ENABLE,
  309. JTAG_TAP_EVENT_DISABLE
  310. };
  311. extern const Jim_Nvp nvp_jtag_tap_event[];
  312. struct jtag_tap_event_action_s
  313. {
  314. enum jtag_tap_event event;
  315. Jim_Obj* body;
  316. jtag_tap_event_action_t* next;
  317. };
  318. extern int jtag_trst;
  319. extern int jtag_srst;
  320. typedef struct jtag_event_callback_s
  321. {
  322. int (*callback)(enum jtag_event event, void* priv);
  323. void* priv;
  324. struct jtag_event_callback_s* next;
  325. } jtag_event_callback_t;
  326. extern jtag_event_callback_t* jtag_event_callbacks;
  327. extern int jtag_speed;
  328. extern int jtag_speed_post_reset;
  329. enum reset_types {
  330. RESET_NONE = 0x0,
  331. RESET_HAS_TRST = 0x1,
  332. RESET_HAS_SRST = 0x2,
  333. RESET_TRST_AND_SRST = 0x3,
  334. RESET_SRST_PULLS_TRST = 0x4,
  335. RESET_TRST_PULLS_SRST = 0x8,
  336. RESET_TRST_OPEN_DRAIN = 0x10,
  337. RESET_SRST_PUSH_PULL = 0x20,
  338. };
  339. extern enum reset_types jtag_reset_config;
  340. /**
  341. * Initialize interface upon startup. Return a successful no-op upon
  342. * subsequent invocations.
  343. */
  344. extern int jtag_interface_init(struct command_context_s* cmd_ctx);
  345. /// Shutdown the JTAG interface upon program exit.
  346. extern int jtag_interface_quit(void);
  347. /**
  348. * Initialize JTAG chain using only a RESET reset. If init fails,
  349. * try reset + init.
  350. */
  351. extern int jtag_init(struct command_context_s* cmd_ctx);
  352. /// reset, then initialize JTAG chain
  353. extern int jtag_init_reset(struct command_context_s* cmd_ctx);
  354. extern int jtag_register_commands(struct command_context_s* cmd_ctx);
  355. /**
  356. * @file
  357. * The JTAG interface can be implemented with a software or hardware fifo.
  358. *
  359. * TAP_DRSHIFT and TAP_IRSHIFT are illegal end states; however,
  360. * TAP_DRSHIFT/IRSHIFT can be emulated as end states, by using longer
  361. * scans.
  362. *
  363. * Code that is relatively insensitive to the path taken through state
  364. * machine (as long as it is JTAG compliant) can use @a endstate for
  365. * jtag_add_xxx_scan(). Otherwise, the pause state must be specified as
  366. * end state and a subsequent jtag_add_pathmove() must be issued.
  367. */
  368. extern void jtag_add_ir_scan(int num_fields, scan_field_t* fields, tap_state_t endstate);
  369. /**
  370. * The same as jtag_add_ir_scan except no verification is performed out
  371. * the output values.
  372. */
  373. extern void jtag_add_ir_scan_noverify(int num_fields, const scan_field_t *fields, tap_state_t state);
  374. /**
  375. * Set in_value to point to 32 bits of memory to scan into. This
  376. * function is a way to handle the case of synchronous and asynchronous
  377. * JTAG queues.
  378. *
  379. * In the event of an asynchronous queue execution the queue buffer
  380. * allocation method is used, for the synchronous case the temporary 32
  381. * bits come from the input field itself.
  382. */
  383. extern void jtag_alloc_in_value32(scan_field_t *field);
  384. extern void jtag_add_dr_scan(int num_fields, const scan_field_t* fields, tap_state_t endstate);
  385. /// A version of jtag_add_dr_scan() that uses the check_value/mask fields
  386. extern void jtag_add_dr_scan_check(int num_fields, scan_field_t* fields, tap_state_t endstate);
  387. extern void jtag_add_plain_ir_scan(int num_fields, const scan_field_t* fields, tap_state_t endstate);
  388. extern void jtag_add_plain_dr_scan(int num_fields, const scan_field_t* fields, tap_state_t endstate);
  389. /**
  390. * Defines a simple JTAG callback that can allow conversions on data
  391. * scanned in from an interface.
  392. *
  393. * This callback should only be used for conversion that cannot fail.
  394. * For conversion types or checks that can fail, use the more complete
  395. * variant: jtag_callback_t.
  396. */
  397. typedef void (*jtag_callback1_t)(u8 *in);
  398. /// A simpler version of jtag_add_callback4().
  399. extern void jtag_add_callback(jtag_callback1_t, u8 *in);
  400. /**
  401. * Defines the type of data passed to the jtag_callback_t interface.
  402. * The underlying type must allow storing an @c int or pointer type.
  403. */
  404. typedef intptr_t jtag_callback_data_t;
  405. /**
  406. * Defines the interface of the JTAG callback mechanism.
  407. *
  408. * @param in the pointer to the data clocked in
  409. * @param data1 An integer big enough to use as an @c int or a pointer.
  410. * @param data2 An integer big enough to use as an @c int or a pointer.
  411. * @param data3 An integer big enough to use as an @c int or a pointer.
  412. * @returns an error code
  413. */
  414. typedef int (*jtag_callback_t)(u8 *in, jtag_callback_data_t data1, jtag_callback_data_t data2, jtag_callback_data_t data3);
  415. /**
  416. * This callback can be executed immediately the queue has been flushed.
  417. *
  418. * The JTAG queue can be executed synchronously or asynchronously.
  419. * Typically for USB, the queue is executed asynchronously. For
  420. * low-latency interfaces, the queue may be executed synchronously.
  421. *
  422. * The callback mechanism is very general and does not make many
  423. * assumptions about what the callback does or what its arguments are.
  424. * These callbacks are typically executed *after* the *entire* JTAG
  425. * queue has been executed for e.g. USB interfaces, and they are
  426. * guaranteeed to be invoked in the order that they were queued.
  427. *
  428. * If the execution of the queue fails before the callbacks, then --
  429. * depending on driver implementation -- the callbacks may or may not be
  430. * invoked. @todo Can we make this behavior consistent?
  431. *
  432. * The strange name is due to C's lack of overloading using function
  433. * arguments.
  434. *
  435. * @param f The callback function to add.
  436. * @param in Typically used to point to the data to operate on.
  437. * Frequently this will be the data clocked in during a shift operation.
  438. * @param data1 An integer big enough to use as an @c int or a pointer.
  439. * @param data2 An integer big enough to use as an @c int or a pointer.
  440. * @param data3 An integer big enough to use as an @c int or a pointer.
  441. *
  442. */
  443. extern void jtag_add_callback4(jtag_callback_t f, u8 *in,
  444. jtag_callback_data_t data1, jtag_callback_data_t data2,
  445. jtag_callback_data_t data3);
  446. /**
  447. * Run a TAP_RESET reset where the end state is TAP_RESET,
  448. * regardless of the start state.
  449. */
  450. extern void jtag_add_tlr(void);
  451. /**
  452. * Application code *must* assume that interfaces will
  453. * implement transitions between states with different
  454. * paths and path lengths through the state diagram. The
  455. * path will vary across interface and also across versions
  456. * of the same interface over time. Even if the OpenOCD code
  457. * is unchanged, the actual path taken may vary over time
  458. * and versions of interface firmware or PCB revisions.
  459. *
  460. * Use jtag_add_pathmove() when specific transition sequences
  461. * are required.
  462. *
  463. * Do not use jtag_add_pathmove() unless you need to, but do use it
  464. * if you have to.
  465. *
  466. * DANGER! If the target is dependent upon a particular sequence
  467. * of transitions for things to work correctly(e.g. as a workaround
  468. * for an errata that contradicts the JTAG standard), then pathmove
  469. * must be used, even if some jtag interfaces happen to use the
  470. * desired path. Worse, the jtag interface used for testing a
  471. * particular implementation, could happen to use the "desired"
  472. * path when transitioning to/from end
  473. * state.
  474. *
  475. * A list of unambigious single clock state transitions, not
  476. * all drivers can support this, but it is required for e.g.
  477. * XScale and Xilinx support
  478. *
  479. * Note! TAP_RESET must not be used in the path!
  480. *
  481. * Note that the first on the list must be reachable
  482. * via a single transition from the current state.
  483. *
  484. * All drivers are required to implement jtag_add_pathmove().
  485. * However, if the pathmove sequence can not be precisely
  486. * executed, an interface_jtag_add_pathmove() or jtag_execute_queue()
  487. * must return an error. It is legal, but not recommended, that
  488. * a driver returns an error in all cases for a pathmove if it
  489. * can only implement a few transitions and therefore
  490. * a partial implementation of pathmove would have little practical
  491. * application.
  492. */
  493. extern void jtag_add_pathmove(int num_states, const tap_state_t* path);
  494. /**
  495. * Goes to TAP_IDLE (if we're not already there), cycle
  496. * precisely num_cycles in the TAP_IDLE state, after which move
  497. * to @a endstate (unless it is also TAP_IDLE).
  498. *
  499. * @param num_cycles Number of cycles in TAP_IDLE state. This argument
  500. * may be 0, in which case this routine will navigate to @a endstate
  501. * via TAP_IDLE.
  502. * @param endstate The final state.
  503. */
  504. extern void jtag_add_runtest(int num_cycles, tap_state_t endstate);
  505. /**
  506. * A reset of the TAP state machine can be requested.
  507. *
  508. * Whether tms or trst reset is used depends on the capabilities of
  509. * the target and jtag interface(reset_config command configures this).
  510. *
  511. * srst can driver a reset of the TAP state machine and vice
  512. * versa
  513. *
  514. * Application code may need to examine value of jtag_reset_config
  515. * to determine the proper codepath
  516. *
  517. * DANGER! Even though srst drives trst, trst might not be connected to
  518. * the interface, and it might actually be *harmful* to assert trst in this case.
  519. *
  520. * This is why combinations such as "reset_config srst_only srst_pulls_trst"
  521. * are supported.
  522. *
  523. * only req_tlr_or_trst and srst can have a transition for a
  524. * call as the effects of transitioning both at the "same time"
  525. * are undefined, but when srst_pulls_trst or vice versa,
  526. * then trst & srst *must* be asserted together.
  527. */
  528. extern void jtag_add_reset(int req_tlr_or_trst, int srst);
  529. extern void jtag_add_end_state(tap_state_t endstate);
  530. extern void jtag_add_sleep(u32 us);
  531. /**
  532. * Function jtag_add_stable_clocks
  533. * first checks that the state in which the clocks are to be issued is
  534. * stable, then queues up clock_count clocks for transmission.
  535. */
  536. void jtag_add_clocks(int num_cycles);
  537. /**
  538. * For software FIFO implementations, the queued commands can be executed
  539. * during this call or earlier. A sw queue might decide to push out
  540. * some of the jtag_add_xxx() operations once the queue is "big enough".
  541. *
  542. * This fn will return an error code if any of the prior jtag_add_xxx()
  543. * calls caused a failure, e.g. check failure. Note that it does not
  544. * matter if the operation was executed *before* jtag_execute_queue(),
  545. * jtag_execute_queue() will still return an error code.
  546. *
  547. * All jtag_add_xxx() calls that have in_handler!=NULL will have been
  548. * executed when this fn returns, but if what has been queued only
  549. * clocks data out, without reading anything back, then JTAG could
  550. * be running *after* jtag_execute_queue() returns. The API does
  551. * not define a way to flush a hw FIFO that runs *after*
  552. * jtag_execute_queue() returns.
  553. *
  554. * jtag_add_xxx() commands can either be executed immediately or
  555. * at some time between the jtag_add_xxx() fn call and jtag_execute_queue().
  556. */
  557. extern int jtag_execute_queue(void);
  558. /* same as jtag_execute_queue() but does not clear the error flag */
  559. extern void jtag_execute_queue_noclear(void);
  560. /**
  561. * The jtag_error variable is set when an error occurs while executing
  562. * the queue.
  563. *
  564. * This flag can also be set from application code, if an error happens
  565. * during processing that should be reported during jtag_execute_queue().
  566. *
  567. * It is cleared by jtag_execute_queue().
  568. */
  569. extern int jtag_error;
  570. static __inline__ void jtag_set_error(int error)
  571. {
  572. if ((error==ERROR_OK)||(jtag_error!=ERROR_OK))
  573. {
  574. /* keep first error */
  575. return;
  576. }
  577. jtag_error=error;
  578. }
  579. /* can be implemented by hw+sw */
  580. extern int jtag_power_dropout(int* dropout);
  581. extern int jtag_srst_asserted(int* srst_asserted);
  582. /* JTAG support functions */
  583. /**
  584. * Execute jtag queue and check value with an optional mask.
  585. * @param field Pointer to scan field.
  586. * @param value Pointer to scan value.
  587. * @param mask Pointer to scan mask; may be NULL.
  588. * @returns Nothing, but calls jtag_set_error() on any error.
  589. */
  590. extern void jtag_check_value_mask(scan_field_t *field, u8 *value, u8 *mask);
  591. #ifdef INCLUDE_JTAG_INTERFACE_H
  592. extern enum scan_type jtag_scan_type(const scan_command_t* cmd);
  593. extern int jtag_scan_size(const scan_command_t* cmd);
  594. extern int jtag_read_buffer(u8* buffer, const scan_command_t* cmd);
  595. extern int jtag_build_buffer(const scan_command_t* cmd, u8** buffer);
  596. #endif // INCLUDE_JTAG_INTERFACE_H
  597. extern void jtag_sleep(u32 us);
  598. extern int jtag_call_event_callbacks(enum jtag_event event);
  599. extern int jtag_register_event_callback(int (* callback)(enum jtag_event event, void* priv), void* priv);
  600. extern int jtag_verify_capture_ir;
  601. void jtag_tap_handle_event(jtag_tap_t* tap, enum jtag_tap_event e);
  602. /*
  603. * The JTAG subsystem defines a number of error codes,
  604. * using codes between -100 and -199.
  605. */
  606. #define ERROR_JTAG_INIT_FAILED (-100)
  607. #define ERROR_JTAG_INVALID_INTERFACE (-101)
  608. #define ERROR_JTAG_NOT_IMPLEMENTED (-102)
  609. #define ERROR_JTAG_TRST_ASSERTED (-103)
  610. #define ERROR_JTAG_QUEUE_FAILED (-104)
  611. #define ERROR_JTAG_NOT_STABLE_STATE (-105)
  612. #define ERROR_JTAG_DEVICE_ERROR (-107)
  613. /**
  614. * jtag_add_dr_out() is a version of jtag_add_dr_scan() which
  615. * only scans data out. It operates on 32 bit integers instead
  616. * of 8 bit, which makes it a better impedance match with
  617. * the calling code which often operate on 32 bit integers.
  618. *
  619. * Current or end_state can not be TAP_RESET. end_state can be TAP_INVALID
  620. *
  621. * num_bits[i] is the number of bits to clock out from value[i] LSB first.
  622. *
  623. * If the device is in bypass, then that is an error condition in
  624. * the caller code that is not detected by this fn, whereas
  625. * jtag_add_dr_scan() does detect it. Similarly if the device is not in
  626. * bypass, data must be passed to it.
  627. *
  628. * If anything fails, then jtag_error will be set and jtag_execute() will
  629. * return an error. There is no way to determine if there was a failure
  630. * during this function call.
  631. *
  632. * This is an inline fn to speed up embedded hosts. Also note that
  633. * interface_jtag_add_dr_out() can be a *small* inline function for
  634. * embedded hosts.
  635. *
  636. * There is no jtag_add_dr_outin() version of this fn that also allows
  637. * clocking data back in. Patches gladly accepted!
  638. */
  639. extern void jtag_add_dr_out(jtag_tap_t* tap,
  640. int num_fields, const int* num_bits, const u32* value,
  641. tap_state_t end_state);
  642. /**
  643. * jtag_add_statemove() moves from the current state to @a goal_state.
  644. *
  645. * This function was originally designed to handle the XSTATE command
  646. * from the XSVF specification.
  647. *
  648. * @param goal_state The final TAP state.
  649. * @return ERROR_OK on success, or an error code on failure.
  650. */
  651. extern int jtag_add_statemove(tap_state_t goal_state);
  652. #endif /* JTAG_H */