driver-avalon.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright 2013 Avalon project
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the Free
  6. * Software Foundation; either version 3 of the License, or (at your option)
  7. * any later version. See COPYING for more details.
  8. */
  9. #ifndef AVALON_H
  10. #define AVALON_H
  11. #ifdef USE_AVALON
  12. #define AVALON_RESET_FAULT_DECISECONDS 1
  13. #define AVALON_MINER_THREADS 1
  14. #define AVALON_IO_SPEED 115200
  15. #define AVALON_HASH_TIME_FACTOR ((float)1.67/0x32)
  16. #define AVALON_RESET_PITCH (300*1000*1000)
  17. #define AVALON_FAN_FACTOR 120
  18. #define AVALON_DEFAULT_FAN_MAX_PWM 0xA0 /* 100% */
  19. #define AVALON_DEFAULT_FAN_MIN_PWM 0x20 /* 20% */
  20. #define AVALON_DEFAULT_TIMEOUT 0x32
  21. #define AVALON_DEFAULT_FREQUENCY 256
  22. #define AVALON_DEFAULT_MINER_NUM 0x20
  23. #define AVALON_DEFAULT_ASIC_NUM 0xA
  24. #define AVALON_FTDI_READSIZE 512
  25. #define AVALON_READBUF_SIZE 8192
  26. #define AVALON_READ_TIMEOUT 10
  27. struct avalon_task {
  28. uint8_t reset :1;
  29. uint8_t flush_fifo :1;
  30. uint8_t fan_eft :1;
  31. uint8_t timer_eft :1;
  32. uint8_t asic_num :4;
  33. uint8_t fan_pwm_data;
  34. uint8_t timeout_data;
  35. uint8_t miner_num;
  36. uint8_t nonce_elf :1;
  37. uint8_t gate_miner_elf :1;
  38. uint8_t asic_pll :1;
  39. uint8_t gate_miner :1;
  40. uint8_t _pad0 :4;
  41. uint8_t _pad1[3];
  42. uint32_t _pad2;
  43. uint8_t midstate[32];
  44. uint8_t data[12];
  45. } __attribute__((packed, aligned(4)));
  46. struct avalon_result {
  47. uint32_t nonce;
  48. uint8_t data[12];
  49. uint8_t midstate[32];
  50. uint8_t fan0;
  51. uint8_t fan1;
  52. uint8_t fan2;
  53. uint8_t temp0;
  54. uint8_t temp1;
  55. uint8_t temp2;
  56. uint8_t _pad0[2];
  57. uint16_t fifo_wp;
  58. uint16_t fifo_rp;
  59. uint8_t chip_num;
  60. uint8_t pwm_data;
  61. uint8_t timeout;
  62. uint8_t miner_num;
  63. } __attribute__((packed, aligned(4)));
  64. struct avalon_info {
  65. int baud;
  66. int miner_count;
  67. int asic_count;
  68. int timeout;
  69. int fan0;
  70. int fan1;
  71. int fan2;
  72. int temp0;
  73. int temp1;
  74. int temp2;
  75. int temp_max;
  76. int temp_history_count;
  77. int temp_history_index;
  78. int temp_sum;
  79. int temp_old;
  80. int fan_pwm;
  81. int no_matching_work;
  82. int matching_work[AVALON_DEFAULT_MINER_NUM];
  83. int frequency;
  84. struct thr_info *thr;
  85. pthread_t read_thr;
  86. pthread_t write_thr;
  87. pthread_mutex_t lock;
  88. pthread_mutex_t qlock;
  89. pthread_cond_t qcond;
  90. int nonces;
  91. bool idle;
  92. bool reset;
  93. };
  94. #define AVALON_WRITE_SIZE (sizeof(struct avalon_task))
  95. #define AVALON_READ_SIZE (sizeof(struct avalon_result))
  96. #define AVALON_ARRAY_SIZE 3
  97. #define AVA_GETS_ERROR -1
  98. #define AVA_GETS_OK 0
  99. #define AVA_SEND_ERROR -1
  100. #define AVA_SEND_OK 0
  101. #define avalon_buffer_full(avalon) !usb_ftdi_cts(avalon)
  102. #define AVALON_READ_TIME(baud) ((double)AVALON_READ_SIZE * (double)8.0 / (double)(baud))
  103. #define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1]
  104. ASSERT1(sizeof(uint32_t) == 4);
  105. extern struct avalon_info **avalon_info;
  106. #endif /* USE_AVALON */
  107. #endif /* AVALON_H */