fpgautils.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. extern int get_serial_cts(int fd);
  33. #ifndef WIN32
  34. extern const struct timeval tv_timeout_default;
  35. extern const struct timeval tv_inter_char_default;
  36. extern size_t _select_read(int fd, char *buf, size_t bufsiz, struct timeval *timeout, struct timeval *char_timeout, int finished);
  37. extern size_t _select_write(int fd, char *buf, size_t siz, struct timeval *timeout);
  38. #define select_open(devpath) \
  39. serial_open(devpath, 0, 0, false)
  40. #define select_open_purge(devpath, purge)\
  41. serial_open(devpath, 0, 0, purge)
  42. #define select_write(fd, buf, siz) \
  43. _select_write(fd, buf, siz, (struct timeval *)(&tv_timeout_default))
  44. #define select_write_full _select_write
  45. #define select_read(fd, buf, bufsiz) \
  46. _select_read(fd, buf, bufsiz, (struct timeval *)(&tv_timeout_default), \
  47. (struct timeval *)(&tv_inter_char_default), -1)
  48. #define select_read_til(fd, buf, bufsiz, eol) \
  49. _select_read(fd, buf, bufsiz, (struct timeval *)(&tv_timeout_default), \
  50. (struct timeval *)(&tv_inter_char_default), eol)
  51. #define select_read_wait(fd, buf, bufsiz, timeout) \
  52. _select_read(fd, buf, bufsiz, timeout, \
  53. (struct timeval *)(&tv_inter_char_default), -1)
  54. #define select_read_wait_til(fd, buf, bufsiz, timeout, eol) \
  55. _select_read(fd, buf, bufsiz, timeout, \
  56. (struct timeval *)(&tv_inter_char_default), eol)
  57. #define select_read_wait_both(fd, buf, bufsiz, timeout, char_timeout) \
  58. _select_read(fd, buf, bufsiz, timeout, char_timeout, -1)
  59. #define select_read_full _select_read
  60. #define select_close(fd) close(fd)
  61. #endif // ! WIN32
  62. #endif