fpgautils.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef FPGAUTILS_H
  2. #define FPGAUTILS_H
  3. #include <stdbool.h>
  4. #include <stdint.h>
  5. #include <stdio.h>
  6. #include <unistd.h>
  7. #ifdef HAVE_LIBUSB
  8. #include <libusb.h>
  9. #endif
  10. struct device_drv;
  11. struct cgpu_info;
  12. struct detectone_meta_info_t {
  13. const char *manufacturer;
  14. const char *product;
  15. const char *serial;
  16. };
  17. // NOTE: Should detectone become run multithreaded, this will become a threadsafe #define
  18. extern struct detectone_meta_info_t detectone_meta_info;
  19. typedef bool(*detectone_func_t)(const char*);
  20. typedef int(*autoscan_func_t)();
  21. extern int _serial_detect(struct device_drv *api, detectone_func_t, autoscan_func_t, int flags);
  22. #define serial_detect_fauto(api, detectone, autoscan) \
  23. _serial_detect(api, detectone, autoscan, 1)
  24. #define serial_detect_auto(api, detectone, autoscan) \
  25. _serial_detect(api, detectone, autoscan, 0)
  26. #define serial_detect_auto_byname(api, detectone, autoscan) \
  27. _serial_detect(api, detectone, autoscan, 2)
  28. #define serial_detect(api, detectone) \
  29. _serial_detect(api, detectone, NULL, 0)
  30. #define serial_detect_byname(api, detectone) \
  31. _serial_detect(api, detectone, NULL, 2)
  32. #define noserial_detect(api, autoscan) \
  33. _serial_detect(api, NULL , autoscan, 0)
  34. #define noserial_detect_manual(api, autoscan) \
  35. _serial_detect(api, NULL , autoscan, 4)
  36. extern int _serial_autodetect(detectone_func_t, ...);
  37. #define serial_autodetect(...) _serial_autodetect(__VA_ARGS__, NULL)
  38. extern struct device_drv *bfg_claim_serial(struct device_drv * const, const bool verbose, const char * const devpath);
  39. #define serial_claim(devpath, drv) bfg_claim_serial(drv, false, devpath)
  40. #define serial_claim_v(devpath, drv) bfg_claim_serial(drv, true , devpath)
  41. extern struct device_drv *bfg_claim_usb(struct device_drv * const, const bool verbose, const uint8_t usbbus, const uint8_t usbaddr);
  42. #define bfg_claim_libusb(api, verbose, dev) bfg_claim_usb(api, verbose, libusb_get_bus_number(dev), libusb_get_device_address(dev))
  43. #ifdef HAVE_LIBUSB
  44. extern void cgpu_copy_libusb_strings(struct cgpu_info *, libusb_device *);
  45. #endif
  46. extern int serial_open(const char *devpath, unsigned long baud, uint8_t timeout, bool purge);
  47. extern ssize_t _serial_read(int fd, char *buf, size_t buflen, char *eol);
  48. #define serial_read(fd, buf, count) \
  49. _serial_read(fd, (char*)(buf), count, NULL)
  50. #define serial_read_line(fd, buf, bufsiz, eol) \
  51. _serial_read(fd, buf, bufsiz, &eol)
  52. #define serial_close(fd) close(fd)
  53. extern FILE *open_bitstream(const char *dname, const char *filename);
  54. extern FILE *open_xilinx_bitstream(const char *dname, const char *repr, const char *fwfile, unsigned long *out_len);
  55. extern int get_serial_cts(int fd);
  56. extern bool valid_baud(int baud);
  57. #endif