driver-avalon.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. struct avalon_task {
  12. uint8_t reset :1;
  13. uint8_t flush_fifo :1;
  14. uint8_t fan_eft :1;
  15. uint8_t timer_eft :1;
  16. uint8_t chip_num :4;
  17. uint8_t fan_pwm_data;
  18. uint8_t timeout_data;
  19. uint8_t miner_num;
  20. uint8_t nonce_elf :1;
  21. uint32_t pad0_miner_ctrl :31;
  22. uint32_t pad1_miner_ctrl;
  23. uint8_t midstate[32];
  24. uint8_t data[12];
  25. } __attribute__((packed, aligned(4)));
  26. struct avalon_result {
  27. uint32_t nonce;
  28. uint8_t data[12];
  29. uint8_t midstate[32];
  30. uint8_t reserved[16];
  31. } __attribute__((packed, aligned(4)));
  32. struct avalon_info {
  33. double Hs;
  34. int read_count;
  35. double fullnonce;
  36. int baud;
  37. int miner_count;
  38. int asic_count;
  39. int timeout;
  40. };
  41. #define TIME_FACTOR 10
  42. #define AVALON_RESET_FAULT_DECISECONDS 1
  43. #define AVALON_READ_COUNT_TIMING (5 * TIME_FACTOR)
  44. #define AVALON_HASH_TIME (0.0000000026316 / AVALON_GET_WORK_COUNT)
  45. #define NANOSEC 1000000000.0
  46. #define AVALON_MINER_THREADS 1
  47. #define AVALON_IO_SPEED 115200
  48. #define AVALON_SEND_WORK_PITCH (32*1000*1000)
  49. #define AVALON_RESET_PITCH (80*1000*1000)
  50. #define AVALON_GET_WORK_COUNT 3 // 24
  51. #define AVALON_DEFAULT_FAN_PWM 0x98
  52. #define AVALON_DEFAULT_TIMEOUT 0x32
  53. #define AVALON_DEFAULT_MINER_NUM AVALON_GET_WORK_COUNT
  54. #define AVALON_DEFAULT_CHIP_NUM 0x1 // 0xA
  55. #define AVALON_WRITE_SIZE (sizeof(struct avalon_task))
  56. #define AVALON_READ_SIZE (sizeof(struct avalon_result))
  57. #define AVA_GETS_ERROR -1
  58. #define AVA_GETS_OK 0
  59. #define AVA_GETS_RESTART 1
  60. #define AVA_GETS_TIMEOUT 2
  61. #define AVA_SEND_ERROR -1
  62. #define AVA_SEND_OK 0
  63. #define AVA_SEND_BUFFER_EMPTY 1
  64. #define AVA_SEND_BUFFER_FULL 2
  65. #define AVA_BUFFER_FULL 0
  66. #define AVA_BUFFER_EMPTY 1
  67. #define avalon_open2(devpath, baud, purge) serial_open(devpath, baud, AVALON_RESET_FAULT_DECISECONDS, purge)
  68. #define avalon_open(devpath, baud) avalon_open2(devpath, baud, true)
  69. #define avalon_close(fd) close(fd)
  70. #define avalon_buffer_full(fd) get_serial_cts(fd)
  71. #define avalon_init_default_task(at) avalon_init_task(at, 0, 0, 0, 0, 0, 0)
  72. #define AVALON_READ_TIME(baud) ((double)AVALON_READ_SIZE * (double)8.0 / (double)(baud))
  73. #define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1]
  74. ASSERT1(sizeof(uint32_t) == 4);
  75. static inline uint8_t rev8(uint8_t d)
  76. {
  77. int i;
  78. uint8_t out = 0;
  79. /* (from left to right) */
  80. for (i = 0; i < 8; i++)
  81. if (d & (1 << i))
  82. out |= (1 << (7 - i));
  83. return out;
  84. }
  85. #endif /* AVALON_H */