driver-avalon.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright 2013 Avalon project
  3. * Copyright 2013 Con Kolivas
  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 AVALON_H
  11. #define AVALON_H
  12. #ifdef USE_AVALON
  13. #include <stdint.h>
  14. #define AVALON_TIME_FACTOR 10
  15. #define AVALON_RESET_FAULT_DECISECONDS 1
  16. #define AVALON_MINER_THREADS 1
  17. #define AVALON_IO_SPEED 115200
  18. #define AVALON_HASH_TIME_FACTOR ((float)1.67/0x32)
  19. #define AVALON_RESET_PITCH (300*1000*1000)
  20. #define AVALON_FAN_FACTOR 120
  21. #define AVALON_DEFAULT_FAN_MAX_PWM 0xA0 /* 100% */
  22. #define AVALON_DEFAULT_FAN_MIN_PWM 0x20 /* 20% */
  23. #define AVALON_DEFAULT_TIMEOUT 0x32
  24. #define AVALON_DEFAULT_FREQUENCY 256
  25. #define AVALON_DEFAULT_MINER_NUM 0x20
  26. #define AVALON_DEFAULT_ASIC_NUM 0xA
  27. #define AVALON_FTDI_READSIZE 512
  28. struct avalon_task {
  29. uint8_t reset :1;
  30. uint8_t flush_fifo :1;
  31. uint8_t fan_eft :1;
  32. uint8_t timer_eft :1;
  33. uint8_t asic_num :4;
  34. uint8_t fan_pwm_data;
  35. uint8_t timeout_data;
  36. uint8_t miner_num;
  37. uint8_t nonce_elf :1;
  38. uint8_t gate_miner_elf :1;
  39. uint8_t asic_pll :1;
  40. uint8_t gate_miner :1;
  41. uint8_t _pad0 :4;
  42. uint8_t _pad1[3];
  43. uint32_t _pad2;
  44. uint8_t midstate[32];
  45. uint8_t data[12];
  46. } __attribute__((packed, aligned(4)));
  47. struct avalon_result {
  48. uint32_t nonce;
  49. uint8_t data[12];
  50. uint8_t midstate[32];
  51. uint8_t fan0;
  52. uint8_t fan1;
  53. uint8_t fan2;
  54. uint8_t temp0;
  55. uint8_t temp1;
  56. uint8_t temp2;
  57. uint8_t _pad0[2];
  58. uint16_t fifo_wp;
  59. uint16_t fifo_rp;
  60. uint8_t chip_num;
  61. uint8_t pwm_data;
  62. uint8_t timeout;
  63. uint8_t miner_num;
  64. } __attribute__((packed, aligned(4)));
  65. struct avalon_info {
  66. int read_count;
  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. };
  87. #define AVALON_WRITE_SIZE (sizeof(struct avalon_task))
  88. #define AVALON_READ_SIZE (sizeof(struct avalon_result))
  89. #define AVALON_ARRAY_SIZE 4
  90. #define AVA_GETS_ERROR -1
  91. #define AVA_GETS_OK 0
  92. #define AVA_GETS_RESTART 1
  93. #define AVA_GETS_TIMEOUT 2
  94. #define AVA_SEND_ERROR -1
  95. #define AVA_SEND_OK 0
  96. #define AVA_SEND_BUFFER_EMPTY 1
  97. #define AVA_SEND_BUFFER_FULL 2
  98. #define AVA_BUFFER_FULL 0
  99. #define AVA_BUFFER_EMPTY 1
  100. #define avalon_open2(devpath, baud, purge) serial_open(devpath, baud, AVALON_RESET_FAULT_DECISECONDS, purge)
  101. #define avalon_open(devpath, baud) avalon_open2(devpath, baud, true)
  102. #define avalon_close(fd) close(fd)
  103. #define avalon_buffer_full(fd) get_serial_cts(fd)
  104. #define AVALON_READ_TIME(baud) ((double)AVALON_READ_SIZE * (double)8.0 / (double)(baud))
  105. #define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1]
  106. ASSERT1(sizeof(uint32_t) == 4);
  107. extern struct avalon_info **avalon_info;
  108. #endif /* USE_AVALON */
  109. #endif /* AVALON_H */