fpgautils.h 2.9 KB

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