driver-gekko.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #include "math.h"
  2. #include "miner.h"
  3. #include "usbutils.h"
  4. #if defined(WIN32) || defined(__APPLE__)
  5. #define thread_yield() sched_yield()
  6. #else
  7. #define thread_yield() pthread_yield(NULL)
  8. #endif
  9. #define JOB_MAX 0x7F
  10. #define BUFFER_MAX 0xFF
  11. enum miner_state {
  12. MINER_INIT = 1,
  13. MINER_CHIP_COUNT,
  14. MINER_CHIP_COUNT_XX,
  15. MINER_CHIP_COUNT_OK,
  16. MINER_OPEN_CORE,
  17. MINER_OPEN_CORE_OK,
  18. MINER_MINING,
  19. MINER_MINING_DUPS,
  20. MINER_SHUTDOWN,
  21. MINER_SHUTDOWN_OK,
  22. MINER_RESET
  23. };
  24. enum miner_asic {
  25. BM1384 = 1,
  26. BM1387
  27. };
  28. enum micro_command {
  29. M1_GET_FAN = (0x00 << 3),
  30. M1_GET_RPM = (0x01 << 3),
  31. M1_GET_VIN = (0x02 << 3),
  32. M1_GET_IIN = (0x03 << 3),
  33. M1_GET_TEMP = (0x04 << 3),
  34. M1_GET_VNODE0 = (0x05 << 3),
  35. M1_CLR_BEN = (0x08 << 3),
  36. M1_SET_BEN = (0x09 << 3),
  37. M1_CLR_LED = (0x0A << 3),
  38. M1_SET_LED = (0x0B << 3),
  39. M1_CLR_RST = (0x0C << 3),
  40. M1_SET_RST = (0x0D << 3),
  41. M2_SET_FAN = (0x18 << 3),
  42. M2_SET_VCORE = (0x1C << 3)
  43. };
  44. struct COMPAC_INFO {
  45. enum sub_ident ident; // Miner identity
  46. enum miner_state mining_state; // Miner state
  47. enum miner_asic asic_type; // ASIC Type
  48. struct thr_info *thr; // Running Thread
  49. struct thr_info rthr; // Listening Thread
  50. struct thr_info wthr; // Miner Work Thread
  51. pthread_mutex_t lock; // Mutex
  52. pthread_mutex_t wlock; // Mutex Serialize Writes
  53. float frequency; // Chip Frequency
  54. float frequency_requested; // Requested Frequency
  55. float frequency_start; // Starting Frequency
  56. float healthy; // Lower percentile before tagging asic unhealthy
  57. float micro_temp; // Micro Reported Temp
  58. uint32_t scanhash_ms; // Sleep time inside scanhash loop
  59. uint32_t task_ms; // Avg time(ms) between task sent to device
  60. uint32_t fullscan_ms; // Estimated time(ms) for full nonce range
  61. uint64_t hashrate; // Estimated hashrate = cores x chips x frequency
  62. uint64_t task_hcn; // Hash Count Number - max nonce iter.
  63. uint32_t prev_nonce; // Last nonce found
  64. int failing; // Flag failing sticks
  65. int fail_count; // Track failures.
  66. int accepted; // Nonces accepted
  67. int dups; // Duplicates found
  68. int interface; // USB interface
  69. int log_startup; // LOG_WARNING first 15 seconds, then LOG_INFO
  70. int nonceless; // Tasks sent. Resets when nonce is found.
  71. int nonces; // Nonces found
  72. int zero_check; // Received nonces from zero work
  73. int vcore; // Core voltage
  74. int micro_found; // Found a micro to communicate with
  75. bool vmask; // Current pool's vmask
  76. uint32_t bauddiv; // Baudrate divider
  77. uint32_t chips; // Stores number of chips found
  78. uint32_t cores; // Stores number of core per chp
  79. uint32_t difficulty; // For computing hashrate
  80. uint64_t hashes; // Hashes completed
  81. uint32_t job_id; // JobId incrementer
  82. uint32_t low_hash; // Tracks of low hashrate
  83. uint32_t max_job_id; // JobId cap
  84. uint32_t ramping; // Ramping incrementer
  85. uint32_t rx_len; // rx length
  86. uint32_t task_len; // task length
  87. uint32_t ticket_mask; // Used to reduce flashes per second
  88. uint32_t tx_len; // tx length
  89. uint32_t update_work; // Notification of work update
  90. struct timeval start_time; // Device startup time
  91. struct timeval monitor_time; // Health check reference point
  92. struct timeval last_scanhash; // Last time inside scanhash loop
  93. struct timeval last_reset; // Last time reset was triggered
  94. struct timeval last_task; // Last time work was sent
  95. struct timeval last_nonce; // Last time nonce was found
  96. struct timeval last_hwerror; // Last time hw error was detected
  97. struct timeval last_frequency_adjust; // Last time of frequency adjust
  98. struct timeval last_frequency_ping; // Last time of frequency poll
  99. struct timeval last_frequency_report; // Last change of frequency report
  100. struct timeval last_chain_inactive; // Last sent chain inactive
  101. struct timeval last_micro_ping; // Last time of micro controller poll
  102. struct timeval last_write_error; // Last usb write error message
  103. bool active_work[JOB_MAX]; // Tag good and stale work
  104. struct work *work[JOB_MAX]; // Work ring buffer
  105. unsigned char task[BUFFER_MAX]; // Task transmit buffer
  106. unsigned char cmd[BUFFER_MAX]; // Command transmit buffer
  107. unsigned char rx[BUFFER_MAX]; // Receive buffer
  108. unsigned char tx[BUFFER_MAX]; // Transmit buffer
  109. unsigned char end[1024]; // buffer overrun test
  110. };
  111. void stuff_lsb(unsigned char *dst, uint32_t x);
  112. void stuff_msb(unsigned char *dst, uint32_t x);
  113. void stuff_reverse(unsigned char *dst, unsigned char *src, uint32_t len);
  114. uint64_t bound(uint64_t value, uint64_t lower_bound, uint64_t upper_bound);