driver-avalon.h 3.2 KB

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