int ret;
int xfer_len;
- if (usb == NULL || command == NULL || cmd_len <= 0)
- return SR_ERR_ARG;
+ if (!usb || !command || cmd_len <= 0)
+ return SR_ERR_BUG;
xfer_len = 0;
ret = libusb_bulk_transfer(usb->devhdl, EP_COMMAND,
(unsigned char *)command, cmd_len * 2,
&xfer_len, USB_TIMEOUT);
if (ret != 0) {
- sr_dbg("Failed to send command %u: %s.",
- LWLA_READ16(command), libusb_error_name(ret));
+ sr_dbg("Failed to send command %d: %s.",
+ LWLA_TO_UINT16(command[0]), libusb_error_name(ret));
return SR_ERR;
}
if (xfer_len != cmd_len * 2) {
- sr_dbg("Failed to send command %u: incorrect length %d != %d.",
- LWLA_READ16(command), xfer_len, cmd_len * 2);
+ sr_dbg("Failed to send command %d: incorrect length %d != %d.",
+ LWLA_TO_UINT16(command[0]), xfer_len, cmd_len * 2);
return SR_ERR;
}
return SR_OK;
}
SR_PRIV int lwla_receive_reply(const struct sr_usb_dev_inst *usb,
- uint16_t *reply, int reply_len, int expect_len)
+ uint32_t *reply, int reply_len, int expect_len)
{
int ret;
int xfer_len;
- if (usb == NULL || reply == NULL || reply_len <= 0)
- return SR_ERR_ARG;
+ if (!usb || !reply || reply_len <= 0)
+ return SR_ERR_BUG;
xfer_len = 0;
ret = libusb_bulk_transfer(usb->devhdl, EP_REPLY,
- (unsigned char *)reply, reply_len * 2,
+ (unsigned char *)reply, reply_len * 4,
&xfer_len, USB_TIMEOUT);
if (ret != 0) {
sr_dbg("Failed to receive reply: %s.", libusb_error_name(ret));
return SR_ERR;
}
- if (xfer_len != expect_len * 2) {
+ if (xfer_len != expect_len * 4) {
sr_dbg("Failed to receive reply: incorrect length %d != %d.",
- xfer_len, expect_len * 2);
+ xfer_len, expect_len * 4);
return SR_ERR;
}
return SR_OK;
{
int ret;
uint16_t command[2];
- uint16_t reply[256]; /* full EP buffer to avoid overflows */
+ uint32_t reply[128]; /* full EP buffer to avoid overflows */
command[0] = LWLA_WORD(CMD_READ_REG);
command[1] = LWLA_WORD(reg);
if (ret != SR_OK)
return ret;
- ret = lwla_receive_reply(usb, reply, G_N_ELEMENTS(reply), 2);
+ ret = lwla_receive_reply(usb, reply, G_N_ELEMENTS(reply), 1);
if (ret == SR_OK)
- *value = LWLA_READ32(reply);
+ *value = LWLA_TO_UINT32(reply[0]);
return ret;
}