fpgautils.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 <stdint.h>
  13. #include <stdio.h>
  14. #include <unistd.h>
  15. typedef bool(*detectone_func_t)(const char*);
  16. typedef int(*autoscan_func_t)();
  17. extern int _serial_detect(const char*dname, detectone_func_t, autoscan_func_t, int flags);
  18. #define serial_detect_fauto(dname, detectone, autoscan) \
  19. _serial_detect(dname, detectone, autoscan, 1)
  20. #define serial_detect_auto(dname, detectone, autoscan) \
  21. _serial_detect(dname, detectone, autoscan, 0)
  22. #define serial_detect_auto_byname(dname, detectone, autoscan) \
  23. _serial_detect(dname, detectone, autoscan, 2)
  24. #define serial_detect(dname, detectone) \
  25. _serial_detect(dname, detectone, NULL, 0)
  26. #define noserial_detect(dname, autoscan) \
  27. _serial_detect(dname, NULL , autoscan, 0)
  28. extern int serial_autodetect_devserial(detectone_func_t, const char*prodname);
  29. extern int serial_autodetect_udev (detectone_func_t, const char*prodname);
  30. extern int serial_autodetect_ftdi (detectone_func_t, const char*needle, const char *needle2);
  31. extern struct device_api *serial_claim(const char *devpath, struct device_api *);
  32. extern int serial_open(const char*devpath, unsigned long baud, uint8_t timeout, bool purge);
  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, count, &eol)
  38. #define serial_close(fd) close(fd)
  39. extern FILE*open_bitstream(const char*dname, const char*filename);
  40. #endif