From: Bert Vermeulen Date: Sat, 21 Jul 2012 20:04:47 +0000 (+0200) Subject: sr/drivers: change driver dev_open/dev_close calls to use sdi X-Git-Tag: dsupstream~785 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=25a0f108f4512ade836fed128c3ad649dedcb788;p=libsigrok.git sr/drivers: change driver dev_open/dev_close calls to use sdi --- diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index 4f802cac..088095ac 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -607,15 +607,11 @@ static int upload_firmware(int firmware_idx, struct context *ctx) 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. */ @@ -748,16 +744,10 @@ static int configure_probes(const struct sr_dev_inst *sdi, const GSList *probes) 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; diff --git a/hardware/chronovu-la8/api.c b/hardware/chronovu-la8/api.c index 4b8d9d39..337c07ff 100644 --- a/hardware/chronovu-la8/api.c +++ b/hardware/chronovu-la8/api.c @@ -168,16 +168,10 @@ err_free_nothing: 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__); @@ -227,16 +221,10 @@ err_dev_open_close_ftdic: 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; diff --git a/hardware/demo/demo.c b/hardware/demo/demo.c index 24c91838..cb2c15d9 100644 --- a/hardware/demo/demo.c +++ b/hardware/demo/demo.c @@ -170,20 +170,20 @@ static GSList *hw_scan(GSList *options) 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. */ diff --git a/hardware/fx2lafw/fx2lafw.c b/hardware/fx2lafw/fx2lafw.c index 2cf9c0f5..8ae0cdf5 100644 --- a/hardware/fx2lafw/fx2lafw.c +++ b/hardware/fx2lafw/fx2lafw.c @@ -143,6 +143,7 @@ static libusb_context *usb_context = NULL; 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); @@ -191,18 +192,15 @@ static gboolean check_conf_profile(libusb_device *dev) 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) @@ -229,7 +227,7 @@ static int fx2lafw_dev_open(int dev_index) 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; @@ -298,23 +296,6 @@ static int fx2lafw_dev_open(int dev_index) 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; @@ -400,7 +381,7 @@ static int clear_instances(void) ret = SR_ERR_BUG; continue; } - close_dev(sdi); + hw_dev_close(sdi); sdi = l->data; sr_dev_inst_free(sdi); } @@ -471,7 +452,7 @@ static GSList *hw_scan(GSList *options) 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. */ @@ -479,7 +460,7 @@ static GSList *hw_scan(GSList *options) 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); } @@ -513,15 +494,12 @@ static GSList *hw_scan(GSList *options) 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; /* @@ -535,7 +513,7 @@ static int hw_dev_open(int dev_index) 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); @@ -545,7 +523,7 @@ static int hw_dev_open(int dev_index) } 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) { @@ -584,17 +562,20 @@ static int hw_dev_open(int dev_index) 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; } diff --git a/hardware/genericdmm/api.c b/hardware/genericdmm/api.c index f29aafd1..c182b039 100644 --- a/hardware/genericdmm/api.c +++ b/hardware/genericdmm/api.c @@ -325,16 +325,10 @@ static GSList *hw_scan(GSList *options) 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; @@ -363,23 +357,15 @@ static int hw_dev_open(int dev_index) 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 */ diff --git a/hardware/hantek-dso/api.c b/hardware/hantek-dso/api.c index d1b2f9b6..0c375140 100644 --- a/hardware/hantek-dso/api.c +++ b/hardware/hantek-dso/api.c @@ -315,15 +315,12 @@ static GSList *hw_scan(GSList *options) 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; /* @@ -337,7 +334,7 @@ static int hw_dev_open(int dev_index) 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; @@ -346,7 +343,7 @@ static int hw_dev_open(int dev_index) } 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) { @@ -363,12 +360,8 @@ static int hw_dev_open(int dev_index) 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); diff --git a/hardware/hantek-dso/dso.c b/hardware/hantek-dso/dso.c index 4eedf798..98a326c0 100644 --- a/hardware/hantek-dso/dso.c +++ b/hardware/hantek-dso/dso.c @@ -29,7 +29,6 @@ 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) @@ -105,16 +104,13 @@ err: 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) @@ -134,7 +130,7 @@ SR_PRIV int dso_open(int dev_index) 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; diff --git a/hardware/hantek-dso/dso.h b/hardware/hantek-dso/dso.h index c7ae841f..38ef61bf 100644 --- a/hardware/hantek-dso/dso.h +++ b/hardware/hantek-dso/dso.h @@ -203,7 +203,7 @@ struct context { 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); diff --git a/hardware/openbench-logic-sniffer/ols.c b/hardware/openbench-logic-sniffer/ols.c index b1bcfa55..735f5fda 100644 --- a/hardware/openbench-logic-sniffer/ols.c +++ b/hardware/openbench-logic-sniffer/ols.c @@ -509,14 +509,10 @@ hw_init_free_ports: 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); @@ -528,19 +524,12 @@ static int hw_dev_open(int dev_index) 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; diff --git a/hardware/zeroplus-logic-cube/zeroplus.c b/hardware/zeroplus-logic-cube/zeroplus.c index a029a3cb..f4b566e8 100644 --- a/hardware/zeroplus-logic-cube/zeroplus.c +++ b/hardware/zeroplus-logic-cube/zeroplus.c @@ -161,6 +161,7 @@ struct context { 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) { @@ -263,28 +264,6 @@ static struct sr_dev_inst *zp_open_dev(int dev_index) 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; @@ -334,7 +313,7 @@ static void clear_instances(void) 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); } @@ -430,19 +409,11 @@ static GSList *hw_scan(GSList *options) 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; @@ -491,17 +462,25 @@ static int hw_dev_open(int dev_index) 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; } diff --git a/libsigrok.h b/libsigrok.h index 911319a9..2b17eef1 100644 --- a/libsigrok.h +++ b/libsigrok.h @@ -490,8 +490,8 @@ struct sr_dev_driver { 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, diff --git a/session_driver.c b/session_driver.c index ce5c665c..34f8c34e 100644 --- a/session_driver.c +++ b/session_driver.c @@ -171,14 +171,8 @@ static int hw_cleanup(void) 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__);