driver-icarus.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright 2012-2014 Luke Dashjr
  3. * Copyright 2014 Nate Woolls
  4. * Copyright 2012 Xiangfu
  5. * Copyright 2012 Andrew Smith
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the Free
  9. * Software Foundation; either version 3 of the License, or (at your option)
  10. * any later version. See COPYING for more details.
  11. */
  12. #ifndef BFG_DRIVER_ICARUS_H
  13. #define BFG_DRIVER_ICARUS_H
  14. #include <stdbool.h>
  15. #include <stdint.h>
  16. #include <sys/time.h>
  17. #include "dynclock.h"
  18. #include "miner.h"
  19. // Fraction of a second, USB timeout is measured in
  20. // i.e. 10 means 1/10 of a second
  21. // Right now, it MUST be 10 due to other assumptions.
  22. #define TIME_FACTOR 10
  23. // It's 10 per second, thus value = 10/TIME_FACTOR =
  24. #define ICARUS_READ_FAULT_DECISECONDS 1
  25. #define NANOSEC 1000000000.0
  26. // Default value for ICARUS_INFO->read_size
  27. #define ICARUS_DEFAULT_READ_SIZE 4
  28. #define ICA_GETS_ERROR -1
  29. #define ICA_GETS_OK 0
  30. #define ICA_GETS_RESTART 1
  31. #define ICA_GETS_TIMEOUT 2
  32. // Store the last INFO_HISTORY data sets
  33. // [0] = current data, not yet ready to be included as an estimate
  34. // Each new data set throws the last old set off the end thus
  35. // keeping a ongoing average of recent data
  36. #define INFO_HISTORY 10
  37. extern struct device_drv icarus_drv;
  38. struct ICARUS_HISTORY {
  39. struct timeval finish;
  40. double sumXiTi;
  41. double sumXi;
  42. double sumTi;
  43. double sumXi2;
  44. uint32_t values;
  45. uint32_t hash_count_min;
  46. uint32_t hash_count_max;
  47. };
  48. enum timing_mode { MODE_DEFAULT, MODE_SHORT, MODE_LONG, MODE_VALUE };
  49. enum icarus_reopen_mode {
  50. IRM_NEVER,
  51. IRM_TIMEOUT,
  52. IRM_CYCLE,
  53. };
  54. enum icarus_user_settings {
  55. IUS_WORK_DIVISION = 1,
  56. IUS_FPGA_COUNT = 2,
  57. };
  58. struct ICARUS_INFO {
  59. // time to calculate the golden_ob
  60. struct timeval golden_tv;
  61. // History structures for calculating read_count
  62. // when info->do_icarus_timing is true
  63. struct ICARUS_HISTORY history[INFO_HISTORY+1];
  64. uint32_t min_data_count;
  65. // Timeout scanning for a nonce (deciseconds)
  66. int read_count;
  67. // Timeout scanning for a golden nonce (deciseconds)
  68. int probe_read_count;
  69. // ds limit for (short=/long=) read_count
  70. int read_count_limit;
  71. enum timing_mode timing_mode;
  72. bool do_icarus_timing;
  73. int do_default_detection;
  74. double fullnonce;
  75. int count;
  76. double W;
  77. uint32_t values;
  78. uint64_t hash_count_range;
  79. // Determine the cost of history processing
  80. // (which will only affect W)
  81. uint64_t history_count;
  82. struct timeval history_time;
  83. // icarus-options
  84. int baud;
  85. // Used to calculate / display hash count when nonce is NOT found
  86. // seconds per Hash
  87. double Hs;
  88. // Used to calculate / display hash count when a nonce is found
  89. int work_division;
  90. int fpga_count;
  91. uint32_t nonce_mask;
  92. enum icarus_reopen_mode reopen_mode;
  93. bool reopen_now;
  94. uint8_t user_set;
  95. bool continue_search;
  96. dclk_change_clock_func_t dclk_change_clock_func;
  97. struct dclk_data dclk;
  98. // Bytes to read from Icarus for nonce
  99. int read_size;
  100. // Settings used when probing / detecting
  101. size_t ob_size;
  102. const char *golden_ob;
  103. const char *golden_nonce;
  104. bool nonce_littleendian;
  105. // Don't check the golden nonce returned when probing
  106. bool ignore_golden_nonce;
  107. // Custom driver functions
  108. bool (*detect_init_func)(const char *devpath, int fd, struct ICARUS_INFO *);
  109. bool (*job_start_func)(struct thr_info *);
  110. #ifdef USE_DUALMINER
  111. bool dual_mode;
  112. #endif
  113. #ifdef USE_ZEUSMINER
  114. // Hardware information, doesn't affect anything directly
  115. uint16_t freq;
  116. uint16_t chips;
  117. #endif
  118. };
  119. struct icarus_state {
  120. bool firstrun;
  121. struct timeval tv_workstart;
  122. struct timeval tv_workfinish;
  123. struct work *last_work;
  124. struct work *last2_work;
  125. bool changework;
  126. bool identify;
  127. uint8_t *ob_bin;
  128. };
  129. bool icarus_detect_custom(const char *devpath, struct device_drv *, struct ICARUS_INFO *);
  130. extern int icarus_gets(unsigned char *, int fd, struct timeval *tv_finish, struct thr_info *, int read_count, int read_size);
  131. extern int icarus_write(int fd, const void *buf, size_t bufLen);
  132. extern bool icarus_init(struct thr_info *);
  133. extern void do_icarus_close(struct thr_info *thr);
  134. extern bool icarus_job_start(struct thr_info *);
  135. #endif