X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fsysclk-lwla%2Flwla.c;h=ab9fece8df1a41614d126124f6e90c34c2095875;hb=e57057aee778e723da572a6b5e2bd01526cc7beb;hp=dcb7af7782d72fb8384c9289348888a3f530f51a;hpb=155b680da482cea2381becb73c51cfb838bff31e;p=libsigrok.git diff --git a/src/hardware/sysclk-lwla/lwla.c b/src/hardware/sysclk-lwla/lwla.c index dcb7af77..ab9fece8 100644 --- a/src/hardware/sysclk-lwla/lwla.c +++ b/src/hardware/sysclk-lwla/lwla.c @@ -17,27 +17,30 @@ * along with this program. If not, see . */ -#include "lwla.h" -#include "protocol.h" -#include "libsigrok-internal.h" +#include #include +#include #include +#include +#include "libsigrok-internal.h" +#include "protocol.h" +#include "lwla.h" -#define BITSTREAM_MAX_SIZE 262144 /* bitstream size limit for safety */ -#define BITSTREAM_HEADER_SIZE 4 /* transfer header size in bytes */ +#define BITSTREAM_MAX_SIZE (256 * 1024) /* bitstream size limit for safety */ +#define BITSTREAM_HEADER_SIZE 4 /* transfer header size in bytes */ /* Load a bitstream file into memory. Returns a newly allocated array * consisting of a 32-bit length field followed by the bitstream data. */ static unsigned char *load_bitstream_file(const char *filename, int *length_p) { - GStatBuf statbuf; + struct stat statbuf; FILE *file; unsigned char *stream; size_t length, count; /* Retrieve and validate the file size. */ - if (g_stat(filename, &statbuf) < 0) { + if (stat(filename, &statbuf) < 0) { sr_err("Failed to access bitstream file: %s.", g_strerror(errno)); return NULL; @@ -110,7 +113,7 @@ SR_PRIV int lwla_send_bitstream(const struct sr_usb_dev_inst *usb, /* Transfer the entire bitstream in one URB. */ ret = libusb_bulk_transfer(usb->devhdl, EP_BITSTREAM, - stream, length, &xfer_len, USB_TIMEOUT); + stream, length, &xfer_len, USB_TIMEOUT_MS); g_free(stream); if (ret != 0) { @@ -126,7 +129,7 @@ SR_PRIV int lwla_send_bitstream(const struct sr_usb_dev_inst *usb, sr_info("FPGA bitstream download of %d bytes done.", xfer_len); /* This delay appears to be necessary for reliable operation. */ - g_usleep(30000); + g_usleep(30 * 1000); return SR_OK; } @@ -143,7 +146,7 @@ SR_PRIV int lwla_send_command(const struct sr_usb_dev_inst *usb, xfer_len = 0; ret = libusb_bulk_transfer(usb->devhdl, EP_COMMAND, (unsigned char *)command, cmd_len * 2, - &xfer_len, USB_TIMEOUT); + &xfer_len, USB_TIMEOUT_MS); if (ret != 0) { sr_dbg("Failed to send command %d: %s.", LWLA_TO_UINT16(command[0]), libusb_error_name(ret)); @@ -169,7 +172,7 @@ SR_PRIV int lwla_receive_reply(const struct sr_usb_dev_inst *usb, xfer_len = 0; ret = libusb_bulk_transfer(usb->devhdl, EP_REPLY, (unsigned char *)reply, reply_len * 4, - &xfer_len, USB_TIMEOUT); + &xfer_len, USB_TIMEOUT_MS); if (ret != 0) { sr_dbg("Failed to receive reply: %s.", libusb_error_name(ret)); return SR_ERR; @@ -192,12 +195,12 @@ SR_PRIV int lwla_read_reg(const struct sr_usb_dev_inst *usb, command[0] = LWLA_WORD(CMD_READ_REG); command[1] = LWLA_WORD(reg); - ret = lwla_send_command(usb, command, G_N_ELEMENTS(command)); + ret = lwla_send_command(usb, command, ARRAY_SIZE(command)); if (ret != SR_OK) return ret; - ret = lwla_receive_reply(usb, reply, G_N_ELEMENTS(reply), 1); + ret = lwla_receive_reply(usb, reply, ARRAY_SIZE(reply), 1); if (ret == SR_OK) *value = LWLA_TO_UINT32(reply[0]); @@ -215,7 +218,7 @@ SR_PRIV int lwla_write_reg(const struct sr_usb_dev_inst *usb, command[2] = LWLA_WORD_0(value); command[3] = LWLA_WORD_1(value); - return lwla_send_command(usb, command, G_N_ELEMENTS(command)); + return lwla_send_command(usb, command, ARRAY_SIZE(command)); } SR_PRIV int lwla_write_regs(const struct sr_usb_dev_inst *usb,