fpgautils.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. struct device_drv;
  8. struct cgpu_info;
  9. typedef bool(*detectone_func_t)(const char*);
  10. typedef int(*autoscan_func_t)();
  11. extern int _serial_detect(struct device_drv *api, detectone_func_t, autoscan_func_t, int flags);
  12. #define serial_detect_fauto(api, detectone, autoscan) \
  13. _serial_detect(api, detectone, autoscan, 1)
  14. #define serial_detect_auto(api, detectone, autoscan) \
  15. _serial_detect(api, detectone, autoscan, 0)
  16. #define serial_detect_auto_byname(api, detectone, autoscan) \
  17. _serial_detect(api, detectone, autoscan, 2)
  18. #define serial_detect(api, detectone) \
  19. _serial_detect(api, detectone, NULL, 0)
  20. #define serial_detect_byname(api, detectone) \
  21. _serial_detect(api, detectone, NULL, 2)
  22. #define noserial_detect(api, autoscan) \
  23. _serial_detect(api, NULL , autoscan, 0)
  24. extern int _serial_autodetect(detectone_func_t, ...);
  25. #define serial_autodetect(...) _serial_autodetect(__VA_ARGS__, NULL)
  26. extern struct device_drv *bfg_claim_serial(struct device_drv * const, const bool verbose, const char * const devpath);
  27. #define serial_claim(devpath, drv) bfg_claim_serial(drv, false, devpath)
  28. #define serial_claim_v(devpath, drv) bfg_claim_serial(drv, true , devpath)
  29. extern struct device_drv *bfg_claim_usb(struct device_drv * const, const bool verbose, const uint8_t usbbus, const uint8_t usbaddr);
  30. extern int serial_open(const char *devpath, unsigned long baud, uint8_t timeout, bool purge);
  31. extern ssize_t _serial_read(int fd, char *buf, size_t buflen, char *eol);
  32. #define serial_read(fd, buf, count) \
  33. _serial_read(fd, (char*)(buf), count, NULL)
  34. #define serial_read_line(fd, buf, bufsiz, eol) \
  35. _serial_read(fd, buf, bufsiz, &eol)
  36. #define serial_close(fd) close(fd)
  37. extern FILE *open_bitstream(const char *dname, const char *filename);
  38. extern FILE *open_xilinx_bitstream(const char *dname, const char *repr, const char *fwfile, unsigned long *out_len);
  39. extern int get_serial_cts(int fd);
  40. #endif