From: Bert Vermeulen Date: Mon, 15 Apr 2013 16:28:16 +0000 (+0200) Subject: ols: Properly initialize operational state before start X-Git-Tag: dsupstream~148 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=bf256783599262b94c4b3be3797f4576053d96e1;p=libsigrok.git ols: Properly initialize operational state before start --- diff --git a/hardware/openbench-logic-sniffer/api.c b/hardware/openbench-logic-sniffer/api.c index 16ed80b9..9b7beb61 100644 --- a/hardware/openbench-logic-sniffer/api.c +++ b/hardware/openbench-logic-sniffer/api.c @@ -151,16 +151,23 @@ static GSList *hw_scan(GSList *options) sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, "Sump", "Logic Analyzer", "v1.0"); sdi->driver = di; - devc = ols_dev_new(); for (i = 0; i < 32; i++) { if (!(probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE, ols_probe_names[i]))) return 0; sdi->probes = g_slist_append(sdi->probes, probe); } + devc = ols_dev_new(); sdi->priv = devc; } + /* Configure samplerate and divider. */ + if (ols_set_samplerate(sdi, DEFAULT_SAMPLERATE) != SR_OK) + sr_dbg("Failed to set default samplerate (%"PRIu64").", + DEFAULT_SAMPLERATE); + /* Clear trigger masks, values and stages. */ + ols_configure_probes(sdi); devc->serial = serial; + drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); @@ -472,6 +479,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, if (send_shortcommand(devc->serial, CMD_RUN) != SR_OK) return SR_ERR; + /* Reset all operational states. */ + devc->num_transfers = devc->num_samples = devc->num_bytes = 0; + /* Send header packet to the session bus. */ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN); @@ -481,7 +491,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, return SR_OK; } -/* TODO: This stops acquisition on ALL devices, ignoring dev_index. */ static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { /* Avoid compiler warnings. */ diff --git a/hardware/openbench-logic-sniffer/protocol.c b/hardware/openbench-logic-sniffer/protocol.c index 0a9047a3..dddc37e4 100644 --- a/hardware/openbench-logic-sniffer/protocol.c +++ b/hardware/openbench-logic-sniffer/protocol.c @@ -133,14 +133,20 @@ SR_PRIV struct dev_context *ols_dev_new(void) { struct dev_context *devc; - if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { + if (!(devc = g_try_malloc(sizeof(struct dev_context)))) { sr_err("Device context malloc failed."); return NULL; } + /* Device-specific settings */ + devc->max_samples = devc->max_samplerate = devc->protocol_version = 0; + + /* Acquisition settings */ + devc->limit_samples = devc->capture_ratio = 0; devc->trigger_at = -1; devc->probe_mask = 0xffffffff; - devc->cur_samplerate = SR_KHZ(200); + devc->flag_reg = 0; + devc->serial = NULL; return devc; diff --git a/hardware/openbench-logic-sniffer/protocol.h b/hardware/openbench-logic-sniffer/protocol.h index bded5662..5c734287 100644 --- a/hardware/openbench-logic-sniffer/protocol.h +++ b/hardware/openbench-logic-sniffer/protocol.h @@ -41,6 +41,7 @@ #define SERIAL_SPEED B115200 #define CLOCK_RATE SR_MHZ(100) #define MIN_NUM_SAMPLES 4 +#define DEFAULT_SAMPLERATE SR_KHZ(200) /* Command opcodes */ #define CMD_RESET 0x00 @@ -76,34 +77,35 @@ /* Private, per-device-instance driver context. */ struct dev_context { - uint32_t max_samplerate; + struct sr_serial_dev_inst *serial; + + /* Fixed device settings */ uint32_t max_samples; + uint32_t max_samplerate; uint32_t protocol_version; + /* Acquisition settings */ uint64_t cur_samplerate; uint32_t cur_samplerate_divider; uint64_t limit_samples; - /* Current state of the flag register */ - uint32_t flag_reg; - - /* Pre/post trigger capture ratio, in percentage. - * 0 means no pre-trigger data. */ int capture_ratio; int trigger_at; uint32_t probe_mask; uint32_t trigger_mask[4]; uint32_t trigger_value[4]; int num_stages; + uint32_t flag_reg; + /* Operational states */ unsigned int num_transfers; unsigned int num_samples; - int rle_count; int num_bytes; + + /* Temporary variables */ + int rle_count; unsigned char sample[4]; unsigned char tmp_sample[4]; unsigned char *raw_sample_buf; - - struct sr_serial_dev_inst *serial; };