Browse Source

Merge branch 'master' into libusbx

nfactor-troky
Con Kolivas 11 years ago
parent
commit
e8b51b294c
  1. 45
      driver-klondike.c
  2. 46
      usbutils.c

45
driver-klondike.c

@ -39,7 +39,7 @@ @@ -39,7 +39,7 @@
#define REPLY_SIZE 15 // adequate for all types of replies
#define REPLY_BUFSIZE 16 // reply + 1 byte to mark used
#define MAX_REPLY_COUNT 32 // more unhandled replies than this will result in data loss
#define MAX_REPLY_COUNT 4096 // more unhandled replies than this will result in data loss
#define REPLY_WAIT_TIME 100 // poll interval for a cmd waiting it's reply
#define CMD_REPLY_RETRIES 8 // how many retries for cmds
#define MAX_WORK_COUNT 4 // for now, must be binary multiple and match firmware
@ -120,6 +120,9 @@ static double cvtKlnToC(uint8_t temp) @@ -120,6 +120,9 @@ static double cvtKlnToC(uint8_t temp)
{
double Rt, stein, celsius;
if (temp == 0)
return 0.0;
Rt = 1000.0 * 255.0 / (double)temp - 1000.0;
stein = log(Rt / 2200.0) / 3987.0;
@ -128,13 +131,39 @@ static double cvtKlnToC(uint8_t temp) @@ -128,13 +131,39 @@ static double cvtKlnToC(uint8_t temp)
celsius = (1.0 / stein) - 273.15;
// For display of bad data
if (celsius < 0.0)
celsius = 0.0;
if (celsius > 200.0)
celsius = 200.0;
return celsius;
}
static int cvtCToKln(double deg)
{
double R = exp((1/(deg+273.15)-1/(273.15+25))*3987)*2200;
return 256*R/(R+1000);
double Rt, stein, temp;
if (deg < 0.0)
deg = 0.0;
stein = 1.0 / (deg + 273.15);
stein -= 1.0 / (double)(25.0 + 273.15);
Rt = exp(stein * 3987.0) * 2200.0;
if (Rt == -1000.0)
Rt++;
temp = 1000.0 * 256.0 / (Rt + 1000.0);
if (temp > 255)
temp = 255;
if (temp < 0)
temp = 0;
return (int)temp;
}
static char *SendCmdGetReply(struct cgpu_info *klncgpu, char Cmd, int device, int datalen, void *data)
@ -619,7 +648,9 @@ static void get_klondike_statline_before(char *buf, size_t siz, struct cgpu_info @@ -619,7 +648,9 @@ static void get_klondike_statline_before(char *buf, size_t siz, struct cgpu_info
struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
uint8_t temp = 0xFF;
uint16_t fan = 0;
uint16_t clock = 0;
int dev;
char tmp[16];
if (klninfo->status == NULL)
return;
@ -629,11 +660,17 @@ static void get_klondike_statline_before(char *buf, size_t siz, struct cgpu_info @@ -629,11 +660,17 @@ static void get_klondike_statline_before(char *buf, size_t siz, struct cgpu_info
if (klninfo->status[dev].temp < temp)
temp = klninfo->status[dev].temp;
fan += klninfo->cfg[dev].fantarget;
clock += klninfo->cfg[dev].hashclock;
}
fan /= klninfo->status->slavecount+1;
clock /= klninfo->status->slavecount+1;
rd_unlock(&(klninfo->stat_lock));
tailsprintf(buf, siz, " %3.0fC %3d%% | ", cvtKlnToC(temp), fan*100/255);
snprintf(tmp, sizeof(tmp), "%2.0fC", cvtKlnToC(temp));
if (strlen(tmp) < 4)
strcat(tmp, " ");
tailsprintf(buf, siz, "%3dMHz %3d%% %s| ", (int)clock, fan*100/255, tmp);
}
static struct api_data *klondike_api_stats(struct cgpu_info *klncgpu)

46
usbutils.c

@ -26,7 +26,9 @@ @@ -26,7 +26,9 @@
(err) == LIBUSB_TRANSFER_ERROR)
#define NOCONTROLDEV(err) ((err) == LIBUSB_ERROR_NO_DEVICE || \
(err) == LIBUSB_ERROR_OTHER)
(err) == LIBUSB_ERROR_OTHER || \
(err) == LIBUSB_TRANSFER_NO_DEVICE || \
(err) == LIBUSB_TRANSFER_ERROR)
/*
* WARNING - these assume DEVLOCK(cgpu, pstate) is called first and
@ -2207,7 +2209,7 @@ static void init_usb_transfer(struct usb_transfer *ut) @@ -2207,7 +2209,7 @@ static void init_usb_transfer(struct usb_transfer *ut)
ut->transfer->user_data = ut;
}
static void LIBUSB_CALL bulk_callback(struct libusb_transfer *transfer)
static void LIBUSB_CALL transfer_callback(struct libusb_transfer *transfer)
{
struct usb_transfer *ut = transfer->user_data;
@ -2285,7 +2287,7 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle, int intinfo, @@ -2285,7 +2287,7 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle, int intinfo,
mutex_lock(&ut.mutex);
/* We give the transfer no timeout since we manage timeouts ourself */
libusb_fill_bulk_transfer(ut.transfer, dev_handle, endpoint, buf, length,
bulk_callback, &ut, 0);
transfer_callback, &ut, 0);
STATS_TIMEVAL(&tv_start);
cg_rlock(&cgusb_fd_lock);
@ -2702,6 +2704,40 @@ out_noerrmsg: @@ -2702,6 +2704,40 @@ out_noerrmsg:
return err;
}
/* As we do for bulk reads, emulate a sync function for control transfers using
* our own timeouts that takes the same parameters as libusb_control_transfer.
*/
static int usb_control_transfer(libusb_device_handle *dev_handle, uint8_t bmRequestType,
uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
unsigned char *buffer, uint16_t wLength, unsigned int timeout)
{
struct usb_transfer ut;
int err, transferred;
unsigned char *buf;
buf = malloc(70);
if (unlikely(!buf))
quit(1, "Failed to malloc buf in usb_control_transfer");
init_usb_transfer(&ut);
mutex_lock(&ut.mutex);
libusb_fill_control_setup(buf, bmRequestType, bRequest, wValue,
wIndex, wLength);
libusb_fill_control_transfer(ut.transfer, dev_handle, buf, transfer_callback,
&ut, 0);
err = libusb_submit_transfer(ut.transfer);
if (!err)
err = callback_wait(&ut, &transferred, timeout);
if (!err && transferred) {
unsigned char *ofbuf = libusb_control_transfer_get_data(ut.transfer);
memcpy(buffer, ofbuf, transferred);
return transferred;
}
if ((err) == LIBUSB_TRANSFER_CANCELLED)
err = LIBUSB_ERROR_TIMEOUT;
return err;
}
int __usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint32_t *data, int siz, unsigned int timeout, __maybe_unused enum usb_cmds cmd)
{
struct cg_usb_device *usbdev;
@ -2758,7 +2794,7 @@ int __usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bReques @@ -2758,7 +2794,7 @@ int __usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bReques
}
STATS_TIMEVAL(&tv_start);
cg_rlock(&cgusb_fd_lock);
err = libusb_control_transfer(usbdev->handle, request_type,
err = usb_control_transfer(usbdev->handle, request_type,
bRequest, wValue, wIndex, buf, (uint16_t)siz, timeout);
cg_runlock(&cgusb_fd_lock);
STATS_TIMEVAL(&tv_finish);
@ -2839,7 +2875,7 @@ int _usb_transfer_read(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRe @@ -2839,7 +2875,7 @@ int _usb_transfer_read(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRe
memset(tbuf, 0, 64);
STATS_TIMEVAL(&tv_start);
cg_rlock(&cgusb_fd_lock);
err = libusb_control_transfer(usbdev->handle, request_type,
err = usb_control_transfer(usbdev->handle, request_type,
bRequest, wValue, wIndex,
tbuf, (uint16_t)bufsiz, timeout);
cg_runlock(&cgusb_fd_lock);

Loading…
Cancel
Save