driver-icarus.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright 2012-2013 Luke Dashjr
  3. * Copyright 2012 Xiangfu
  4. * Copyright 2012 Andrew Smith
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 3 of the License, or (at your option)
  9. * any later version. See COPYING for more details.
  10. */
  11. #ifndef BFG_DRIVER_ICARUS_H
  12. #define BFG_DRIVER_ICARUS_H
  13. #include <stdbool.h>
  14. #include <stdint.h>
  15. #include <sys/time.h>
  16. #include "dynclock.h"
  17. #include "miner.h"
  18. // Fraction of a second, USB timeout is measured in
  19. // i.e. 10 means 1/10 of a second
  20. // Right now, it MUST be 10 due to other assumptions.
  21. #define TIME_FACTOR 10
  22. // It's 10 per second, thus value = 10/TIME_FACTOR =
  23. #define ICARUS_READ_FAULT_DECISECONDS 1
  24. #define NANOSEC 1000000000.0
  25. // Default value for ICARUS_INFO->read_size
  26. #define ICARUS_DEFAULT_READ_SIZE 4
  27. #define ICA_GETS_ERROR -1
  28. #define ICA_GETS_OK 0
  29. #define ICA_GETS_RESTART 1
  30. #define ICA_GETS_TIMEOUT 2
  31. // Store the last INFO_HISTORY data sets
  32. // [0] = current data, not yet ready to be included as an estimate
  33. // Each new data set throws the last old set off the end thus
  34. // keeping a ongoing average of recent data
  35. #define INFO_HISTORY 10
  36. extern struct device_drv icarus_drv;
  37. struct ICARUS_HISTORY {
  38. struct timeval finish;
  39. double sumXiTi;
  40. double sumXi;
  41. double sumTi;
  42. double sumXi2;
  43. uint32_t values;
  44. uint32_t hash_count_min;
  45. uint32_t hash_count_max;
  46. };
  47. enum timing_mode { MODE_DEFAULT, MODE_SHORT, MODE_LONG, MODE_VALUE };
  48. enum icarus_reopen_mode {
  49. IRM_NEVER,
  50. IRM_TIMEOUT,
  51. IRM_CYCLE,
  52. };
  53. enum icarus_user_settings {
  54. IUS_WORK_DIVISION = 1,
  55. IUS_FPGA_COUNT = 2,
  56. };
  57. struct ICARUS_INFO {
  58. // time to calculate the golden_ob
  59. struct timeval golden_tv;
  60. // History structures for calculating read_count
  61. // when info->do_icarus_timing is true
  62. struct ICARUS_HISTORY history[INFO_HISTORY+1];
  63. uint32_t min_data_count;
  64. // Timeout scanning for a nonce (deciseconds)
  65. int read_count;
  66. // Timeout scanning for a golden nonce (deciseconds)
  67. int probe_read_count;
  68. // ds limit for (short=/long=) read_count
  69. int read_count_limit;
  70. enum timing_mode timing_mode;
  71. bool do_icarus_timing;
  72. int do_default_detection;
  73. double fullnonce;
  74. int count;
  75. double W;
  76. uint32_t values;
  77. uint64_t hash_count_range;
  78. // Determine the cost of history processing
  79. // (which will only affect W)
  80. uint64_t history_count;
  81. struct timeval history_time;
  82. // icarus-options
  83. int baud;
  84. // Used to calculate / display hash count when nonce is NOT found
  85. // seconds per Hash
  86. double Hs;
  87. // Used to calculate / display hash count when a nonce is found
  88. int work_division;
  89. int fpga_count;
  90. uint32_t nonce_mask;
  91. enum icarus_reopen_mode reopen_mode;
  92. bool reopen_now;
  93. uint8_t user_set;
  94. bool continue_search;
  95. dclk_change_clock_func_t dclk_change_clock_func;
  96. struct dclk_data dclk;
  97. // Bytes to read from Icarus for nonce
  98. int read_size;
  99. // Settings used when probing / detecting
  100. size_t ob_size;
  101. const char *golden_ob;
  102. const char *golden_nonce;
  103. bool nonce_littleendian;
  104. // Don't check the golden nonce returned when probing
  105. bool ignore_golden_nonce;
  106. // Custom driver functions
  107. bool (*detect_init_func)(const char *devpath, int fd, struct ICARUS_INFO *);
  108. bool (*job_start_func)(struct thr_info *);
  109. };
  110. struct icarus_state {
  111. bool firstrun;
  112. struct timeval tv_workstart;
  113. struct timeval tv_workfinish;
  114. struct work *last_work;
  115. struct work *last2_work;
  116. bool changework;
  117. bool identify;
  118. uint8_t *ob_bin;
  119. };
  120. bool icarus_detect_custom(const char *devpath, struct device_drv *, struct ICARUS_INFO *);
  121. extern int icarus_gets(unsigned char *, int fd, struct timeval *tv_finish, struct thr_info *, int read_count, int read_size);
  122. extern int icarus_write(int fd, const void *buf, size_t bufLen);
  123. extern bool icarus_init(struct thr_info *);
  124. extern void do_icarus_close(struct thr_info *thr);
  125. extern bool icarus_job_start(struct thr_info *);
  126. #endif