jtag.h 1.4 KB

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