From: Bert Vermeulen Date: Sat, 21 Jul 2012 20:41:58 +0000 (+0200) Subject: sr/drivers: change driver dev_acquisition_start/_stop calls to use sdi X-Git-Tag: dsupstream~784 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=3ffb6964a1585b5f6ffa0747c089a1cd557e4feb;p=libsigrok.git sr/drivers: change driver dev_acquisition_start/_stop calls to use sdi --- diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index 088095ac..b174eaff 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -123,7 +123,8 @@ static const char *firmware_files[] = { "asix-sigma-phasor.fw", /* Frequency counter */ }; -static int hw_dev_acquisition_stop(int dev_index, void *cb_data); +static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, + void *cb_data); static int sigma_read(void *buf, size_t size, struct context *ctx) { @@ -1053,7 +1054,7 @@ static int receive_data(int fd, int revents, void *cb_data) if (running_msec < ctx->limit_msec && numchunks < 32767) return TRUE; /* While capturing... */ else - hw_dev_acquisition_stop(sdi->index, sdi); + hw_dev_acquisition_stop(sdi, sdi); } else if (ctx->state.state == SIGMA_DOWNLOAD) { if (ctx->state.chunks_downloaded >= numchunks) { @@ -1269,9 +1270,9 @@ static int build_basic_trigger(struct triggerlut *lut, struct context *ctx) return SR_OK; } -static int hw_dev_acquisition_start(int dev_index, void *cb_data) +static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, + void *cb_data) { - struct sr_dev_inst *sdi; struct context *ctx; struct sr_datafeed_packet *packet; struct sr_datafeed_header *header; @@ -1282,9 +1283,6 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data) struct triggerinout triggerinout_conf; struct triggerlut lut; - if (!(sdi = sr_dev_inst_get(adi->instances, dev_index))) - return SR_ERR; - ctx = sdi->priv; /* If the samplerate has not been set, default to 200 kHz. */ @@ -1392,7 +1390,7 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data) sr_session_send(ctx->session_dev_id, packet); /* Add capture source. */ - sr_source_add(0, G_IO_IN, 10, receive_data, sdi); + sr_source_add(0, G_IO_IN, 10, receive_data, (void *)sdi); g_free(header); g_free(packet); @@ -1402,20 +1400,15 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data) return SR_OK; } -static int hw_dev_acquisition_stop(int dev_index, void *cb_data) +static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, + void *cb_data) { - struct sr_dev_inst *sdi; struct context *ctx; uint8_t modestatus; /* Avoid compiler warnings. */ (void)cb_data; - 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 337c07ff..419fd118 100644 --- a/hardware/chronovu-la8/api.c +++ b/hardware/chronovu-la8/api.c @@ -38,7 +38,8 @@ static const uint16_t usb_pids[] = { }; /* Function prototypes. */ -static int hw_dev_acquisition_stop(int dev_index, void *cb_data); +static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, + void *cb_data); static void clear_instances(void) { @@ -396,7 +397,7 @@ static int receive_data(int fd, int revents, void *cb_data) /* Get one block of data. */ if ((ret = la8_read_block(ctx)) < 0) { sr_err("la8: %s: la8_read_block error: %d", __func__, ret); - hw_dev_acquisition_stop(sdi->index, sdi); + hw_dev_acquisition_stop(sdi, sdi); return FALSE; } @@ -412,15 +413,15 @@ static int receive_data(int fd, int revents, void *cb_data) for (i = 0; i < NUM_BLOCKS; i++) send_block_to_session_bus(ctx, i); - hw_dev_acquisition_stop(sdi->index, sdi); + hw_dev_acquisition_stop(sdi, sdi); // return FALSE; /* FIXME? */ return TRUE; } -static int hw_dev_acquisition_start(int dev_index, void *cb_data) +static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, + void *cb_data) { - struct sr_dev_inst *sdi; struct context *ctx; struct sr_datafeed_packet packet; struct sr_datafeed_header header; @@ -428,11 +429,6 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data) uint8_t buf[4]; int bytes_written; - 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; @@ -494,24 +490,19 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data) ctx->trigger_found = 0; /* Hook up a dummy handler to receive data from the LA8. */ - sr_source_add(-1, G_IO_IN, 0, receive_data, sdi); + sr_source_add(-1, G_IO_IN, 0, receive_data, (void *)sdi); return SR_OK; } -static int hw_dev_acquisition_stop(int dev_index, void *cb_data) +static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, + void *cb_data) { - struct sr_dev_inst *sdi; struct context *ctx; struct sr_datafeed_packet packet; sr_dbg("la8: Stopping acquisition."); - 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 cb2c15d9..2fbac3ea 100644 --- a/hardware/demo/demo.c +++ b/hardware/demo/demo.c @@ -71,7 +71,6 @@ struct context { uint8_t sample_generator; uint8_t thread_running; uint64_t samples_counter; - int dev_index; void *session_dev_id; GTimer *timer; }; @@ -139,7 +138,8 @@ static int default_pattern = PATTERN_SIGROK; static GThread *my_thread; static int thread_running; -static int hw_dev_acquisition_stop(int dev_index, void *cb_data); +static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, + void *cb_data); static int hw_init(void) { @@ -419,13 +419,16 @@ static int receive_data(int fd, int revents, void *cb_data) return TRUE; } -static int hw_dev_acquisition_start(int dev_index, void *cb_data) +static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, + void *cb_data) { struct sr_datafeed_packet *packet; struct sr_datafeed_header *header; struct sr_datafeed_meta_logic meta; struct context *ctx; + (void)sdi; + /* TODO: 'ctx' is never g_free()'d? */ if (!(ctx = g_try_malloc(sizeof(struct context)))) { sr_err("demo: %s: ctx malloc failed", __func__); @@ -434,7 +437,6 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data) ctx->sample_generator = default_pattern; ctx->session_dev_id = cb_data; - ctx->dev_index = dev_index; ctx->samples_counter = 0; if (pipe(ctx->pipe_fds)) { @@ -500,11 +502,11 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data) return SR_OK; } -/* TODO: This stops acquisition on ALL devices, ignoring dev_index. */ -static int hw_dev_acquisition_stop(int dev_index, void *cb_data) +static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, + void *cb_data) { /* Avoid compiler warnings. */ - (void)dev_index; + (void)sdi; (void)cb_data; /* Stop generate thread. */ diff --git a/hardware/fx2lafw/fx2lafw.c b/hardware/fx2lafw/fx2lafw.c index 8ae0cdf5..87edea6f 100644 --- a/hardware/fx2lafw/fx2lafw.c +++ b/hardware/fx2lafw/fx2lafw.c @@ -146,7 +146,8 @@ 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); +static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, + void *cb_data); /** * Check the USB configuration to determine if this is an fx2lafw device. @@ -928,9 +929,9 @@ static unsigned int get_timeout(struct context *ctx) return timeout + timeout / 4; /* Leave a headroom of 25% percent */ } -static int hw_dev_acquisition_start(int dev_index, void *cb_data) +static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, + void *cb_data) { - struct sr_dev_inst *sdi; struct sr_datafeed_packet packet; struct sr_datafeed_header header; struct sr_datafeed_meta_logic meta; @@ -941,10 +942,7 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data) int ret; unsigned char *buf; - if (!(sdi = sr_dev_inst_get(fdi->instances, dev_index))) - return SR_ERR; ctx = sdi->priv; - if (ctx->submitted_transfers != 0) return SR_ERR; @@ -1010,16 +1008,13 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data) } /* TODO: This stops acquisition on ALL devices, ignoring dev_index. */ -static int hw_dev_acquisition_stop(int dev_index, void *cb_data) +static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, + void *cb_data) { - struct sr_dev_inst *sdi; /* Avoid compiler warnings. */ (void)cb_data; - if (!(sdi = sr_dev_inst_get(fdi->instances, dev_index))) - return SR_ERR; - abort_acquisition(sdi->priv); return SR_OK; diff --git a/hardware/genericdmm/api.c b/hardware/genericdmm/api.c index c182b039..e4de064d 100644 --- a/hardware/genericdmm/api.c +++ b/hardware/genericdmm/api.c @@ -536,19 +536,14 @@ static int receive_data(int fd, int revents, void *cb_data) return TRUE; } -static int hw_dev_acquisition_start(int dev_index, void *cb_data) +static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, + void *cb_data) { struct sr_datafeed_packet packet; struct sr_datafeed_header header; struct sr_datafeed_meta_analog meta; - 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; @@ -587,12 +582,13 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data) return SR_OK; } -static int hw_dev_acquisition_stop(int dev_index, void *cb_data) +static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, + void *cb_data) { struct sr_datafeed_packet packet; /* Avoid compiler warnings. */ - (void)dev_index; + (void)sdi; sr_dbg("genericdmm: Stopping acquisition."); diff --git a/hardware/hantek-dso/api.c b/hardware/hantek-dso/api.c index 0c375140..60c91314 100644 --- a/hardware/hantek-dso/api.c +++ b/hardware/hantek-dso/api.c @@ -787,19 +787,16 @@ static int handle_event(int fd, int revents, void *cb_data) return TRUE; } -static int hw_dev_acquisition_start(int dev_index, void *cb_data) +static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, + void *cb_data) { const struct libusb_pollfd **lupfd; struct sr_datafeed_packet packet; struct sr_datafeed_header header; struct sr_datafeed_meta_analog meta; - struct sr_dev_inst *sdi; struct context *ctx; int i; - if (!(sdi = sr_dev_inst_get(hdi->instances, dev_index))) - return SR_ERR; - if (sdi->status != SR_ST_ACTIVE) return SR_ERR; @@ -838,15 +835,12 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data) /* TODO: doesn't really cancel pending transfers so they might come in after * SR_DF_END is sent. */ -static int hw_dev_acquisition_stop(int dev_index, void *cb_data) +static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, + void *cb_data) { struct sr_datafeed_packet packet; - struct sr_dev_inst *sdi; struct context *ctx; - if (!(sdi = sr_dev_inst_get(hdi->instances, dev_index))) - return SR_ERR; - if (sdi->status != SR_ST_ACTIVE) return SR_ERR; diff --git a/hardware/zeroplus-logic-cube/zeroplus.c b/hardware/zeroplus-logic-cube/zeroplus.c index f4b566e8..f889362c 100644 --- a/hardware/zeroplus-logic-cube/zeroplus.c +++ b/hardware/zeroplus-logic-cube/zeroplus.c @@ -609,9 +609,9 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap, } } -static int hw_dev_acquisition_start(int dev_index, void *cb_data) +static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, + void *cb_data) { - struct sr_dev_inst *sdi; struct sr_datafeed_packet packet; struct sr_datafeed_logic logic; struct sr_datafeed_header header; @@ -622,11 +622,6 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data) unsigned char *buf; struct context *ctx; - if (!(sdi = sr_dev_inst_get(zdi->instances, dev_index))) { - sr_err("zp: %s: sdi was NULL", __func__); - return SR_ERR; - } - if (!(ctx = sdi->priv)) { sr_err("zp: %s: sdi->priv was NULL", __func__); return SR_ERR_ARG; @@ -691,20 +686,15 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data) } /* TODO: This stops acquisition on ALL devices, ignoring dev_index. */ -static int hw_dev_acquisition_stop(int dev_index, void *cb_data) +static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, + void *cb_data) { struct sr_datafeed_packet packet; - struct sr_dev_inst *sdi; struct context *ctx; packet.type = SR_DF_END; sr_session_send(cb_data, &packet); - if (!(sdi = sr_dev_inst_get(zdi->instances, dev_index))) { - sr_err("zp: %s: sdi was NULL", __func__); - return SR_ERR_BUG; - } - if (!(ctx = sdi->priv)) { sr_err("zp: %s: sdi->priv was NULL", __func__); return SR_ERR_BUG; diff --git a/libsigrok.h b/libsigrok.h index 2b17eef1..33d28697 100644 --- a/libsigrok.h +++ b/libsigrok.h @@ -499,8 +499,10 @@ struct sr_dev_driver { int (*dev_status_get) (int dev_index); int (*dev_config_set) (const struct sr_dev_inst *sdi, int hwcap, const void *value); - int (*dev_acquisition_start) (int dev_index, void *session_dev_id); - int (*dev_acquisition_stop) (int dev_index, void *session_dev_id); + int (*dev_acquisition_start) (const struct sr_dev_inst *sdi, + void *cb_data); + int (*dev_acquisition_stop) (const struct sr_dev_inst *sdi, + void *cb_data); /* Dynamic */ GSList *instances;