X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fopenbench-logic-sniffer%2Fapi.c;h=a70e3168bd8a3cea86b408924ff3b7dc5c2bacdc;hb=448e81b1e565525c9e8881f17f36dbca93832346;hp=4abc929a24b0824673303971afe92cc45b3b2e4f;hpb=41812aca436805b0614f2a8f31cf2f8ce494aea0;p=libsigrok.git diff --git a/src/hardware/openbench-logic-sniffer/api.c b/src/hardware/openbench-logic-sniffer/api.c index 4abc929a..a70e3168 100644 --- a/src/hardware/openbench-logic-sniffer/api.c +++ b/src/hardware/openbench-logic-sniffer/api.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include +#include #include "protocol.h" #define SERIALCOMM "115200/8n1" @@ -87,17 +87,11 @@ static const uint64_t samplerates[] = { SR_PRIV struct sr_dev_driver ols_driver_info; -static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) -{ - return std_init(sr_ctx, di, LOG_PREFIX); -} - static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct sr_config *src; struct sr_dev_inst *sdi; struct drv_context *drvc; - struct dev_context *devc; struct sr_serial_dev_inst *serial; GSList *l, *devices; int ret; @@ -182,7 +176,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) if (sp_input_waiting(serial->data) != 0) { /* Got metadata. */ sdi = get_metadata(serial); - devc = sdi->priv; } else { /* Not an OLS -- some other board that uses the sump protocol. */ sr_info("Device does not support metadata."); @@ -195,8 +188,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) for (i = 0; i < ARRAY_SIZE(ols_channel_names); i++) sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, ols_channel_names[i]); - devc = ols_dev_new(); - sdi->priv = devc; + sdi->priv = ols_dev_new(); } /* Configure samplerate and divider. */ if (ols_set_samplerate(sdi, DEFAULT_SAMPLERATE) != SR_OK) @@ -213,16 +205,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) return devices; } -static GSList *dev_list(const struct sr_dev_driver *di) -{ - return ((struct drv_context *)(di->context))->instances; -} - -static int cleanup(const struct sr_dev_driver *di) -{ - return std_dev_clear(di, NULL); -} - static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -294,10 +276,9 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd break; case SR_CONF_CAPTURE_RATIO: devc->capture_ratio = g_variant_get_uint64(data); - if (devc->capture_ratio < 0 || devc->capture_ratio > 100) { - devc->capture_ratio = 0; + if (devc->capture_ratio < 0 || devc->capture_ratio > 100) ret = SR_ERR; - } else + else ret = SR_OK; break; case SR_CONF_EXTERNAL_CLOCK: @@ -467,8 +448,7 @@ static int set_trigger(const struct sr_dev_inst *sdi, int stage) return SR_OK; } -static int dev_acquisition_start(const struct sr_dev_inst *sdi, - void *cb_data) +static int dev_acquisition_start(const struct sr_dev_inst *sdi) { struct dev_context *devc; struct sr_serial_dev_inst *serial; @@ -574,19 +554,19 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, devc->cnt_bytes = devc->cnt_samples = devc->cnt_samples_rle = 0; memset(devc->sample, 0, 4); - /* Send header packet to the session bus. */ - std_session_send_df_header(cb_data, LOG_PREFIX); + std_session_send_df_header(sdi, LOG_PREFIX); - serial_source_add(sdi->session, serial, G_IO_IN, -1, - ols_receive_data, cb_data); + /* If the device stops sending for longer than it takes to send a byte, + * that means it's finished. But wait at least 100 ms to be safe. + */ + serial_source_add(sdi->session, serial, G_IO_IN, 100, + ols_receive_data, (struct sr_dev_inst *)sdi); return SR_OK; } -static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) +static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - (void)cb_data; - abort_acquisition(sdi); return SR_OK; @@ -596,10 +576,10 @@ SR_PRIV struct sr_dev_driver ols_driver_info = { .name = "ols", .longname = "Openbench Logic Sniffer", .api_version = 1, - .init = init, - .cleanup = cleanup, + .init = std_init, + .cleanup = std_cleanup, .scan = scan, - .dev_list = dev_list, + .dev_list = std_dev_list, .dev_clear = NULL, .config_get = config_get, .config_set = config_set,