From: Joel Holdsworth Date: Tue, 10 Apr 2012 17:27:24 +0000 (+0100) Subject: fx2lafw: Added command to verify firmware version X-Git-Tag: libsigrok-0.1.0~6 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=13bf7eccbb08214c3d6d53da5b5b6a269a64a779;p=libsigrok.git fx2lafw: Added command to verify firmware version --- diff --git a/hardware/fx2lafw/command.c b/hardware/fx2lafw/command.c index 04ab56c5..ffe18da6 100644 --- a/hardware/fx2lafw/command.c +++ b/hardware/fx2lafw/command.c @@ -22,6 +22,23 @@ #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) { diff --git a/hardware/fx2lafw/command.h b/hardware/fx2lafw/command.h index cdc9f1eb..deacbecd 100644 --- a/hardware/fx2lafw/command.h +++ b/hardware/fx2lafw/command.h @@ -33,6 +33,11 @@ #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); diff --git a/hardware/fx2lafw/fx2lafw.c b/hardware/fx2lafw/fx2lafw.c index 42d994d9..5ec1f492 100644 --- a/hardware/fx2lafw/fx2lafw.c +++ b/hardware/fx2lafw/fx2lafw.c @@ -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); diff --git a/hardware/fx2lafw/fx2lafw.h b/hardware/fx2lafw/fx2lafw.h index 48b6c441..b03e86ab 100644 --- a/hardware/fx2lafw/fx2lafw.h +++ b/hardware/fx2lafw/fx2lafw.h @@ -29,6 +29,10 @@ #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