static int polling(struct thr_info *thr) { int i, tmp; struct hashratio_pkg send_pkg; struct hashratio_ret ar; struct cgpu_info *hashratio = thr->cgpu; struct hashratio_info *info = hashratio->device_data; memset(send_pkg.data, 0, HRTO_P_DATA_LEN); hashratio_init_pkg(&send_pkg, HRTO_P_POLLING, 1, 1); while (hashratio_send_pkg(info->fd, &send_pkg, thr) != HRTO_SEND_OK) ; hashratio_get_result(thr, info->fd, &ar); return 0; }
static int64_t hashratio_scanhash(struct thr_info *thr) { struct cgpu_info *hashratio = thr->cgpu; struct hashratio_info *info = hashratio->device_data; struct hashratio_pkg send_pkg; struct hashratio_ret ar; memset(send_pkg.data, 0, HRTO_P_DATA_LEN); hashratio_init_pkg(&send_pkg, HRTO_P_POLLING, 1, 1); if (unlikely(hashratio->usbinfo.nodev || hashratio_send_pkgs(hashratio, &send_pkg))) { applog(LOG_ERR, "%s%d: Device disappeared, shutting down thread", hashratio->drv->name, hashratio->device_id); return -1; } hashratio_get_result(thr, &ar); return (int64_t)info->local_work * 64 * 0xffffffff; }
static bool hashratio_detect_one(const char *devpath) { struct hashratio_info *info; int ackdetect; int fd; int tmp, i; char mm_version[16]; struct cgpu_info *hashratio; struct hashratio_pkg detect_pkg; struct hashratio_ret ret_pkg; applog(LOG_DEBUG, "hashratio Detect: Attempting to open %s", devpath); fd = hashratio_open(devpath, HRTO_IO_SPEED, true); if (unlikely(fd == -1)) { applog(LOG_ERR, "hashratio Detect: Failed to open %s", devpath); return false; } tcflush(fd, TCIOFLUSH); strcpy(mm_version, "NONE"); /* Send out detect pkg */ memset(detect_pkg.data, 0, HRTO_P_DATA_LEN); hashratio_init_pkg(&detect_pkg, HRTO_P_DETECT, 1, 1); hashratio_send_pkg(fd, &detect_pkg, NULL); ackdetect = hashratio_get_result(NULL, fd, &ret_pkg); applog(LOG_DEBUG, "hashratio Detect ID: %d", ackdetect); if (ackdetect != HRTO_P_ACKDETECT) return false; memcpy(mm_version, ret_pkg.data, 15); mm_version[15] = '\0'; /* We have a real Hashratio! */ hashratio = calloc(1, sizeof(struct cgpu_info)); hashratio->drv = &hashratio_drv; hashratio->device_path = strdup(devpath); hashratio->threads = HRTO_MINER_THREADS; add_cgpu(hashratio); applog(LOG_INFO, "hashratio Detect: Found at %s, mark as %d", devpath, hashratio->device_id); hashratio->device_data = calloc(sizeof(struct hashratio_info), 1); if (unlikely(!(hashratio->device_data))) quit(1, "Failed to malloc hashratio_info"); info = hashratio->device_data; strcpy(info->mm_version, mm_version); info->baud = HRTO_IO_SPEED; info->fan_pwm = HRTO_DEFAULT_FAN / 100 * HRTO_PWM_MAX; info->temp_max = 0; info->temp_history_index = 0; info->temp_sum = 0; info->temp_old = 0; info->default_freq = opt_hashratio_freq; info->fd = -1; /* Set asic to idle mode after detect */ hashratio_close(fd); return true; }