fpgautils.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. #include "deviceapi.h"
  11. struct device_drv;
  12. struct cgpu_info;
  13. struct detectone_meta_info_t {
  14. const char *manufacturer;
  15. const char *product;
  16. const char *serial;
  17. };
  18. // NOTE: Should detectone become run multithreaded, this will become a threadsafe #define
  19. extern struct detectone_meta_info_t detectone_meta_info;
  20. extern void clear_detectone_meta_info(void);
  21. extern int _serial_autodetect(detectone_func_t, ...);
  22. #define serial_autodetect(...) _serial_autodetect(__VA_ARGS__, NULL)
  23. extern struct device_drv *bfg_claim_serial(struct device_drv * const, const bool verbose, const char * const devpath);
  24. #define serial_claim(devpath, drv) bfg_claim_serial(drv, false, devpath)
  25. #define serial_claim_v(devpath, drv) bfg_claim_serial(drv, true , devpath)
  26. extern struct device_drv *bfg_claim_usb(struct device_drv * const, const bool verbose, const uint8_t usbbus, const uint8_t usbaddr);
  27. #define bfg_claim_libusb(api, verbose, dev) bfg_claim_usb(api, verbose, libusb_get_bus_number(dev), libusb_get_device_address(dev))
  28. #ifdef HAVE_LIBUSB
  29. extern void cgpu_copy_libusb_strings(struct cgpu_info *, libusb_device *);
  30. #endif
  31. extern int serial_open(const char *devpath, unsigned long baud, uint8_t timeout, bool purge);
  32. extern ssize_t _serial_read(int fd, char *buf, size_t buflen, char *eol);
  33. #define serial_read(fd, buf, count) \
  34. _serial_read(fd, (char*)(buf), count, NULL)
  35. #define serial_read_line(fd, buf, bufsiz, eol) \
  36. _serial_read(fd, buf, bufsiz, &eol)
  37. #define serial_close(fd) close(fd)
  38. extern FILE *open_xilinx_bitstream(const char *dname, const char *repr, const char *fwfile, unsigned long *out_len);
  39. extern bool load_bitstream_intelhex(bytes_t *out, const char *dname, const char *fn);
  40. extern bool load_bitstream_bytes(bytes_t *out, const char *dname, const char *fileprefix);
  41. extern int get_serial_cts(int fd);
  42. extern bool valid_baud(int baud);
  43. #endif