driver-avalon.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. struct avalon_task {
  25. uint8_t reset :1;
  26. uint8_t flush_fifo :1;
  27. uint8_t fan_eft :1;
  28. uint8_t timer_eft :1;
  29. uint8_t asic_num :4;
  30. uint8_t fan_pwm_data;
  31. uint8_t timeout_data;
  32. uint8_t miner_num;
  33. uint8_t nonce_elf :1;
  34. uint8_t gate_miner_elf :1;
  35. uint8_t asic_pll :1;
  36. uint8_t gate_miner :1;
  37. uint8_t _pad0 :4;
  38. uint8_t _pad1[3];
  39. uint32_t _pad2;
  40. uint8_t midstate[32];
  41. uint8_t data[12];
  42. } __attribute__((packed, aligned(4)));
  43. struct avalon_result {
  44. uint32_t nonce;
  45. uint8_t data[12];
  46. uint8_t midstate[32];
  47. uint8_t fan0;
  48. uint8_t fan1;
  49. uint8_t fan2;
  50. uint8_t temp0;
  51. uint8_t temp1;
  52. uint8_t temp2;
  53. uint8_t _pad0[2];
  54. uint16_t fifo_wp;
  55. uint16_t fifo_rp;
  56. uint8_t chip_num;
  57. uint8_t pwm_data;
  58. uint8_t timeout;
  59. uint8_t miner_num;
  60. } __attribute__((packed, aligned(4)));
  61. struct avalon_info {
  62. int baud;
  63. int miner_count;
  64. int asic_count;
  65. int timeout;
  66. int fan0;
  67. int fan1;
  68. int fan2;
  69. int temp0;
  70. int temp1;
  71. int temp2;
  72. int temp_max;
  73. int temp_history_count;
  74. int temp_history_index;
  75. int temp_sum;
  76. int temp_old;
  77. int fan_pwm;
  78. int no_matching_work;
  79. int matching_work[AVALON_DEFAULT_MINER_NUM];
  80. int frequency;
  81. };
  82. #define AVALON_WRITE_SIZE (sizeof(struct avalon_task))
  83. #define AVALON_READ_SIZE (sizeof(struct avalon_result))
  84. #define AVALON_ARRAY_SIZE 4
  85. #define AVA_GETS_ERROR -1
  86. #define AVA_GETS_OK 0
  87. #define AVA_GETS_RESTART 1
  88. #define AVA_GETS_TIMEOUT 2
  89. #define AVA_SEND_ERROR -1
  90. #define AVA_SEND_OK 0
  91. #define AVA_SEND_BUFFER_EMPTY 1
  92. #define AVA_SEND_BUFFER_FULL 2
  93. #define AVA_BUFFER_FULL 0
  94. #define AVA_BUFFER_EMPTY 1
  95. #define avalon_open2(devpath, baud, purge) serial_open(devpath, baud, AVALON_RESET_FAULT_DECISECONDS, purge)
  96. #define avalon_open(devpath, baud) avalon_open2(devpath, baud, true)
  97. #define avalon_close(fd) close(fd)
  98. #define avalon_buffer_full(fd) get_serial_cts(fd)
  99. #define AVALON_READ_TIME(baud) ((double)AVALON_READ_SIZE * (double)8.0 / (double)(baud))
  100. #define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1]
  101. ASSERT1(sizeof(uint32_t) == 4);
  102. extern struct avalon_info **avalon_info;
  103. #endif /* USE_AVALON */
  104. #endif /* AVALON_H */