driver-avalon.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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));
  26. struct avalon_result {
  27. uint32_t nonce;
  28. uint8_t data[12];
  29. uint8_t midstate[32];
  30. uint8_t reserved[8];
  31. } __attribute__((packed));
  32. struct AVALON_HISTORY {
  33. struct timeval finish;
  34. double sumXiTi;
  35. double sumXi;
  36. double sumTi;
  37. double sumXi2;
  38. uint32_t values;
  39. uint32_t hash_count_min;
  40. uint32_t hash_count_max;
  41. };
  42. enum timing_mode { MODE_DEFAULT, MODE_SHORT, MODE_LONG, MODE_VALUE };
  43. #define INFO_HISTORY 10
  44. struct AVALON_INFO {
  45. struct AVALON_HISTORY history[INFO_HISTORY+1];
  46. uint32_t min_data_count;
  47. /* seconds per Hash */
  48. double Hs;
  49. int read_count;
  50. enum timing_mode timing_mode;
  51. bool do_avalon_timing;
  52. double fullnonce;
  53. int count;
  54. double W;
  55. uint32_t values;
  56. uint64_t hash_count_range;
  57. /* Determine the cost of history processing
  58. * (which will only affect W) */
  59. uint64_t history_count;
  60. struct timeval history_time;
  61. int baud;
  62. int work_division;
  63. int asic_count;
  64. uint32_t nonce_mask;
  65. };
  66. #define AVALON_MINER_THREADS 1
  67. #define AVALON_GET_WORK_COUNT 1 // 24
  68. #define AVALON_IO_SPEED 19200 // 115200
  69. #define AVALON_SEND_WORK_PITCH 4000 /* 4ms */
  70. #define AVALON_DEFAULT_MINER_NUM 0x18
  71. #define AVALON_DEFAULT_CHIP_NUM 0xA
  72. #define AVALON_DEFAULT_FAN_PWM 0x98
  73. #define AVALON_DEFAULT_TIMEOUT 0x27
  74. #define AVALON_WRITE_SIZE (sizeof(struct avalon_task))
  75. #define AVALON_READ_SIZE (sizeof(struct avalon_result))
  76. #define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1]
  77. ASSERT1(sizeof(uint32_t) == 4);
  78. #define AVALON_READ_TIME(baud) ((double)AVALON_READ_SIZE * (double)8.0 / (double)(baud))
  79. #define TIME_FACTOR 10
  80. #define AVALON_RESET_FAULT_DECISECONDS 1
  81. #define AVALON_READ_COUNT_TIMING (5 * TIME_FACTOR)
  82. //#define AVALON_HASH_TIME 0.0000000000155
  83. #define AVALON_HASH_TIME (0.0000000026316)
  84. #define NANOSEC 1000000000.0
  85. #define HISTORY_SEC 60
  86. #define MIN_DATA_COUNT 5
  87. #define MAX_MIN_DATA_COUNT 100
  88. #define END_CONDITION 0x0000ffff
  89. #define AVA_GETS_ERROR -1
  90. #define AVA_GETS_OK 0
  91. #define AVA_GETS_RESTART 1
  92. #define AVA_GETS_TIMEOUT 2
  93. #define AVA_SEND_ERROR -1
  94. #define AVA_SEND_OK 0
  95. #define AVA_SEND_BUFFER_EMPTY 1
  96. #define AVA_SEND_BUFFER_FULL 2
  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_init_default_task(at) avalon_init_task(at, 0, 0, 0, 0, 0, 0)
  100. #define avalon_close(fd) close(fd)
  101. #define AVA_BUFFER_FULL 1
  102. #define AVA_BUFFER_EMPTY 0
  103. #define avalon_buffer_full(fd) get_serial_cts(fd)
  104. static void rev(unsigned char *s, size_t l)
  105. {
  106. size_t i, j;
  107. unsigned char t;
  108. for (i = 0, j = l - 1; i < j; i++, j--) {
  109. t = s[i];
  110. s[i] = s[j];
  111. s[j] = t;
  112. }
  113. }
  114. #endif /* AVALON_H */