fx2lafw: Added command to verify firmware version

This commit is contained in:
Joel Holdsworth 2012-04-10 18:27:24 +01:00
parent 6fbe5e6081
commit 13bf7eccbb
4 changed files with 51 additions and 6 deletions

View File

@ -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)
{

View File

@ -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);

View 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 we made it here, we handled the device one way or another */
if((ret = command_get_fw_version(ctx->usb->devhdl, &vi)) != SR_OK) {
sr_err("fx2lafw: Failed to retrieve "
"firmware version information");
break;
}
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);

View File

@ -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