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