hantek-4032l: Get FGPA version.

- get FPGA version in dev_open
 - enable some features only for newer FPGA
- decrease printing number of message of FPGA version

Signed-off-by: Andrej Valek <andy@skyrain.eu>
This commit is contained in:
Andrej Valek 2018-04-29 22:15:12 +02:00 committed by Uwe Hermann
parent 28f2d07fe5
commit 7a7afc0086
3 changed files with 49 additions and 1 deletions

View File

@ -267,6 +267,10 @@ static int dev_open(struct sr_dev_inst *sdi)
return SR_ERR;
}
/* Get FPGA version. */
if ((ret = h4032l_get_fpga_version(sdi)) != SR_OK)
return ret;
return SR_OK;
}

View File

@ -124,7 +124,6 @@ void LIBUSB_CALL h4032l_usb_callback(struct libusb_transfer *transfer)
* First Transfer as next.
*/
status = (struct h4032l_status_packet *)transfer->buffer;
sr_dbg("FPGA version: 0x%x.", status->fpga_version);
if (status->magic != H4032L_STATUS_PACKET_MAGIC)
devc->status = H4032L_STATUS_RESPONSE_STATUS;
else if (status->status == 2)
@ -333,3 +332,46 @@ SR_PRIV int h4032l_dev_open(struct sr_dev_inst *sdi)
libusb_free_device_list(devlist, 1);
return ret;
}
SR_PRIV int h4032l_get_fpga_version(const struct sr_dev_inst *sdi)
{
struct dev_context *devc = sdi->priv;
struct sr_usb_dev_inst *usb = sdi->conn;
struct h4032l_status_packet *status;
int transferred;
int i, ret;
/* Set command to status. */
devc->cmd_pkt.magic = H4032L_CMD_PKT_MAGIC;
devc->cmd_pkt.cmd = CMD_STATUS;
/* Send status request. */
if ((ret = libusb_bulk_transfer(usb->devhdl,
2 | LIBUSB_ENDPOINT_OUT, (unsigned char *)&devc->cmd_pkt,
sizeof(struct h4032l_cmd_pkt), &transferred, H4032L_USB_TIMEOUT)) < 0) {
sr_err("Unable to send FPGA version request: %s.",
libusb_error_name(ret));
return SR_ERR;
}
/* Attempt to get FGPA version. */
for (i = 0; i < 10; i++) {
if ((ret = libusb_bulk_transfer(usb->devhdl,
6 | LIBUSB_ENDPOINT_IN, devc->buffer,
ARRAY_SIZE(devc->buffer), &transferred, H4032L_USB_TIMEOUT)) < 0) {
sr_err("Unable to receive FPGA version: %s.",
libusb_error_name(ret));
return SR_ERR;
}
status = (struct h4032l_status_packet *)devc->buffer;
if (status->magic == H4032L_STATUS_PACKET_MAGIC) {
sr_dbg("FPGA version: 0x%x.", status->fpga_version);
devc->fpga_version = status->fpga_version;
return SR_OK;
}
}
sr_err("Unable to get FPGA version.");
return SR_ERR;
}

View File

@ -126,6 +126,7 @@ struct dev_context {
struct libusb_transfer *usb_transfer;
uint8_t buffer[512];
uint64_t capture_ratio;
uint32_t fpga_version;
};
SR_PRIV int h4032l_receive_data(int fd, int revents, void *cb_data);
@ -133,5 +134,6 @@ SR_PRIV uint16_t h4032l_voltage2pwm(double voltage);
SR_PRIV void LIBUSB_CALL h4032l_usb_callback(struct libusb_transfer *transfer);
SR_PRIV int h4032l_start(const struct sr_dev_inst *sdi);
SR_PRIV int h4032l_dev_open(struct sr_dev_inst *sdi);
SR_PRIV int h4032l_get_fpga_version(const struct sr_dev_inst *sdi);
#endif