jtag.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #pragma once
  2. #ifndef MAKE_TAPROUTE_C
  3. # include "common.h"
  4. #else
  5. # define extern_c extern
  6. #endif
  7. enum TAP_STATE
  8. {
  9. TAP_TEST_LOGIC_RESET = 0,
  10. TAP_RUN_TEST_IDLE = 1,
  11. TAP_SELECT_DR_SCAN = 2,
  12. TAP_CAPTURE_DR = 3,
  13. TAP_SHIFT_DR = 4,
  14. TAP_EXIT1_DR = 5,
  15. TAP_PAUSE_DR = 6,
  16. TAP_EXIT2_DR = 7,
  17. TAP_UPDATE_DR = 8,
  18. TAP_SELECT_IR_SCAN = 9,
  19. TAP_CAPTURE_IR = 10,
  20. TAP_SHIFT_IR = 11,
  21. TAP_EXIT1_IR = 12,
  22. TAP_PAUSE_IR = 13,
  23. TAP_EXIT2_IR = 14,
  24. TAP_UPDATE_IR = 15
  25. };
  26. /*
  27. * Short (3-letter) name of states (tap.c)
  28. */
  29. extern_c const char tap_state_names[16][4];
  30. /*
  31. * Where to we end up if we do a transition [state][tms]? (tap.c)
  32. */
  33. extern_c const uint8_t tap_state_next[16][2];
  34. /*
  35. * Bitmap to get to state [to]: use TMS in bit #from
  36. * (repeat until from == to). (taproute.c)
  37. */
  38. extern_c const uint16_t tap_state_route[16];
  39. #ifndef MAKE_TAPROUTE_C
  40. enum jtag_io_flags {
  41. JIO_TDI = 1, /* TDI high if tdi == NULL */
  42. JIO_TMS = 2, /* TMS high on last clock (go to EXIT1) */
  43. JIO_CS = 4 /* Raise TMS *after* the last clock (used for SPI) */
  44. };
  45. struct jtag_config {
  46. unsigned long hz; /* JTAG frequency */
  47. uint8_t pin_tdi; /* TDI/MOSI */
  48. uint8_t pin_tdo; /* TDO/MISO */
  49. uint8_t pin_tms; /* TMS/CS# */
  50. uint8_t pin_tck; /* TCK/SCLK */
  51. bool be; /* Bigendian (for SPI) */
  52. };
  53. typedef struct spz_stream spz_stream;
  54. /*
  55. * Low-level TAP hardware operation interface
  56. */
  57. extern_c int jtag_init(void);
  58. extern_c int jtag_enable(const struct jtag_config *);
  59. extern_c int jtag_disable(const struct jtag_config *);
  60. extern_c int jtag_goto_state(enum TAP_STATE state);
  61. extern_c int jtag_set_tms(bool tms);
  62. extern_c void jtag_delay(unsigned int us);
  63. extern_c uint32_t jtag_pulse(unsigned int bits, uint32_t tdi, uint32_t tms);
  64. extern_c int jtag_io(unsigned int bits, enum jtag_io_flags flags,
  65. const void *tdi, void *tdo);
  66. extern_c int jtag_shift_spz(spz_stream *spz, enum jtag_io_flags flags);
  67. extern_c int tap_goto_state(enum TAP_STATE state);
  68. extern_c int tap_reset(void);
  69. extern_c void tap_set_ir(uint32_t ir, unsigned int bits);
  70. extern_c void tap_run_test_idle(unsigned int clocks);
  71. #endif /* MAKE_TAPROUTE_C */