driver-avalon.h 2.9 KB

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