return SR_OK;
}
-static int hw_dev_open(int dev_index)
+static int hw_dev_open(struct sr_dev_inst *sdi)
{
- struct sr_dev_inst *sdi;
struct context *ctx;
int ret;
- if (!(sdi = sr_dev_inst_get(adi->instances, dev_index)))
- return SR_ERR;
-
ctx = sdi->priv;
/* Make sure it's an ASIX SIGMA. */
return SR_OK;
}
-static int hw_dev_close(int dev_index)
+static int hw_dev_close(struct sr_dev_inst *sdi)
{
- struct sr_dev_inst *sdi;
struct context *ctx;
- if (!(sdi = sr_dev_inst_get(adi->instances, dev_index))) {
- sr_err("sigma: %s: sdi was NULL", __func__);
- return SR_ERR_BUG;
- }
-
if (!(ctx = sdi->priv)) {
sr_err("sigma: %s: sdi->priv was NULL", __func__);
return SR_ERR_BUG;
return NULL;
}
-static int hw_dev_open(int dev_index)
+static int hw_dev_open(struct sr_dev_inst *sdi)
{
- int ret;
- struct sr_dev_inst *sdi;
struct context *ctx;
-
- if (!(sdi = sr_dev_inst_get(cdi->instances, dev_index))) {
- sr_err("la8: %s: sdi was NULL", __func__);
- return SR_ERR_BUG;
- }
+ int ret;
if (!(ctx = sdi->priv)) {
sr_err("la8: %s: sdi->priv was NULL", __func__);
return SR_ERR;
}
-static int hw_dev_close(int dev_index)
+static int hw_dev_close(struct sr_dev_inst *sdi)
{
- struct sr_dev_inst *sdi;
struct context *ctx;
- if (!(sdi = sr_dev_inst_get(cdi->instances, dev_index))) {
- sr_err("la8: %s: sdi was NULL", __func__);
- return SR_ERR_BUG;
- }
-
if (!(ctx = sdi->priv)) {
sr_err("la8: %s: sdi->priv was NULL", __func__);
return SR_ERR_BUG;
return devices;
}
-static int hw_dev_open(int dev_index)
+static int hw_dev_open(struct sr_dev_inst *sdi)
{
/* Avoid compiler warnings. */
- (void)dev_index;
+ (void)sdi;
/* Nothing needed so far. */
return SR_OK;
}
-static int hw_dev_close(int dev_index)
+static int hw_dev_close(struct sr_dev_inst *sdi)
{
/* Avoid compiler warnings. */
- (void)dev_index;
+ (void)sdi;
/* Nothing needed so far. */
SR_PRIV struct sr_dev_driver fx2lafw_driver_info;
static struct sr_dev_driver *fdi = &fx2lafw_driver_info;
+static int hw_dev_close(struct sr_dev_inst *sdi);
static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
const void *value);
static int hw_dev_acquisition_stop(int dev_index, void *cb_data);
return ret;
}
-static int fx2lafw_dev_open(int dev_index)
+static int fx2lafw_dev_open(struct sr_dev_inst *sdi)
{
libusb_device **devlist;
struct libusb_device_descriptor des;
- struct sr_dev_inst *sdi;
struct context *ctx;
struct version_info vi;
int ret, skip, i;
uint8_t revid;
- if (!(sdi = sr_dev_inst_get(fdi->instances, dev_index)))
- return SR_ERR;
ctx = sdi->priv;
if (sdi->status == SR_ST_ACTIVE)
continue;
if (sdi->status == SR_ST_INITIALIZING) {
- if (skip != dev_index) {
+ if (skip != sdi->index) {
/* Skip devices of this type that aren't the one we want. */
skip += 1;
continue;
return SR_OK;
}
-static void close_dev(struct sr_dev_inst *sdi)
-{
- struct context *ctx;
-
- ctx = sdi->priv;
-
- if (ctx->usb->devhdl == NULL)
- return;
-
- sr_info("fx2lafw: Closing device %d on %d.%d interface %d.",
- sdi->index, ctx->usb->bus, ctx->usb->address, USB_INTERFACE);
- libusb_release_interface(ctx->usb->devhdl, USB_INTERFACE);
- libusb_close(ctx->usb->devhdl);
- ctx->usb->devhdl = NULL;
- sdi->status = SR_ST_INACTIVE;
-}
-
static int configure_probes(struct context *ctx, GSList *probes)
{
struct sr_probe *probe;
ret = SR_ERR_BUG;
continue;
}
- close_dev(sdi);
+ hw_dev_close(sdi);
sdi = l->data;
sr_dev_inst_free(sdi);
}
sdi = sr_dev_inst_new(devcnt, SR_ST_INITIALIZING,
prof->vendor, prof->model, prof->model_version);
if (!sdi)
- return 0;
+ return NULL;
sdi->driver = fdi;
/* Fill in probelist according to this device's profile. */
for (j = 0; j < num_logic_probes; j++) {
if (!(probe = sr_probe_new(j, SR_PROBE_LOGIC, TRUE,
probe_names[j])))
- return 0;
+ return NULL;
sdi->probes = g_slist_append(sdi->probes, probe);
}
return devices;
}
-static int hw_dev_open(int dev_index)
+static int hw_dev_open(struct sr_dev_inst *sdi)
{
- struct sr_dev_inst *sdi;
struct context *ctx;
int ret;
int64_t timediff_us, timediff_ms;
- if (!(sdi = sr_dev_inst_get(fdi->instances, dev_index)))
- return SR_ERR;
ctx = sdi->priv;
/*
g_usleep(300 * 1000);
timediff_ms = 0;
while (timediff_ms < MAX_RENUM_DELAY_MS) {
- if ((ret = fx2lafw_dev_open(dev_index)) == SR_OK)
+ if ((ret = fx2lafw_dev_open(sdi)) == SR_OK)
break;
g_usleep(100 * 1000);
}
sr_info("fx2lafw: Device came back after %d ms.", timediff_ms);
} else {
- ret = fx2lafw_dev_open(dev_index);
+ ret = fx2lafw_dev_open(sdi);
}
if (ret != SR_OK) {
return SR_OK;
}
-static int hw_dev_close(int dev_index)
+static int hw_dev_close(struct sr_dev_inst *sdi)
{
- struct sr_dev_inst *sdi;
+ struct context *ctx;
- if (!(sdi = sr_dev_inst_get(fdi->instances, dev_index))) {
- sr_err("fx2lafw: %s: sdi was NULL.", __func__);
- return SR_ERR_BUG;
- }
+ ctx = sdi->priv;
+ if (ctx->usb->devhdl == NULL)
+ return SR_ERR;
- /* TODO */
- close_dev(sdi);
+ sr_info("fx2lafw: Closing device %d on %d.%d interface %d.",
+ sdi->index, ctx->usb->bus, ctx->usb->address, USB_INTERFACE);
+ libusb_release_interface(ctx->usb->devhdl, USB_INTERFACE);
+ libusb_close(ctx->usb->devhdl);
+ ctx->usb->devhdl = NULL;
+ sdi->status = SR_ST_INACTIVE;
return SR_OK;
}
return devices;
}
-static int hw_dev_open(int dev_index)
+static int hw_dev_open(struct sr_dev_inst *sdi)
{
- struct sr_dev_inst *sdi;
struct context *ctx;
- if (!(sdi = sr_dev_inst_get(gdi->instances, dev_index))) {
- sr_err("genericdmm: sdi was NULL.");
- return SR_ERR_BUG;
- }
-
if (!(ctx = sdi->priv)) {
sr_err("genericdmm: sdi->priv was NULL.");
return SR_ERR_BUG;
return SR_OK;
}
-static int hw_dev_close(int dev_index)
+static int hw_dev_close(struct sr_dev_inst *sdi)
{
- struct sr_dev_inst *sdi;
struct context *ctx;
- if (!(sdi = sr_dev_inst_get(gdi->instances, dev_index))) {
- sr_err("genericdmm: %s: sdi was NULL.", __func__);
- return SR_ERR_BUG;
- }
-
if (!(ctx = sdi->priv)) {
sr_err("genericdmm: %s: sdi->priv was NULL.", __func__);
return SR_ERR_BUG;
}
- /* TODO: Check for != NULL. */
-
switch (ctx->profile->transport) {
case DMM_TRANSPORT_USBHID:
/* TODO */
return devices;
}
-static int hw_dev_open(int dev_index)
+static int hw_dev_open(struct sr_dev_inst *sdi)
{
- struct sr_dev_inst *sdi;
struct context *ctx;
int64_t timediff_us, timediff_ms;
int err;
- if (!(sdi = sr_dev_inst_get(hdi->instances, dev_index)))
- return SR_ERR_ARG;
ctx = sdi->priv;
/*
g_usleep(300 * 1000);
timediff_ms = 0;
while (timediff_ms < MAX_RENUM_DELAY_MS) {
- if ((err = dso_open(dev_index)) == SR_OK)
+ if ((err = dso_open(sdi)) == SR_OK)
break;
g_usleep(100 * 1000);
timediff_us = g_get_monotonic_time() - ctx->fw_updated;
}
sr_info("hantek-dso: device came back after %d ms", timediff_ms);
} else {
- err = dso_open(dev_index);
+ err = dso_open(sdi);
}
if (err != SR_OK) {
return SR_OK;
}
-static int hw_dev_close(int dev_index)
+static int hw_dev_close(struct sr_dev_inst *sdi)
{
- struct sr_dev_inst *sdi;
-
- if (!(sdi = sr_dev_inst_get(hdi->instances, dev_index)))
- return SR_ERR_ARG;
dso_close(sdi);
extern libusb_context *usb_context;
extern struct sr_dev_driver hantek_dso_driver_info;
-static struct sr_dev_driver *hdi = &hantek_dso_driver_info;
static int send_begin(struct context *ctx)
return mps;
}
-SR_PRIV int dso_open(int dev_index)
+SR_PRIV int dso_open(struct sr_dev_inst *sdi)
{
libusb_device **devlist;
struct libusb_device_descriptor des;
- struct sr_dev_inst *sdi;
struct context *ctx;
int err, skip, i;
- if (!(sdi = sr_dev_inst_get(hdi->instances, dev_index)))
- return SR_ERR_ARG;
ctx = sdi->priv;
if (sdi->status == SR_ST_ACTIVE)
continue;
if (sdi->status == SR_ST_INITIALIZING) {
- if (skip != dev_index) {
+ if (skip != sdi->index) {
/* Skip devices of this type that aren't the one we want. */
skip += 1;
continue;
unsigned char *framebuf;
};
-SR_PRIV int dso_open(int dev_index);
+SR_PRIV int dso_open(struct sr_dev_inst *sdi);
SR_PRIV void dso_close(struct sr_dev_inst *sdi);
SR_PRIV int dso_enable_trigger(struct context *ctx);
SR_PRIV int dso_force_trigger(struct context *ctx);
return devices;
}
-static int hw_dev_open(int dev_index)
+static int hw_dev_open(struct sr_dev_inst *sdi)
{
- struct sr_dev_inst *sdi;
struct context *ctx;
- if (!(sdi = sr_dev_inst_get(odi->instances, dev_index)))
- return SR_ERR;
-
ctx = sdi->priv;
ctx->serial->fd = serial_open(ctx->serial->port, O_RDWR);
return SR_OK;
}
-static int hw_dev_close(int dev_index)
+static int hw_dev_close(struct sr_dev_inst *sdi)
{
- struct sr_dev_inst *sdi;
struct context *ctx;
- if (!(sdi = sr_dev_inst_get(odi->instances, dev_index))) {
- sr_err("ols: %s: sdi was NULL", __func__);
- return SR_ERR_BUG;
- }
-
ctx = sdi->priv;
- /* TODO */
if (ctx->serial->fd != -1) {
serial_close(ctx->serial->fd);
ctx->serial->fd = -1;
static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
const void *value);
+static int hw_dev_close(struct sr_dev_inst *sdi);
static unsigned int get_memory_size(int type)
{
return sdi;
}
-static void close_dev(struct sr_dev_inst *sdi)
-{
- struct context *ctx;
-
- if (!(ctx = sdi->priv)) {
- sr_err("zp: %s: sdi->priv was NULL", __func__);
- return; /* FIXME */
- }
-
- if (!ctx->usb->devhdl)
- return;
-
- sr_info("zp: closing device %d on %d.%d interface %d", sdi->index,
- ctx->usb->bus, ctx->usb->address, USB_INTERFACE);
- libusb_release_interface(ctx->usb->devhdl, USB_INTERFACE);
- libusb_reset_device(ctx->usb->devhdl);
- libusb_close(ctx->usb->devhdl);
- ctx->usb->devhdl = NULL;
- /* TODO: Call libusb_exit() here or only in hw_cleanup()? */
- sdi->status = SR_ST_INACTIVE;
-}
-
static int configure_probes(const struct sr_dev_inst *sdi, const GSList *probes)
{
struct context *ctx;
for (l = zdi->instances; l; l = l->next) {
sdi = l->data;
/* Properly close all devices... */
- close_dev(sdi);
+ hw_dev_close(sdi);
/* ...and free all their memory. */
sr_dev_inst_free(sdi);
}
return devices;
}
-static int hw_dev_open(int dev_index)
+static int hw_dev_open(struct sr_dev_inst *sdi)
{
- struct sr_dev_inst *sdi;
struct context *ctx;
int ret;
- if (!(sdi = zp_open_dev(dev_index))) {
- sr_err("zp: unable to open device");
- return SR_ERR;
- }
-
- /* TODO: Note: sdi is retrieved in zp_open_dev(). */
-
if (!(ctx = sdi->priv)) {
sr_err("zp: %s: sdi->priv was NULL", __func__);
return SR_ERR_ARG;
return SR_OK;
}
-static int hw_dev_close(int dev_index)
+static int hw_dev_close(struct sr_dev_inst *sdi)
{
- struct sr_dev_inst *sdi;
+ struct context *ctx;
- if (!(sdi = sr_dev_inst_get(zdi->instances, dev_index))) {
- sr_err("zp: %s: sdi was NULL", __func__);
- return SR_ERR; /* TODO: SR_ERR_ARG? */
+ if (!(ctx = sdi->priv)) {
+ sr_err("zp: %s: sdi->priv was NULL", __func__);
+ return SR_ERR;
}
- /* TODO */
- close_dev(sdi);
+ if (!ctx->usb->devhdl)
+ return SR_ERR;
+
+ sr_info("zp: closing device %d on %d.%d interface %d", sdi->index,
+ ctx->usb->bus, ctx->usb->address, USB_INTERFACE);
+ libusb_release_interface(ctx->usb->devhdl, USB_INTERFACE);
+ libusb_reset_device(ctx->usb->devhdl);
+ libusb_close(ctx->usb->devhdl);
+ ctx->usb->devhdl = NULL;
+ sdi->status = SR_ST_INACTIVE;
return SR_OK;
}
GSList *(*scan) (GSList *options);
/* Device-specific */
- int (*dev_open) (int dev_index);
- int (*dev_close) (int dev_index);
+ int (*dev_open) (struct sr_dev_inst *sdi);
+ int (*dev_close) (struct sr_dev_inst *sdi);
/* TODO remove this */
const void *(*dev_info_get) (int dev_index, int dev_info_id);
int (*info_get) (int dev_info_id, const void **data,
return SR_OK;
}
-static int hw_dev_open(int dev_index)
+static int hw_dev_open(struct sr_dev_inst *sdi)
{
- struct sr_dev_inst *sdi;
-
- sdi = sr_dev_inst_new(dev_index, SR_ST_INITIALIZING,
- NULL, NULL, NULL);
- if (!sdi)
- return SR_ERR;
if (!(sdi->priv = g_try_malloc0(sizeof(struct session_vdev)))) {
sr_err("session driver: %s: sdi->priv malloc failed", __func__);