jtag.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #ifndef BFGMINER_JTAG_H
  2. #define BFGMINER_JTAG_H
  3. #include <stdbool.h>
  4. #include <stdint.h>
  5. #include <unistd.h>
  6. struct jtag_port_a {
  7. struct ft232r_device_handle *ftdi;
  8. uint8_t state;
  9. bool async;
  10. uint8_t bufread;
  11. };
  12. struct jtag_port {
  13. struct jtag_port_a *a;
  14. uint8_t tck;
  15. uint8_t tms;
  16. uint8_t tdi;
  17. uint8_t tdo;
  18. uint8_t ignored;
  19. };
  20. enum jtagreg {
  21. JTAG_REG_DR,
  22. JTAG_REG_IR,
  23. };
  24. extern bool jtag_clock(struct jtag_port *, bool tms, bool tdi, bool *tdo);
  25. extern bool _jtag_llrw(struct jtag_port *, void *buf, size_t bitlength, bool do_read, int stage);
  26. extern bool jtag_reset(struct jtag_port *);
  27. extern ssize_t jtag_detect(struct jtag_port *);
  28. extern bool _jtag_rw(struct jtag_port *, enum jtagreg r, void *buf, size_t bitlength, bool do_read, int stage);
  29. #define jtag_read(jp, r, data, bitlen) _jtag_rw(jp, r, data, bitlen, true, 0xff)
  30. #define jtag_sread(jp, r, data, bitlen) _jtag_rw(jp, r, data, bitlen, true, 1)
  31. #define jtag_sread_more(jp, data, bitlen, finish) _jtag_llrw(jp, data, bitlen, true, (finish) ? 2 : 0)
  32. // Cast is used to accept const data - while it ignores the compiler attribute, it still won't modify the data
  33. #define jtag_write(jp, r, data, bitlen) _jtag_rw(jp, r, (void*)data, bitlen, false, 0xff)
  34. #define jtag_swrite(jp, r, data, bitlen) _jtag_rw(jp, r, (void*)data, bitlen, false, 1)
  35. #define jtag_swrite_more(jp, data, bitlen, finish) _jtag_llrw(jp, (void*)data, bitlen, false, (finish) ? 2 : 0)
  36. extern bool jtag_run(struct jtag_port *);
  37. #endif