driver-avalon.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * Copyright 2013 Avalon project
  3. * Copyright 2013 Con Kolivas <kernel@kolivas.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the Free
  7. * Software Foundation; either version 3 of the License, or (at your option)
  8. * any later version. See COPYING for more details.
  9. */
  10. #ifndef AVALON_H
  11. #define AVALON_H
  12. #ifdef USE_AVALON
  13. #include "util.h"
  14. #define AVALON_RESET_FAULT_DECISECONDS 1
  15. #define AVALON_MINER_THREADS 1
  16. #define AVALON_IO_SPEED 115200
  17. #define AVALON_HASH_TIME_FACTOR ((float)1.67/0x32)
  18. #define AVALON_RESET_PITCH (300*1000*1000)
  19. #define AVALON_FAN_FACTOR 120
  20. #define AVALON_PWM_MAX 0xA0
  21. #define AVALON_DEFAULT_FAN_MIN 20
  22. #define AVALON_DEFAULT_FAN_MAX 100
  23. #define AVALON_DEFAULT_FAN_MAX_PWM 0xA0 /* 100% */
  24. #define AVALON_DEFAULT_FAN_MIN_PWM 0x20 /* 20% */
  25. #define AVALON_TEMP_TARGET 50
  26. #define AVALON_TEMP_HYSTERESIS 3
  27. #define AVALON_TEMP_OVERHEAT 60
  28. #define BITBURNER_DEFAULT_CORE_VOLTAGE 1200 /* in millivolts */
  29. #define BITBURNER_MIN_COREMV 1000
  30. /* change here if you want to risk killing it :) */
  31. #define BITBURNER_MAX_COREMV 1400
  32. #define AVALON_DEFAULT_TIMEOUT 0x2D
  33. #define AVALON_MIN_FREQUENCY 256
  34. #define AVALON_MAX_FREQUENCY 1024
  35. #define AVALON_TIMEOUT_FACTOR 12690
  36. #define AVALON_DEFAULT_FREQUENCY 282
  37. #define AVALON_DEFAULT_MINER_NUM 0x20
  38. #define AVALON_DEFAULT_ASIC_NUM 0xA
  39. #define AVALON_AUTO_CYCLE 1024
  40. #define AVALON_FTDI_READSIZE 510
  41. #define AVALON_USB_PACKETSIZE 512
  42. #define AVALON_READBUF_SIZE 8192
  43. #define AVALON_RESET_TIMEOUT 100
  44. #define AVALON_READ_TIMEOUT 18 /* Enough to only half fill the buffer */
  45. #define AVALON_LATENCY 1
  46. struct avalon_task {
  47. uint8_t reset :1;
  48. uint8_t flush_fifo :1;
  49. uint8_t fan_eft :1;
  50. uint8_t timer_eft :1;
  51. uint8_t asic_num :4;
  52. uint8_t fan_pwm_data;
  53. uint8_t timeout_data;
  54. uint8_t miner_num;
  55. uint8_t nonce_elf :1;
  56. uint8_t gate_miner_elf :1;
  57. uint8_t asic_pll :1;
  58. uint8_t gate_miner :1;
  59. uint8_t _pad0 :4;
  60. uint8_t _pad1[3];
  61. uint32_t _pad2;
  62. uint8_t midstate[32];
  63. uint8_t data[12];
  64. } __attribute__((packed, aligned(4)));
  65. struct avalon_result {
  66. uint32_t nonce;
  67. uint8_t data[12];
  68. uint8_t midstate[32];
  69. uint8_t fan0;
  70. uint8_t fan1;
  71. uint8_t fan2;
  72. uint8_t temp0;
  73. uint8_t temp1;
  74. uint8_t temp2;
  75. uint8_t _pad0[2];
  76. uint16_t fifo_wp;
  77. uint16_t fifo_rp;
  78. uint8_t chip_num;
  79. uint8_t pwm_data;
  80. uint8_t timeout;
  81. uint8_t miner_num;
  82. } __attribute__((packed, aligned(4)));
  83. struct avalon_info {
  84. int baud;
  85. int miner_count;
  86. int asic_count;
  87. int timeout;
  88. int fan0;
  89. int fan1;
  90. int fan2;
  91. int temp0;
  92. int temp1;
  93. int temp2;
  94. int temp_max;
  95. int temp_history_count;
  96. int temp_history_index;
  97. int temp_sum;
  98. int temp_old;
  99. int fan_pwm;
  100. int core_voltage;
  101. int no_matching_work;
  102. int matching_work[AVALON_DEFAULT_MINER_NUM];
  103. int frequency;
  104. uint32_t ctlr_ver;
  105. struct thr_info *thr;
  106. pthread_t read_thr;
  107. pthread_t write_thr;
  108. pthread_mutex_t lock;
  109. pthread_mutex_t qlock;
  110. pthread_cond_t qcond;
  111. int nonces;
  112. int auto_queued;
  113. int auto_nonces;
  114. int auto_hw;
  115. int idle;
  116. bool reset;
  117. bool overheat;
  118. bool optimal;
  119. uint8_t version1;
  120. uint8_t version2;
  121. uint8_t version3;
  122. };
  123. #define BITBURNER_VERSION1 1
  124. #define BITBURNER_VERSION2 0
  125. #define BITBURNER_VERSION3 0
  126. #define AVALON_WRITE_SIZE (sizeof(struct avalon_task))
  127. #define AVALON_READ_SIZE (sizeof(struct avalon_result))
  128. #define AVALON_ARRAY_SIZE 3
  129. #define BITBURNER_ARRAY_SIZE 4
  130. #define AVA_GETS_ERROR -1
  131. #define AVA_GETS_OK 0
  132. #define AVA_SEND_ERROR -1
  133. #define AVA_SEND_OK 0
  134. #define avalon_buffer_full(avalon) !usb_ftdi_cts(avalon)
  135. #define AVALON_READ_TIME(baud) ((double)AVALON_READ_SIZE * (double)8.0 / (double)(baud))
  136. #define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1]
  137. ASSERT1(sizeof(uint32_t) == 4);
  138. extern struct avalon_info **avalon_info;
  139. extern int opt_avalon_temp;
  140. extern int opt_avalon_overheat;
  141. extern int opt_avalon_fan_min;
  142. extern int opt_avalon_fan_max;
  143. extern int opt_avalon_freq_min;
  144. extern int opt_avalon_freq_max;
  145. extern bool opt_avalon_auto;
  146. extern int opt_bitburner_core_voltage;
  147. extern char *set_avalon_fan(char *arg);
  148. extern char *set_avalon_freq(char *arg);
  149. #endif /* USE_AVALON */
  150. #endif /* AVALON_H */