driver-avalonmm.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright 2013 Con Kolivas <kernel@kolivas.org>
  3. * Copyright 2012-2014 Xiangfu <xiangfu@openmobilefree.com>
  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 _AVALON2_H_
  11. #define _AVALON2_H_
  12. #include "lowl-vcom.h"
  13. #include "util.h"
  14. #ifdef USE_AVALON2
  15. #define AVA2_MINER_THREADS 1
  16. #define AVA2_RESET_FAULT_DECISECONDS 10
  17. #define AVA2_IO_SPEED 115200
  18. #define AVA2_DEFAULT_MINERS 10
  19. #define AVA2_DEFAULT_MODULARS 3
  20. #define AVA2_PWM_MAX 0x3FF
  21. #define AVA2_DEFAULT_FAN_PWM 80 /* % */
  22. #define AVA2_DEFAULT_FAN_MIN 0
  23. #define AVA2_DEFAULT_FAN_MAX 100
  24. #define AVA2_DEFAULT_VOLTAGE 10000 /* V * 10000 */
  25. #define AVA2_DEFAULT_VOLTAGE_MIN 6000
  26. #define AVA2_DEFAULT_VOLTAGE_MAX 11000
  27. #define AVA2_DEFAULT_FREQUENCY 1500 /* In MH/s */
  28. #define AVA2_DEFAULT_FREQUENCY_MIN 300
  29. #define AVA2_DEFAULT_FREQUENCY_MAX 2000
  30. /* Avalon2 protocol package type */
  31. #define AVA2_H1 'A'
  32. #define AVA2_H2 'V'
  33. #define AVA2_P_COINBASE_SIZE (6 * 1024)
  34. #define AVA2_P_MERKLES_COUNT 20
  35. #define AVA2_P_COUNT 39
  36. #define AVA2_P_DATA_LEN (AVA2_P_COUNT - 7)
  37. #define AVA2_P_DETECT 10
  38. #define AVA2_P_STATIC 11
  39. #define AVA2_P_JOB_ID 12
  40. #define AVA2_P_COINBASE 13
  41. #define AVA2_P_MERKLES 14
  42. #define AVA2_P_HEADER 15
  43. #define AVA2_P_POLLING 16
  44. #define AVA2_P_TARGET 17
  45. #define AVA2_P_REQUIRE 18
  46. #define AVA2_P_SET 19
  47. #define AVA2_P_TEST 20
  48. #define AVA2_P_ACK 21
  49. #define AVA2_P_NAK 22
  50. #define AVA2_P_NONCE 23
  51. #define AVA2_P_STATUS 24
  52. #define AVA2_P_ACKDETECT 25
  53. #define AVA2_P_TEST_RET 26
  54. /* Avalon2 protocol package type */
  55. struct avalon2_pkg {
  56. uint8_t head[2];
  57. uint8_t type;
  58. uint8_t idx;
  59. uint8_t cnt;
  60. uint8_t data[32];
  61. uint8_t crc[2];
  62. };
  63. #define avalon2_ret avalon2_pkg
  64. struct avalon2_info {
  65. int fd;
  66. int baud;
  67. uint32_t xnonce1;
  68. int set_frequency;
  69. int set_voltage;
  70. int get_voltage[AVA2_DEFAULT_MODULARS];
  71. int get_frequency[AVA2_DEFAULT_MODULARS];
  72. int fan_pwm;
  73. int fan[2 * AVA2_DEFAULT_MODULARS];
  74. int temp[2 * AVA2_DEFAULT_MODULARS];
  75. int temp_max;
  76. int temp_history_count;
  77. int temp_history_index;
  78. int temp_sum;
  79. int temp_old;
  80. bool first;
  81. bool new_stratum;
  82. int pool_no;
  83. int diff;
  84. int local_works[AVA2_DEFAULT_MODULARS];
  85. int hw_works[AVA2_DEFAULT_MODULARS];
  86. int matching_work[AVA2_DEFAULT_MINERS * AVA2_DEFAULT_MODULARS];
  87. int local_work[AVA2_DEFAULT_MODULARS];
  88. int hw_work[AVA2_DEFAULT_MODULARS];
  89. int modulars[AVA2_DEFAULT_MODULARS];
  90. char mm_version[AVA2_DEFAULT_MODULARS][16];
  91. uint32_t jobid;
  92. struct timeval tv_prepared;
  93. struct stratum_work swork;
  94. };
  95. #define AVA2_WRITE_SIZE (sizeof(struct avalon2_pkg))
  96. #define AVA2_READ_SIZE AVA2_WRITE_SIZE
  97. #define AVA2_GETS_OK 0
  98. #define AVA2_GETS_TIMEOUT -1
  99. #define AVA2_GETS_RESTART -2
  100. #define AVA2_GETS_ERROR -3
  101. #define AVA2_SEND_OK 0
  102. #define AVA2_SEND_ERROR -1
  103. #define avalon2_open(devpath, baud, purge) serial_open(devpath, baud, AVA2_RESET_FAULT_DECISECONDS, purge)
  104. #define avalon2_close(fd) close(fd)
  105. extern char *set_avalon2_fan(char *arg);
  106. extern char *set_avalon2_freq(char *arg);
  107. extern char *set_avalon2_voltage(char *arg);
  108. #endif /* USE_AVALON2 */
  109. #endif /* _AVALON2_H_ */