]> sigrok.org Git - libsigrok.git/commitdiff
ols: Properly initialize operational state before start
authorBert Vermeulen <redacted>
Mon, 15 Apr 2013 16:28:16 +0000 (18:28 +0200)
committerBert Vermeulen <redacted>
Mon, 15 Apr 2013 16:28:43 +0000 (18:28 +0200)
hardware/openbench-logic-sniffer/api.c
hardware/openbench-logic-sniffer/protocol.c
hardware/openbench-logic-sniffer/protocol.h

index 16ed80b9e7c2df0e00051637d71824a66a7f489e..9b7beb6194664318e624223c281318b1f446980a 100644 (file)
@@ -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. */
index 0a9047a3fa6140b75392f73273aab21568dc29ab..dddc37e43dcb1c043aecd44146f986973779459a 100644 (file)
@@ -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;
index bded566230ad41a1471e7e6dad4f96058fda6ad7..5c734287086202a6a5e74fe6feec7e3c7958628c 100644 (file)
@@ -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
 
 /* 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;
 };