From: Uwe Hermann Date: Thu, 9 Apr 2015 17:55:08 +0000 (+0200) Subject: dslogic: Add #defines for timeouts and delays. X-Git-Tag: libsigrok-0.4.0~536 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=4df5739a9f4272e57d737dc3a957b2f723bbaad1;hp=eac0c6132752224f46661ddc5a37a1e0e4694c27 dslogic: Add #defines for timeouts and delays. --- diff --git a/src/hardware/fx2lafw/dslogic.c b/src/hardware/fx2lafw/dslogic.c index 715ca8a5..6a8af130 100644 --- a/src/hardware/fx2lafw/dslogic.c +++ b/src/hardware/fx2lafw/dslogic.c @@ -30,6 +30,10 @@ #define FW_BUFSIZE (4 * 1024) +#define FPGA_UPLOAD_DELAY (10 * 1000) + +#define USB_TIMEOUT (3 * 1000) + int dslogic_fpga_firmware_upload(const struct sr_dev_inst *sdi, const char *filename) { @@ -51,7 +55,7 @@ int dslogic_fpga_firmware_upload(const struct sr_dev_inst *sdi, /* Tell the device firmware is coming. */ if ((ret = libusb_control_transfer(usb->devhdl, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT, DS_CMD_FPGA_FW, 0x0000, 0x0000, - NULL, 0, 3000)) < 0) { + NULL, 0, USB_TIMEOUT)) < 0) { sr_err("Failed to upload FPGA firmware: %s.", libusb_error_name(ret)); return SR_ERR; } @@ -63,7 +67,7 @@ int dslogic_fpga_firmware_upload(const struct sr_dev_inst *sdi, } /* Give the FX2 time to get ready for FPGA firmware upload. */ - g_usleep(10 * 1000); + g_usleep(FPGA_UPLOAD_DELAY); sum = 0; result = SR_OK; @@ -72,7 +76,7 @@ int dslogic_fpga_firmware_upload(const struct sr_dev_inst *sdi, break; if ((ret = libusb_bulk_transfer(usb->devhdl, 2 | LIBUSB_ENDPOINT_OUT, - buf, chunksize, &transferred, 1000)) < 0) { + buf, chunksize, &transferred, USB_TIMEOUT)) < 0) { sr_err("Unable to configure FPGA firmware: %s.", libusb_error_name(ret)); result = SR_ERR; @@ -111,7 +115,7 @@ int dslogic_start_acquisition(const struct sr_dev_inst *sdi) usb = sdi->conn; ret = libusb_control_transfer(usb->devhdl, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT, DS_CMD_START, 0x0000, 0x0000, - (unsigned char *)&mode, sizeof(mode), 3000); + (unsigned char *)&mode, sizeof(mode), USB_TIMEOUT); if (ret < 0) { sr_err("Failed to send start command: %s.", libusb_error_name(ret)); return SR_ERR; @@ -132,7 +136,7 @@ int dslogic_stop_acquisition(const struct sr_dev_inst *sdi) usb = sdi->conn; ret = libusb_control_transfer(usb->devhdl, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT, DS_CMD_START, 0x0000, 0x0000, - (unsigned char *)&mode, sizeof(struct dslogic_mode), 3000); + (unsigned char *)&mode, sizeof(struct dslogic_mode), USB_TIMEOUT); if (ret < 0) { sr_err("Failed to send stop command: %s.", libusb_error_name(ret)); return SR_ERR; @@ -183,7 +187,7 @@ int dslogic_fpga_configure(const struct sr_dev_inst *sdi) ret = libusb_control_transfer(usb->devhdl, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT, DS_CMD_CONFIG, 0x0000, 0x0000, - c, 3, 100); + c, 3, USB_TIMEOUT); if (ret < 0) { sr_err("Failed to send FPGA configure command: %s.", libusb_error_name(ret)); return SR_ERR; @@ -219,8 +223,7 @@ int dslogic_fpga_configure(const struct sr_dev_inst *sdi) len = sizeof(struct dslogic_fpga_config); ret = libusb_bulk_transfer(usb->devhdl, 2 | LIBUSB_ENDPOINT_OUT, - (unsigned char *)&cfg, len, - &transferred, 100); + (unsigned char *)&cfg, len, &transferred, USB_TIMEOUT); if (ret < 0 || transferred != len) { sr_err("Failed to send FPGA configuration: %s.", libusb_error_name(ret)); return SR_ERR; diff --git a/src/hardware/fx2lafw/protocol.c b/src/hardware/fx2lafw/protocol.c index 70825878..6681b9ef 100644 --- a/src/hardware/fx2lafw/protocol.c +++ b/src/hardware/fx2lafw/protocol.c @@ -38,6 +38,8 @@ struct cmd_start_acquisition { #pragma pack(pop) +#define USB_TIMEOUT 100 + static int command_get_fw_version(libusb_device_handle *devhdl, struct version_info *vi) { @@ -45,7 +47,7 @@ static int command_get_fw_version(libusb_device_handle *devhdl, ret = libusb_control_transfer(devhdl, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN, CMD_GET_FW_VERSION, 0x0000, 0x0000, - (unsigned char *)vi, sizeof(struct version_info), 100); + (unsigned char *)vi, sizeof(struct version_info), USB_TIMEOUT); if (ret < 0) { sr_err("Unable to get version info: %s.", @@ -65,7 +67,7 @@ static int command_get_revid_version(struct sr_dev_inst *sdi, uint8_t *revid) cmd = devc->dslogic ? DS_CMD_GET_REVID_VERSION : CMD_GET_REVID_VERSION; ret = libusb_control_transfer(devhdl, LIBUSB_REQUEST_TYPE_VENDOR | - LIBUSB_ENDPOINT_IN, cmd, 0x0000, 0x0000, revid, 1, 100); + LIBUSB_ENDPOINT_IN, cmd, 0x0000, 0x0000, revid, 1, USB_TIMEOUT); if (ret < 0) { sr_err("Unable to get REVID: %s.", libusb_error_name(ret)); @@ -126,7 +128,7 @@ SR_PRIV int fx2lafw_command_start_acquisition(const struct sr_dev_inst *sdi) /* Send the control message. */ ret = libusb_control_transfer(usb->devhdl, LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT, CMD_START, 0x0000, 0x0000, - (unsigned char *)&cmd, sizeof(cmd), 100); + (unsigned char *)&cmd, sizeof(cmd), USB_TIMEOUT); if (ret < 0) { sr_err("Unable to send start command: %s.", libusb_error_name(ret));