jtag.h 1.4 KB

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