libztex.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * libztex.h - headers for Ztex 1.15x fpga board support library
  3. *
  4. * Copyright (c) 2012 nelisky.btc@gmail.com
  5. *
  6. * This work is based upon the Java SDK provided by ztex which is
  7. * Copyright (C) 2009-2011 ZTEX GmbH.
  8. * http://www.ztex.de
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, see http://www.gnu.org/licenses/.
  21. **/
  22. #ifndef __LIBZTEX_H__
  23. #define __LIBZTEX_H__
  24. #include <libusb-1.0/libusb.h>
  25. #define LIBZTEX_MAX_DESCRIPTORS 512
  26. #define LIBZTEX_SNSTRING_LEN 10
  27. #define LIBZTEX_IDVENDOR 0x221A
  28. #define LIBZTEX_IDPRODUCT 0x0100
  29. #define LIBZTEX_MAXMAXERRORRATE 0.05
  30. #define LIBZTEX_ERRORHYSTERESIS 0.1
  31. #define LIBZTEX_OVERHEATTHRESHOLD 0.4
  32. struct libztex_fpgastate {
  33. bool fpgaConfigured;
  34. unsigned char fpgaChecksum;
  35. uint16_t fpgaBytes;
  36. unsigned char fpgaInitB;
  37. unsigned char fpgaFlashResult;
  38. bool fpgaFlashBitSwap;
  39. };
  40. struct libztex_device {
  41. pthread_mutex_t mutex;
  42. struct libztex_device *root;
  43. int fpgaNum;
  44. bool valid;
  45. struct libusb_device_descriptor descriptor;
  46. libusb_device_handle *hndl;
  47. unsigned char usbbus;
  48. unsigned char usbaddress;
  49. unsigned char snString[LIBZTEX_SNSTRING_LEN+1];
  50. unsigned char productId[4];
  51. unsigned char fwVersion;
  52. unsigned char interfaceVersion;
  53. unsigned char interfaceCapabilities[6];
  54. unsigned char moduleReserved[12];
  55. uint8_t numNonces;
  56. uint16_t offsNonces;
  57. double freqM1;
  58. uint8_t freqM;
  59. uint8_t freqMaxM;
  60. uint8_t freqMDefault;
  61. char* bitFileName;
  62. bool suspendSupported;
  63. double hashesPerClock;
  64. uint8_t extraSolutions;
  65. double errorCount[256];
  66. double errorWeight[256];
  67. double errorRate[256];
  68. double maxErrorRate[256];
  69. int numberOfFpgas;
  70. int selectedFpga;
  71. bool parallelConfigSupport;
  72. char repr[20];
  73. };
  74. struct libztex_dev_list {
  75. struct libztex_device *dev;
  76. struct libztex_dev_list *next;
  77. };
  78. struct libztex_hash_data {
  79. uint32_t goldenNonce[2];
  80. uint32_t nonce;
  81. uint32_t hash7;
  82. };
  83. extern int libztex_scanDevices (struct libztex_dev_list ***devs);
  84. extern void libztex_freeDevList (struct libztex_dev_list **devs);
  85. extern int libztex_prepare_device (struct libusb_device *dev, struct libztex_device** ztex);
  86. extern void libztex_destroy_device (struct libztex_device* ztex);
  87. extern int libztex_configureFpga (struct libztex_device *dev);
  88. extern int libztex_setFreq (struct libztex_device *ztex, uint16_t freq);
  89. extern int libztex_sendHashData (struct libztex_device *ztex, unsigned char *sendbuf);
  90. extern int libztex_readHashData (struct libztex_device *ztex, struct libztex_hash_data nonces[]);
  91. extern int libztex_resetFpga (struct libztex_device *ztex);
  92. extern int libztex_selectFpga(struct libztex_device *ztex);
  93. extern int libztex_numberOfFpgas(struct libztex_device *ztex);
  94. #endif /* __LIBZTEX_H__ */