]> sigrok.org Git - libsigrok.git/commitdiff
fx2lafw: Added command to verify firmware version
authorJoel Holdsworth <redacted>
Tue, 10 Apr 2012 17:27:24 +0000 (18:27 +0100)
committerJoel Holdsworth <redacted>
Tue, 10 Apr 2012 17:27:24 +0000 (18:27 +0100)
hardware/fx2lafw/command.c
hardware/fx2lafw/command.h
hardware/fx2lafw/fx2lafw.c
hardware/fx2lafw/fx2lafw.h

index 04ab56c56697a6109e1ddab437930dc1c1594941..ffe18da64ebf01c90ebf04aca9959ed33c5b0205 100644 (file)
 #include "sigrok.h"
 #include "sigrok-internal.h"
 
+SR_PRIV int command_get_fw_version(libusb_device_handle *devhdl,
+                                  struct version_info *vi)
+{
+       const int 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);
+
+       if(ret < 0) {
+               sr_err("fx2lafw: Unable to get version info: %d.", ret);
+               return SR_ERR;
+       }
+
+       return SR_OK;
+}
+
 SR_PRIV int command_start_acquisition(libusb_device_handle *devhdl,
                                      uint64_t samplerate)
 {
index cdc9f1eb449e31b014572cc40ed9d89fd7b209d0..deacbecd0d4a23edba5981a598ec77cae1f1c77c 100644 (file)
 
 #pragma pack(push, 1)
 
+struct version_info {
+       uint8_t major;
+       uint8_t minor;
+};
+
 struct cmd_start_acquisition {
        uint8_t flags;
        uint8_t sample_delay;
@@ -40,6 +45,9 @@ struct cmd_start_acquisition {
 
 #pragma pack(pop)
 
+SR_PRIV int command_get_fw_version(libusb_device_handle *devhdl,
+                                  struct version_info *vi);
+
 SR_PRIV int command_start_acquisition(libusb_device_handle *devhdl,
                                      uint64_t samplerate);
 
index 42d994d953ac55764e3782996797edee932a5201..5ec1f492f2ecdd902739b8c7fa73d0a9b1f9c8cd 100644 (file)
@@ -164,6 +164,7 @@ static int fx2lafw_dev_open(int dev_index)
        struct libusb_device_descriptor des;
        struct sr_dev_inst *sdi;
        struct context *ctx;
+       struct version_info vi;
        int ret, skip, i;
 
        if (!(sdi = sr_dev_inst_get(dev_insts, dev_index)))
@@ -217,16 +218,31 @@ static int fx2lafw_dev_open(int dev_index)
                                 * so we don't know the address yet.
                                 */
                                ctx->usb->address = libusb_get_device_address(devlist[i]);
-
-                       sdi->status = SR_ST_ACTIVE;
-                       sr_info("fx2lafw: Opened device %d on %d.%d "
-                               "interface %d.", sdi->index, ctx->usb->bus,
-                               ctx->usb->address, USB_INTERFACE);
                } else {
                        sr_err("fx2lafw: Failed to open device: %d.", ret);
+                       break;
+               }
+
+               if((ret = command_get_fw_version(ctx->usb->devhdl, &vi)) != SR_OK) {
+                       sr_err("fx2lafw: Failed to retrieve "
+                               "firmware version information");
+                       break;
                }
 
-               /* if we made it here, we handled the device one way or another */
+               if(vi.major != FX2LAFW_VERSION_MAJOR ||
+                       vi.minor != FX2LAFW_VERSION_MINOR) {
+                       sr_err("fx2lafw: Expected firmware version %d.%02d "
+                               "got %d.%02d", FX2LAFW_VERSION_MAJOR,
+                               FX2LAFW_VERSION_MINOR, vi.major, vi.minor);
+                       break;
+               }
+
+               sdi->status = SR_ST_ACTIVE;
+               sr_info("fx2lafw: Opened device %d on %d.%d "
+                       "interface %d, firmware version %d.%02d",
+                       sdi->index, ctx->usb->bus, ctx->usb->address,
+                       USB_INTERFACE, vi.major, vi.minor);
+
                break;
        }
        libusb_free_device_list(devlist, 1);
index 48b6c441d5626bcf58691d52946ac50c03855f03..b03e86ab6fb94f1261032cc4f459eac240a0150d 100644 (file)
 #define NUM_SIMUL_TRANSFERS    32
 #define MAX_EMPTY_TRANSFERS    (NUM_SIMUL_TRANSFERS * 2)
 
+#define FX2LAFW_VERSION_MAJOR  1
+#define FX2LAFW_VERSION_MINOR  0
+
+
 /* Software trigger implementation: positive values indicate trigger stage. */
 #define TRIGGER_FIRED          -1