fpgautils.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 FPGAUTILS_H
  10. #define FPGAUTILS_H
  11. #include <stdbool.h>
  12. #include <stdio.h>
  13. #include "miner.h"
  14. typedef bool(*detectone_func_t)(const char*);
  15. typedef int(*autoscan_func_t)();
  16. #ifdef WIN32
  17. extern ssize_t win32read(int fd, void *buf, size_t count);
  18. extern ssize_t win32write(int fd, const void *buf, size_t count);
  19. #endif
  20. extern int _serial_detect(struct device_drv *drv, detectone_func_t, autoscan_func_t, bool force_autoscan, bool inhibit_autoscan);
  21. #define serial_detect_fauto(drv, detectone, autoscan) \
  22. _serial_detect(drv, detectone, autoscan, true, false)
  23. #define serial_detect_iauto(drv, detectone, autoscan) \
  24. _serial_detect(drv, detectone, autoscan, false, true)
  25. #define serial_detect_auto(drv, detectone, autoscan) \
  26. _serial_detect(drv, detectone, autoscan, false, false)
  27. #define serial_detect(drv, detectone) \
  28. _serial_detect(drv, detectone, NULL, false, false)
  29. extern int serial_autodetect_devserial(detectone_func_t, const char *prodname);
  30. extern int serial_autodetect_udev(detectone_func_t, const char *prodname);
  31. #define serial_open(dev,baud,timeout,purge) serial_open_ex(dev, baud, timeout, 0, purge, false)
  32. extern int serial_open_ex(const char *devpath, unsigned long baud, signed short timeout, signed short minbytes, bool purge, bool win32overlapped);
  33. extern ssize_t _serial_read(int fd, char *buf, size_t buflen, char *eol);
  34. #define serial_read(fd, buf, count) \
  35. _serial_read(fd, (char*)(buf), count, NULL)
  36. #define serial_read_line(fd, buf, bufsiz, eol) \
  37. _serial_read(fd, buf, bufsiz, &eol)
  38. #define serial_close(fd) close(fd)
  39. extern FILE *open_bitstream(const char *dname, const char *filename);
  40. extern int get_serial_cts(int fd);
  41. #ifndef WIN32
  42. extern const struct timeval tv_timeout_default;
  43. extern const struct timeval tv_inter_char_default;
  44. extern size_t _select_read(int fd, char *buf, size_t bufsiz, struct timeval *timeout, struct timeval *char_timeout, int finished);
  45. extern size_t _select_write(int fd, char *buf, size_t siz, struct timeval *timeout);
  46. #define select_open(devpath) \
  47. serial_open(devpath, 0, 0, false)
  48. #define select_open_purge(devpath, purge)\
  49. serial_open(devpath, 0, 0, purge)
  50. #define select_write(fd, buf, siz) \
  51. _select_write(fd, buf, siz, (struct timeval *)(&tv_timeout_default))
  52. #define select_write_full _select_write
  53. #define select_read(fd, buf, bufsiz) \
  54. _select_read(fd, buf, bufsiz, (struct timeval *)(&tv_timeout_default), \
  55. (struct timeval *)(&tv_inter_char_default), -1)
  56. #define select_read_til(fd, buf, bufsiz, eol) \
  57. _select_read(fd, buf, bufsiz, (struct timeval *)(&tv_timeout_default), \
  58. (struct timeval *)(&tv_inter_char_default), eol)
  59. #define select_read_wait(fd, buf, bufsiz, timeout) \
  60. _select_read(fd, buf, bufsiz, timeout, \
  61. (struct timeval *)(&tv_inter_char_default), -1)
  62. #define select_read_wait_til(fd, buf, bufsiz, timeout, eol) \
  63. _select_read(fd, buf, bufsiz, timeout, \
  64. (struct timeval *)(&tv_inter_char_default), eol)
  65. #define select_read_wait_both(fd, buf, bufsiz, timeout, char_timeout) \
  66. _select_read(fd, buf, bufsiz, timeout, char_timeout, -1)
  67. #define select_read_full _select_read
  68. #define select_close(fd) close(fd)
  69. #endif // ! WIN32
  70. #endif