Browse Source

Implement avalon_ready and avalon_wait_ready functions for when usb is ready to receive commands.

nfactor-troky
Con Kolivas 12 years ago
parent
commit
a32e521d0a
  1. 6
      driver-avalon.c
  2. 1
      driver-avalon.h
  3. 20
      usbutils.c
  4. 1
      usbutils.h

6
driver-avalon.c

@ -121,6 +121,12 @@ static inline void avalon_create_task(struct avalon_task *at,
memcpy(at->data, work->data + 64, 12); memcpy(at->data, work->data + 64, 12);
} }
static void avalon_wait_ready(struct cgpu_info *avalon)
{
while (!avalon_ready(avalon))
nmsleep(40);
}
static int avalon_write(struct cgpu_info *avalon, char *buf, ssize_t len) static int avalon_write(struct cgpu_info *avalon, char *buf, ssize_t len)
{ {
ssize_t wrote = 0; ssize_t wrote = 0;

1
driver-avalon.h

@ -123,6 +123,7 @@ struct avalon_info {
#define AVA_SEND_OK 0 #define AVA_SEND_OK 0
#define avalon_buffer_full(avalon) !usb_ftdi_cts(avalon) #define avalon_buffer_full(avalon) !usb_ftdi_cts(avalon)
#define avalon_ready(avalon) usb_ftdi_ctw(avalon)
#define AVALON_READ_TIME(baud) ((double)AVALON_READ_SIZE * (double)8.0 / (double)(baud)) #define AVALON_READ_TIME(baud) ((double)AVALON_READ_SIZE * (double)8.0 / (double)(baud))
#define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1] #define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1]

20
usbutils.c

@ -2240,6 +2240,26 @@ int usb_ftdi_cts(struct cgpu_info *cgpu)
return (ret & FTDI_RS0_CTS); return (ret & FTDI_RS0_CTS);
} }
#define FTDI_RS_DR 1
#define FTDI_RS_OE (1<<1)
#define FTDI_RS_PE (1<<2)
#define FTDI_RS_FE (1<<3)
#define FTDI_RS_BI (1<<4)
#define FTDI_RS_THRE (1<<5)
#define FTDI_RS_TEMT (1<<6)
#define FTDI_RS_FIFO (1<<7)
int usb_ftdi_ctw(struct cgpu_info *cgpu)
{
struct cg_usb_device *usbdev = cgpu->usbdev;
unsigned char buf[2];
libusb_control_transfer(usbdev->handle, (uint8_t)FTDI_TYPE_IN,
(uint8_t)5, (uint16_t)0, (uint16_t)0,
buf, 2, DEVTIMEOUT);
return ((buf[1] & FTDI_RS_THRE) && (buf[1] & FTDI_RS_TEMT));
}
int _usb_write(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, __maybe_unused enum usb_cmds cmd) int _usb_write(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, __maybe_unused enum usb_cmds cmd)
{ {
struct cg_usb_device *usbdev = cgpu->usbdev; struct cg_usb_device *usbdev = cgpu->usbdev;

1
usbutils.h

@ -238,6 +238,7 @@ struct api_data *api_usb_stats(int *count);
void update_usb_stats(struct cgpu_info *cgpu); void update_usb_stats(struct cgpu_info *cgpu);
int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, const char *end, enum usb_cmds cmd, bool readonce); int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, const char *end, enum usb_cmds cmd, bool readonce);
int usb_ftdi_cts(struct cgpu_info *cgpu); int usb_ftdi_cts(struct cgpu_info *cgpu);
int usb_ftdi_ctw(struct cgpu_info *cgpu);
int _usb_write(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, enum usb_cmds); int _usb_write(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, enum usb_cmds);
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, enum usb_cmds cmd); 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, enum usb_cmds cmd);
int _usb_transfer_read(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, char *buf, int bufsiz, int *amount, unsigned int timeout, enum usb_cmds cmd); int _usb_transfer_read(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, char *buf, int bufsiz, int *amount, unsigned int timeout, enum usb_cmds cmd);

Loading…
Cancel
Save