driver-avalon.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #include <semaphore.h>
  13. #define AVALON_RESET_FAULT_DECISECONDS 1
  14. #define AVALON_MINER_THREADS 1
  15. #define AVALON_IO_SPEED 115200
  16. #define AVALON_HASH_TIME_FACTOR ((float)1.67/0x32)
  17. #define AVALON_RESET_PITCH (300*1000*1000)
  18. #define AVALON_FAN_FACTOR 120
  19. #define AVALON_DEFAULT_FAN_MAX_PWM 0xA0 /* 100% */
  20. #define AVALON_DEFAULT_FAN_MIN_PWM 0x20 /* 20% */
  21. #define AVALON_DEFAULT_TIMEOUT 0x32
  22. #define AVALON_DEFAULT_FREQUENCY 256
  23. #define AVALON_DEFAULT_MINER_NUM 0x20
  24. #define AVALON_DEFAULT_ASIC_NUM 0xA
  25. #define AVALON_FTDI_READSIZE 510
  26. #define AVALON_READBUF_SIZE 8192
  27. #define AVALON_RESET_TIMEOUT 100
  28. #define AVALON_READ_TIMEOUT 10
  29. struct avalon_task {
  30. uint8_t reset :1;
  31. uint8_t flush_fifo :1;
  32. uint8_t fan_eft :1;
  33. uint8_t timer_eft :1;
  34. uint8_t asic_num :4;
  35. uint8_t fan_pwm_data;
  36. uint8_t timeout_data;
  37. uint8_t miner_num;
  38. uint8_t nonce_elf :1;
  39. uint8_t gate_miner_elf :1;
  40. uint8_t asic_pll :1;
  41. uint8_t gate_miner :1;
  42. uint8_t _pad0 :4;
  43. uint8_t _pad1[3];
  44. uint32_t _pad2;
  45. uint8_t midstate[32];
  46. uint8_t data[12];
  47. } __attribute__((packed, aligned(4)));
  48. struct avalon_result {
  49. uint32_t nonce;
  50. uint8_t data[12];
  51. uint8_t midstate[32];
  52. uint8_t fan0;
  53. uint8_t fan1;
  54. uint8_t fan2;
  55. uint8_t temp0;
  56. uint8_t temp1;
  57. uint8_t temp2;
  58. uint8_t _pad0[2];
  59. uint16_t fifo_wp;
  60. uint16_t fifo_rp;
  61. uint8_t chip_num;
  62. uint8_t pwm_data;
  63. uint8_t timeout;
  64. uint8_t miner_num;
  65. } __attribute__((packed, aligned(4)));
  66. struct avalon_info {
  67. int baud;
  68. int miner_count;
  69. int asic_count;
  70. int timeout;
  71. int fan0;
  72. int fan1;
  73. int fan2;
  74. int temp0;
  75. int temp1;
  76. int temp2;
  77. int temp_max;
  78. int temp_history_count;
  79. int temp_history_index;
  80. int temp_sum;
  81. int temp_old;
  82. int fan_pwm;
  83. int no_matching_work;
  84. int matching_work[AVALON_DEFAULT_MINER_NUM];
  85. int frequency;
  86. struct thr_info *thr;
  87. pthread_t read_thr;
  88. pthread_t write_thr;
  89. pthread_mutex_t lock;
  90. pthread_mutex_t qlock;
  91. pthread_cond_t qcond;
  92. sem_t read_sem;
  93. sem_t write_sem;
  94. int nonces;
  95. bool idle;
  96. bool reset;
  97. };
  98. #define AVALON_WRITE_SIZE (sizeof(struct avalon_task))
  99. #define AVALON_READ_SIZE (sizeof(struct avalon_result))
  100. #define AVALON_ARRAY_SIZE 3
  101. #define AVA_GETS_ERROR -1
  102. #define AVA_GETS_OK 0
  103. #define AVA_SEND_ERROR -1
  104. #define AVA_SEND_OK 0
  105. #define avalon_buffer_full(avalon) !usb_ftdi_cts(avalon)
  106. #define AVALON_READ_TIME(baud) ((double)AVALON_READ_SIZE * (double)8.0 / (double)(baud))
  107. #define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1]
  108. ASSERT1(sizeof(uint32_t) == 4);
  109. extern struct avalon_info **avalon_info;
  110. #endif /* USE_AVALON */
  111. #endif /* AVALON_H */