X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Ffx2lafw%2Fapi.c;h=4a80b57494d5adb2ba72d7505b56ddd3ac6b822a;hb=803db07a1af036a5da65581ddbac23b7f84a4388;hp=ccd769b2162e0cb43406924c90f7d59d57bf979d;hpb=a7d7f93c1ba6f08c243b894dda29b8ac0349bf10;p=libsigrok.git
diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c
index ccd769b2..4a80b574 100644
--- a/src/hardware/fx2lafw/api.c
+++ b/src/hardware/fx2lafw/api.c
@@ -18,7 +18,9 @@
* along with this program. If not, see .
*/
+#include
#include "protocol.h"
+#include "dslogic.h"
static const struct fx2lafw_profile supported_fx2[] = {
/*
@@ -27,35 +29,48 @@ static const struct fx2lafw_profile supported_fx2[] = {
* ARMFLY AX-Pro
*/
{ 0x08a9, 0x0014, "CWAV", "USBee AX", NULL,
- FIRMWARE_DIR "/fx2lafw-cwav-usbeeax.fw",
+ "fx2lafw-cwav-usbeeax.fw",
0, NULL, NULL},
/*
* CWAV USBee DX
* XZL-Studio DX
*/
{ 0x08a9, 0x0015, "CWAV", "USBee DX", NULL,
- FIRMWARE_DIR "/fx2lafw-cwav-usbeedx.fw",
+ "fx2lafw-cwav-usbeedx.fw",
DEV_CAPS_16BIT, NULL, NULL },
/*
* CWAV USBee SX
*/
{ 0x08a9, 0x0009, "CWAV", "USBee SX", NULL,
- FIRMWARE_DIR "/fx2lafw-cwav-usbeesx.fw",
+ "fx2lafw-cwav-usbeesx.fw",
0, NULL, NULL},
- /*
- * DreamSourceLab DSLogic (before FW upload)
- */
+ /* DreamSourceLab DSLogic (before FW upload) */
{ 0x2a0e, 0x0001, "DreamSourceLab", "DSLogic", NULL,
- FIRMWARE_DIR "/dreamsourcelab-dslogic-fx2.fw",
+ "dreamsourcelab-dslogic-fx2.fw",
DEV_CAPS_16BIT, NULL, NULL},
-
- /*
- * DreamSourceLab DSLogic (after FW upload)
- */
+ /* DreamSourceLab DSLogic (after FW upload) */
{ 0x2a0e, 0x0001, "DreamSourceLab", "DSLogic", NULL,
- FIRMWARE_DIR "/dreamsourcelab-dslogic-fx2.fw",
+ "dreamsourcelab-dslogic-fx2.fw",
+ DEV_CAPS_16BIT, "DreamSourceLab", "DSLogic"},
+
+ /* DreamSourceLab DSCope (before FW upload) */
+ { 0x2a0e, 0x0002, "DreamSourceLab", "DSCope", NULL,
+ "dreamsourcelab-dscope-fx2.fw",
+ DEV_CAPS_16BIT, NULL, NULL},
+ /* DreamSourceLab DSCope (after FW upload) */
+ { 0x2a0e, 0x0002, "DreamSourceLab", "DSCope", NULL,
+ "dreamsourcelab-dscope-fx2.fw",
+ DEV_CAPS_16BIT, "DreamSourceLab", "DSCope"},
+
+ /* DreamSourceLab DSLogic Pro (before FW upload) */
+ { 0x2a0e, 0x0003, "DreamSourceLab", "DSLogic Pro", NULL,
+ "dreamsourcelab-dslogic-pro-fx2.fw",
+ DEV_CAPS_16BIT, NULL, NULL},
+ /* DreamSourceLab DSLogic Pro (after FW upload) */
+ { 0x2a0e, 0x0003, "DreamSourceLab", "DSLogic Pro", NULL,
+ "dreamsourcelab-dslogic-pro-fx2.fw",
DEV_CAPS_16BIT, "DreamSourceLab", "DSLogic"},
/*
@@ -65,7 +80,7 @@ static const struct fx2lafw_profile supported_fx2[] = {
* Robomotic BugLogic 3
*/
{ 0x0925, 0x3881, "Saleae", "Logic", NULL,
- FIRMWARE_DIR "/fx2lafw-saleae-logic.fw",
+ "fx2lafw-saleae-logic.fw",
0, NULL, NULL},
/*
@@ -74,17 +89,31 @@ static const struct fx2lafw_profile supported_fx2[] = {
* Braintechnology USB Interface V2.x
*/
{ 0x04B4, 0x8613, "Cypress", "FX2", NULL,
- FIRMWARE_DIR "/fx2lafw-cypress-fx2.fw",
+ "fx2lafw-cypress-fx2.fw",
DEV_CAPS_16BIT, NULL, NULL },
/*
* Braintechnology USB-LPS
*/
{ 0x16d0, 0x0498, "Braintechnology", "USB-LPS", NULL,
- FIRMWARE_DIR "/fx2lafw-braintechnology-usb-lps.fw",
+ "fx2lafw-braintechnology-usb-lps.fw",
+ DEV_CAPS_16BIT, NULL, NULL },
+
+ /*
+ * sigrok FX2 based 8-channel logic analyzer
+ */
+ { 0x1d50, 0x608c, "sigrok", "FX2 LA (8ch)", NULL,
+ "fx2lafw-sigrok-fx2-8ch.fw",
+ 0, NULL, NULL},
+
+ /*
+ * sigrok FX2 based 16-channel logic analyzer
+ */
+ { 0x1d50, 0x608d, "sigrok", "FX2 LA (16ch)", NULL,
+ "fx2lafw-sigrok-fx2-16ch.fw",
DEV_CAPS_16BIT, NULL, NULL },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
+ ALL_ZERO
};
static const uint32_t drvopts[] = {
@@ -105,9 +134,8 @@ static const uint32_t devopts[] = {
};
static const char *channel_names[] = {
- "0", "1", "2", "3", "4", "5", "6", "7",
- "8", "9", "10", "11", "12", "13", "14", "15",
- NULL,
+ "0", "1", "2", "3", "4", "5", "6", "7",
+ "8", "9", "10", "11", "12", "13", "14", "15",
};
static const int32_t soft_trigger_matches[] = {
@@ -157,20 +185,18 @@ static const uint64_t dslogic_samplerates[] = {
};
SR_PRIV struct sr_dev_driver fx2lafw_driver_info;
-static struct sr_dev_driver *di = &fx2lafw_driver_info;
-static int init(struct sr_context *sr_ctx)
+static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx)
{
return std_init(sr_ctx, di, LOG_PREFIX);
}
-static GSList *scan(GSList *options)
+static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
struct drv_context *drvc;
struct dev_context *devc;
struct sr_dev_inst *sdi;
struct sr_usb_dev_inst *usb;
- struct sr_channel *ch;
struct sr_config *src;
const struct fx2lafw_profile *prof;
GSList *l, *devices, *conn_devices;
@@ -182,7 +208,7 @@ static GSList *scan(GSList *options)
const char *conn;
char manufacturer[64], product[64], serial_num[64], connection_id[64];
- drvc = di->priv;
+ drvc = di->context;
conn = NULL;
for (l = options; l; l = l->next) {
@@ -216,11 +242,7 @@ static GSList *scan(GSList *options)
continue;
}
- if ((ret = libusb_get_device_descriptor( devlist[i], &des)) != 0) {
- sr_warn("Failed to get device descriptor: %s.",
- libusb_error_name(ret));
- continue;
- }
+ libusb_get_device_descriptor( devlist[i], &des);
if ((ret = libusb_open(devlist[i], &hdl)) < 0)
continue;
@@ -287,11 +309,9 @@ static GSList *scan(GSList *options)
/* Fill in channellist according to this device's profile. */
num_logic_channels = prof->dev_caps & DEV_CAPS_16BIT ? 16 : 8;
- for (j = 0; j < num_logic_channels; j++) {
- ch = sr_channel_new(j, SR_CHANNEL_LOGIC, TRUE,
+ for (j = 0; j < num_logic_channels; j++)
+ sr_channel_new(sdi, j, SR_CHANNEL_LOGIC, TRUE,
channel_names[j]);
- sdi->channels = g_slist_append(sdi->channels, ch);
- }
devc = fx2lafw_dev_new();
devc->profile = prof;
@@ -300,18 +320,20 @@ static GSList *scan(GSList *options)
drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
- if (strcmp(prof->model, "DSLogic")) {
+ if (!strcmp(prof->model, "DSLogic")
+ || !strcmp(prof->model, "DSLogic Pro")
+ || !strcmp(prof->model, "DSCope")) {
+ devc->dslogic = TRUE;
+ devc->samplerates = dslogic_samplerates;
+ devc->num_samplerates = ARRAY_SIZE(dslogic_samplerates);
+ has_firmware = match_manuf_prod(devlist[i], "DreamSourceLab", "DSLogic")
+ || match_manuf_prod(devlist[i], "DreamSourceLab", "DSCope");
+ } else {
devc->dslogic = FALSE;
devc->samplerates = samplerates;
devc->num_samplerates = ARRAY_SIZE(samplerates);
has_firmware = match_manuf_prod(devlist[i],
"sigrok", "fx2lafw");
- } else {
- devc->dslogic = TRUE;
- devc->samplerates = dslogic_samplerates;
- devc->num_samplerates = ARRAY_SIZE(dslogic_samplerates);
- has_firmware = match_manuf_prod(devlist[i],
- "DreamSourceLab", "DSLogic");
}
if (has_firmware) {
@@ -322,8 +344,8 @@ static GSList *scan(GSList *options)
sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]),
libusb_get_device_address(devlist[i]), NULL);
} else {
- if (ezusb_upload_firmware(devlist[i], USB_CONFIGURATION,
- prof->firmware) == SR_OK)
+ if (ezusb_upload_firmware(drvc->sr_ctx, devlist[i],
+ USB_CONFIGURATION, prof->firmware) == SR_OK)
/* Store when this device's FW was updated. */
devc->fw_updated = g_get_monotonic_time();
else
@@ -342,15 +364,17 @@ static GSList *scan(GSList *options)
return devices;
}
-static GSList *dev_list(void)
+static GSList *dev_list(const struct sr_dev_driver *di)
{
- return ((struct drv_context *)(di->priv))->instances;
+ return ((struct drv_context *)(di->context))->instances;
}
static int dev_open(struct sr_dev_inst *sdi)
{
+ struct sr_dev_driver *di = sdi->driver;
struct sr_usb_dev_inst *usb;
struct dev_context *devc;
+ const char *fpga_firmware = NULL;
int ret;
int64_t timediff_us, timediff_ms;
@@ -411,8 +435,16 @@ static int dev_open(struct sr_dev_inst *sdi)
}
if (devc->dslogic) {
- if ((ret = dslogic_fpga_firmware_upload(usb->devhdl,
- DSLOGIC_FPGA_FIRMWARE)) != SR_OK)
+ if (!strcmp(devc->profile->model, "DSLogic")) {
+ fpga_firmware = DSLOGIC_FPGA_FIRMWARE;
+ } else if (!strcmp(devc->profile->model, "DSLogic Pro")) {
+ fpga_firmware = DSLOGIC_PRO_FPGA_FIRMWARE;
+ } else if (!strcmp(devc->profile->model, "DSCope")) {
+ fpga_firmware = DSCOPE_FPGA_FIRMWARE;
+ }
+
+ if ((ret = dslogic_fpga_firmware_upload(sdi,
+ fpga_firmware)) != SR_OK)
return ret;
}
@@ -429,7 +461,7 @@ static int dev_close(struct sr_dev_inst *sdi)
struct sr_usb_dev_inst *usb;
usb = sdi->conn;
- if (usb->devhdl == NULL)
+ if (!usb->devhdl)
return SR_ERR;
sr_info("fx2lafw: Closing device on %d.%d (logical) / %s (physical) interface %d.",
@@ -442,18 +474,17 @@ static int dev_close(struct sr_dev_inst *sdi)
return SR_OK;
}
-static int cleanup(void)
+static int cleanup(const struct sr_dev_driver *di)
{
int ret;
struct drv_context *drvc;
- if (!(drvc = di->priv))
+ if (!(drvc = di->context))
return SR_OK;
ret = std_dev_clear(di, NULL);
g_free(drvc);
- di->priv = NULL;
return ret;
}
@@ -505,8 +536,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
{
struct dev_context *devc;
uint64_t arg;
- unsigned int i;
- int ret;
+ int i, ret;
(void)cg;
@@ -521,30 +551,26 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
ret = SR_OK;
switch (key) {
- case SR_CONF_SAMPLERATE:
- arg = g_variant_get_uint64(data);
- for (i = 0; i < ARRAY_SIZE(samplerates); i++) {
- if (samplerates[i] == arg) {
- devc->cur_samplerate = arg;
- break;
- }
+ case SR_CONF_SAMPLERATE:
+ arg = g_variant_get_uint64(data);
+ for (i = 0; i < devc->num_samplerates; i++) {
+ if (devc->samplerates[i] == arg) {
+ devc->cur_samplerate = arg;
+ break;
}
- if (i == ARRAY_SIZE(samplerates))
- ret = SR_ERR_ARG;
- break;
- case SR_CONF_LIMIT_SAMPLES:
- devc->limit_samples = g_variant_get_uint64(data);
- break;
- case SR_CONF_CAPTURE_RATIO:
- devc->capture_ratio = g_variant_get_uint64(data);
- if (devc->capture_ratio > 100) {
- devc->capture_ratio = 0;
- ret = SR_ERR;
- } else
- ret = SR_OK;
- break;
- default:
- ret = SR_ERR_NA;
+ }
+ if (i == devc->num_samplerates)
+ ret = SR_ERR_ARG;
+ break;
+ case SR_CONF_LIMIT_SAMPLES:
+ devc->limit_samples = g_variant_get_uint64(data);
+ break;
+ case SR_CONF_CAPTURE_RATIO:
+ devc->capture_ratio = g_variant_get_uint64(data);
+ ret = (devc->capture_ratio > 100) ? SR_ERR : SR_OK;
+ break;
+ default:
+ ret = SR_ERR_NA;
}
return ret;
@@ -601,9 +627,8 @@ static int receive_data(int fd, int revents, void *cb_data)
(void)fd;
(void)revents;
- (void)cb_data;
- drvc = di->priv;
+ drvc = (struct drv_context *)cb_data;
tv.tv_sec = tv.tv_usec = 0;
libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv);
@@ -611,26 +636,20 @@ static int receive_data(int fd, int revents, void *cb_data)
return TRUE;
}
-static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
+static int start_transfers(const struct sr_dev_inst *sdi)
{
struct dev_context *devc;
- struct drv_context *drvc;
struct sr_usb_dev_inst *usb;
struct sr_trigger *trigger;
struct libusb_transfer *transfer;
- unsigned int i, timeout, num_transfers;
- int ret;
+ unsigned int i, num_transfers;
+ int endpoint, timeout, ret;
unsigned char *buf;
size_t size;
- if (sdi->status != SR_ST_ACTIVE)
- return SR_ERR_DEV_CLOSED;
-
- drvc = di->priv;
devc = sdi->priv;
usb = sdi->conn;
- devc->cb_data = cb_data;
devc->sent_samples = 0;
devc->acq_aborted = FALSE;
devc->empty_transfer_count = 0;
@@ -640,13 +659,12 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
if (devc->limit_samples > 0)
pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100;
devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples);
- if (devc->stl == NULL)
+ if (!devc->stl)
return SR_ERR_MALLOC;
devc->trigger_fired = FALSE;
} else
devc->trigger_fired = TRUE;
- timeout = fx2lafw_get_timeout(devc);
num_transfers = fx2lafw_get_number_of_transfers(devc);
size = fx2lafw_get_buffer_size(devc);
devc->submitted_transfers = 0;
@@ -657,6 +675,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
return SR_ERR_MALLOC;
}
+ timeout = fx2lafw_get_timeout(devc);
+ endpoint = devc->dslogic ? 6 : 2;
devc->num_transfers = num_transfers;
for (i = 0; i < num_transfers; i++) {
if (!(buf = g_try_malloc(size))) {
@@ -665,7 +685,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
}
transfer = libusb_alloc_transfer(0);
libusb_fill_bulk_transfer(transfer, usb->devhdl,
- 2 | LIBUSB_ENDPOINT_IN, buf, size,
+ endpoint | LIBUSB_ENDPOINT_IN, buf, size,
fx2lafw_receive_transfer, (void *)sdi, timeout);
if ((ret = libusb_submit_transfer(transfer)) != 0) {
sr_err("Failed to submit transfer: %s.",
@@ -679,16 +699,96 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
devc->submitted_transfers++;
}
- devc->ctx = drvc->sr_ctx;
+ /* Send header packet to the session bus. */
+ std_session_send_df_header(sdi, LOG_PREFIX);
- usb_source_add(sdi->session, devc->ctx, timeout, receive_data, NULL);
+ return SR_OK;
+}
- /* Send header packet to the session bus. */
- std_session_send_df_header(cb_data, LOG_PREFIX);
+static void LIBUSB_CALL dslogic_trigger_receive(struct libusb_transfer *transfer)
+{
+ const struct sr_dev_inst *sdi;
+ struct dslogic_trigger_pos *tpos;
+
+ sdi = transfer->user_data;
+
+ if (transfer->status == LIBUSB_TRANSFER_COMPLETED
+ && transfer->actual_length == sizeof(struct dslogic_trigger_pos)) {
+ tpos = (struct dslogic_trigger_pos *)transfer->buffer;
+ sr_dbg("tpos real_pos %.8x ram_saddr %.8x", tpos->real_pos, tpos->ram_saddr);
+ g_free(tpos);
+ start_transfers(sdi);
+ }
+
+ libusb_free_transfer(transfer);
+
+}
- if ((ret = fx2lafw_command_start_acquisition(sdi)) != SR_OK) {
- fx2lafw_abort_acquisition(devc);
+static int dslogic_trigger_request(const struct sr_dev_inst *sdi)
+{
+ struct sr_usb_dev_inst *usb;
+ struct libusb_transfer *transfer;
+ struct dslogic_trigger_pos *tpos;
+ int ret;
+
+ usb = sdi->conn;
+
+ if ((ret = dslogic_stop_acquisition(sdi)) != SR_OK)
return ret;
+
+ if ((ret = dslogic_fpga_configure(sdi)) != SR_OK)
+ return ret;
+
+ if ((ret = dslogic_start_acquisition(sdi)) != SR_OK)
+ return ret;
+
+ sr_dbg("Getting trigger.");
+ tpos = g_malloc(sizeof(struct dslogic_trigger_pos));
+ transfer = libusb_alloc_transfer(0);
+ libusb_fill_bulk_transfer(transfer, usb->devhdl, 6 | LIBUSB_ENDPOINT_IN,
+ (unsigned char *)tpos, sizeof(struct dslogic_trigger_pos),
+ dslogic_trigger_receive, (void *)sdi, 0);
+ if ((ret = libusb_submit_transfer(transfer)) < 0) {
+ sr_err("Failed to request trigger: %s.", libusb_error_name(ret));
+ libusb_free_transfer(transfer);
+ g_free(tpos);
+ return SR_ERR;
+ }
+
+ return ret;
+}
+
+static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
+{
+ struct sr_dev_driver *di;
+ struct drv_context *drvc;
+ struct dev_context *devc;
+ int timeout, ret;
+
+ if (sdi->status != SR_ST_ACTIVE)
+ return SR_ERR_DEV_CLOSED;
+
+ di = sdi->driver;
+ drvc = di->context;
+ devc = sdi->priv;
+
+ devc->ctx = drvc->sr_ctx;
+ devc->cb_data = cb_data;
+ devc->sent_samples = 0;
+ devc->empty_transfer_count = 0;
+ devc->acq_aborted = FALSE;
+
+ timeout = fx2lafw_get_timeout(devc);
+ usb_source_add(sdi->session, devc->ctx, timeout, receive_data, drvc);
+
+ if (devc->dslogic) {
+ dslogic_trigger_request(sdi);
+ } else {
+ start_transfers(sdi);
+ if ((ret = fx2lafw_command_start_acquisition(sdi)) != SR_OK) {
+ fx2lafw_abort_acquisition(devc);
+ return ret;
+ }
}
return SR_OK;
@@ -719,5 +819,5 @@ SR_PRIV struct sr_dev_driver fx2lafw_driver_info = {
.dev_close = dev_close,
.dev_acquisition_start = dev_acquisition_start,
.dev_acquisition_stop = dev_acquisition_stop,
- .priv = NULL,
+ .context = NULL,
};