jtag.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright 2012 Luke Dashjr
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the Free
  6. * Software Foundation; either version 3 of the License, or (at your option)
  7. * any later version. See COPYING for more details.
  8. */
  9. #ifndef BFGMINER_JTAG_H
  10. #define BFGMINER_JTAG_H
  11. #include <stdbool.h>
  12. #include <stdint.h>
  13. #include <unistd.h>
  14. struct jtag_port_a {
  15. struct ft232r_device_handle *ftdi;
  16. uint8_t state;
  17. bool async;
  18. uint8_t bufread;
  19. };
  20. struct jtag_port {
  21. struct jtag_port_a *a;
  22. uint8_t tck;
  23. uint8_t tms;
  24. uint8_t tdi;
  25. uint8_t tdo;
  26. uint8_t ignored;
  27. };
  28. enum jtagreg {
  29. JTAG_REG_DR,
  30. JTAG_REG_IR,
  31. };
  32. extern bool jtag_clock(struct jtag_port *, bool tms, bool tdi, bool *tdo);
  33. extern bool _jtag_llrw(struct jtag_port *, void *buf, size_t bitlength, bool do_read, int stage);
  34. extern bool jtag_reset(struct jtag_port *);
  35. extern ssize_t jtag_detect(struct jtag_port *);
  36. extern bool _jtag_rw(struct jtag_port *, enum jtagreg r, void *buf, size_t bitlength, bool do_read, int stage);
  37. #define jtag_read(jp, r, data, bitlen) _jtag_rw(jp, r, data, bitlen, true, 0xff)
  38. #define jtag_sread(jp, r, data, bitlen) _jtag_rw(jp, r, data, bitlen, true, 1)
  39. #define jtag_sread_more(jp, data, bitlen, finish) _jtag_llrw(jp, data, bitlen, true, (finish) ? 2 : 0)
  40. // Cast is used to accept const data - while it ignores the compiler attribute, it still won't modify the data
  41. #define jtag_write(jp, r, data, bitlen) _jtag_rw(jp, r, (void*)data, bitlen, false, 0xff)
  42. #define jtag_swrite(jp, r, data, bitlen) _jtag_rw(jp, r, (void*)data, bitlen, false, 1)
  43. #define jtag_swrite_more(jp, data, bitlen, finish) _jtag_llrw(jp, (void*)data, bitlen, false, (finish) ? 2 : 0)
  44. extern bool jtag_run(struct jtag_port *);
  45. #endif