]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/fx2lafw/dslogic.c
Fix log varargs bugs indicated by -Wformat
[libsigrok.git] / src / hardware / fx2lafw / dslogic.c
index 715ca8a571bcb69cc2963fbe6a3e5497901004cb..5d543ada237cc62d509a381508a455f5f7416ef6 100644 (file)
 
 #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)
 {
        FILE *fw;
-       struct stat st;
+       GStatBuf st;
        struct sr_usb_dev_inst *usb;
        int chunksize, result, ret;
        unsigned char *buf;
        int sum, transferred;
+       uint8_t cmd[3];
 
        sr_dbg("Uploading FPGA firmware at %s.", filename);
 
        usb = sdi->conn;
-       if (stat(filename, &st) < 0) {
-               sr_err("Unable to upload FPGA firmware: %s", strerror(errno));
+       if (g_stat(filename, &st) < 0) {
+               sr_err("Unable to upload FPGA firmware: %s", g_strerror(errno));
                return SR_ERR;
        }
 
        /* Tell the device firmware is coming. */
+       memset(cmd, 0, sizeof(cmd));
        if ((ret = libusb_control_transfer(usb->devhdl, LIBUSB_REQUEST_TYPE_VENDOR |
                        LIBUSB_ENDPOINT_OUT, DS_CMD_FPGA_FW, 0x0000, 0x0000,
-                       NULL, 0, 3000)) < 0) {
+                       (unsigned char *)&cmd, sizeof(cmd), USB_TIMEOUT)) < 0) {
                sr_err("Failed to upload FPGA firmware: %s.", libusb_error_name(ret));
                return SR_ERR;
        }
        buf = g_malloc(FW_BUFSIZE);
 
        if (!(fw = g_fopen(filename, "rb"))) {
-               sr_err("Unable to open %s for reading: %s.", filename, strerror(errno));
+               sr_err("Unable to open %s for reading: %s.", filename, g_strerror(errno));
                return SR_ERR;
        }
 
        /* 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,14 +78,15 @@ 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;
                        break;
                }
                sum += transferred;
-               sr_spew("Uploaded %d/%d bytes.", sum, st.st_size);
+               sr_spew("Uploaded %d/%" PRIu64 " bytes.",
+                       sum, (uint64_t)st.st_size);
 
                if (transferred != chunksize) {
                        sr_err("Short transfer while uploading FPGA firmware.");
@@ -111,7 +118,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 +139,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 +190,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 +226,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;