libztex.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.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.5
  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. bool valid;
  42. struct libusb_device_descriptor descriptor;
  43. libusb_device_handle *hndl;
  44. unsigned char usbbus;
  45. unsigned char usbaddress;
  46. unsigned char snString[LIBZTEX_SNSTRING_LEN+1];
  47. unsigned char productId[4];
  48. unsigned char fwVersion;
  49. unsigned char interfaceVersion;
  50. unsigned char interfaceCapabilities[6];
  51. unsigned char moduleReserved[12];
  52. uint8_t numNonces;
  53. uint16_t offsNonces;
  54. uint16_t freqM1;
  55. uint8_t freqM;
  56. uint8_t freqMaxM;
  57. uint8_t freqMDefault;
  58. char* bitFileName;
  59. double errorCount[256];
  60. double errorWeight[256];
  61. double errorRate[256];
  62. double maxErrorRate[256];
  63. char repr[64];
  64. };
  65. struct libztex_dev_list {
  66. struct libztex_device *dev;
  67. struct libztex_dev_list *next;
  68. };
  69. struct libztex_hash_data {
  70. uint32_t goldenNonce;
  71. uint32_t nonce;
  72. uint32_t hash7;
  73. };
  74. extern int libztex_scanDevices (struct libztex_dev_list ***devs);
  75. extern void libztex_freeDevList (struct libztex_dev_list **devs);
  76. extern void libztex_destroy_device (struct libztex_device* ztex);
  77. extern int libztex_configureFpga (struct libztex_device *dev);
  78. extern int libztex_setFreq (struct libztex_device *ztex, uint16_t freq);
  79. extern int libztex_sendHashData (struct libztex_device *ztex, unsigned char *sendbuf);
  80. extern int libztex_readHashData (struct libztex_device *ztex, struct libztex_hash_data nonces[]);
  81. extern int libztex_resetFpga (struct libztex_device *ztex);
  82. #endif /* __LIBZTEX_H__ */