]> sigrok.org Git - libsigrok.git/blobdiff - hardware/openbench-logic-sniffer/api.c
probe_groups: API changes required to implement probe groups.
[libsigrok.git] / hardware / openbench-logic-sniffer / api.c
index 1a449a6b6ad63a7e52dd2e0289076c2599e9479c..8a83abc711447843bf432964edf26ca3cd391fae 100644 (file)
@@ -32,9 +32,27 @@ static const int32_t hwcaps[] = {
        SR_CONF_TRIGGER_TYPE,
        SR_CONF_CAPTURE_RATIO,
        SR_CONF_LIMIT_SAMPLES,
+       SR_CONF_EXTERNAL_CLOCK,
+       SR_CONF_PATTERN_MODE,
+       SR_CONF_SWAP,
        SR_CONF_RLE,
 };
 
+#define STR_PATTERN_EXTERNAL "external"
+#define STR_PATTERN_INTERNAL "internal"
+
+/* Supported methods of test pattern outputs */
+enum {
+       /**
+        * Capture pins 31:16 (unbuffered wing) output a test pattern
+        * that can captured on pins 0:15.
+        */
+       PATTERN_EXTERNAL,
+
+       /** Route test pattern internally to capture buffer. */
+       PATTERN_INTERNAL,
+};
+
 /* Probes are numbered 0-31 (on the PCB silkscreen). */
 SR_PRIV const char *ols_probe_names[NUM_PROBES + 1] = {
        "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12",
@@ -53,12 +71,17 @@ static const uint64_t samplerates[] = {
 SR_PRIV struct sr_dev_driver ols_driver_info;
 static struct sr_dev_driver *di = &ols_driver_info;
 
-static int hw_init(struct sr_context *sr_ctx)
+static int dev_clear(void)
 {
-       return std_hw_init(sr_ctx, di, DRIVER_LOG_DOMAIN);
+       return std_dev_clear(di, NULL);
 }
 
-static GSList *hw_scan(GSList *options)
+static int init(struct sr_context *sr_ctx)
+{
+       return std_init(sr_ctx, di, LOG_PREFIX);
+}
+
+static GSList *scan(GSList *options)
 {
        struct sr_config *src;
        struct sr_dev_inst *sdi;
@@ -72,8 +95,6 @@ static GSList *hw_scan(GSList *options)
        const char *conn, *serialcomm;
        char buf[8];
 
-       (void)options;
-
        drvc = di->priv;
 
        devices = NULL;
@@ -178,12 +199,12 @@ static GSList *hw_scan(GSList *options)
        return devices;
 }
 
-static GSList *hw_dev_list(void)
+static GSList *dev_list(void)
 {
        return ((struct drv_context *)(di->priv))->instances;
 }
 
-static int hw_dev_open(struct sr_dev_inst *sdi)
+static int dev_open(struct sr_dev_inst *sdi)
 {
        struct sr_serial_dev_inst *serial;
 
@@ -196,7 +217,7 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-static int hw_dev_close(struct sr_dev_inst *sdi)
+static int dev_close(struct sr_dev_inst *sdi)
 {
        struct sr_serial_dev_inst *serial;
 
@@ -209,47 +230,18 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-static int hw_cleanup(void)
+static int cleanup(void)
 {
-       GSList *l;
-       struct sr_dev_inst *sdi;
-       struct drv_context *drvc;
-       struct dev_context *devc;
-       struct sr_serial_dev_inst *serial;
-       int ret = SR_OK;
-
-       if (!(drvc = di->priv))
-               return SR_OK;
-
-       /* Properly close and free all devices. */
-       for (l = drvc->instances; l; l = l->next) {
-               if (!(sdi = l->data)) {
-                       /* Log error, but continue cleaning up the rest. */
-                       sr_err("%s: sdi was NULL, continuing", __func__);
-                       ret = SR_ERR_BUG;
-                       continue;
-               }
-               if (!(devc = sdi->priv)) {
-                       /* Log error, but continue cleaning up the rest. */
-                       sr_err("%s: sdi->priv was NULL, continuing", __func__);
-                       ret = SR_ERR_BUG;
-                       continue;
-               }
-               hw_dev_close(sdi);
-               serial = sdi->conn;
-               sr_serial_dev_inst_free(serial);
-               sr_dev_inst_free(sdi);
-       }
-       g_slist_free(drvc->instances);
-       drvc->instances = NULL;
-
-       return ret;
+       return dev_clear();
 }
 
-static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi)
+static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
+               const struct sr_probe_group *probe_group)
 {
        struct dev_context *devc;
 
+       (void)probe_group;
+
        if (!sdi)
                return SR_ERR_ARG;
 
@@ -264,6 +256,12 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi)
        case SR_CONF_LIMIT_SAMPLES:
                *data = g_variant_new_uint64(devc->limit_samples);
                break;
+       case SR_CONF_PATTERN_MODE:
+               if (devc->flag_reg & FLAG_EXTERNAL_TEST_MODE)
+                       *data = g_variant_new_string(STR_PATTERN_EXTERNAL);
+               else if (devc->flag_reg & FLAG_INTERNAL_TEST_MODE)
+                       *data = g_variant_new_string(STR_PATTERN_INTERNAL);
+               break;
        case SR_CONF_RLE:
                *data = g_variant_new_boolean(devc->flag_reg & FLAG_RLE ? TRUE : FALSE);
                break;
@@ -274,11 +272,15 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
+static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
+               const struct sr_probe_group *probe_group)
 {
        struct dev_context *devc;
        int ret;
        uint64_t tmp_u64;
+       const char *stropt;
+
+       (void)probe_group;
 
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
@@ -307,6 +309,40 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
                } else
                        ret = SR_OK;
                break;
+       case SR_CONF_EXTERNAL_CLOCK:
+               if (g_variant_get_boolean(data)) {
+                       sr_info("Enabling external clock.");
+                       devc->flag_reg |= FLAG_CLOCK_EXTERNAL;
+               } else {
+                       sr_info("Disabled external clock.");
+                       devc->flag_reg &= ~FLAG_CLOCK_EXTERNAL;
+               }
+               ret = SR_OK;
+               break;
+       case SR_CONF_PATTERN_MODE:
+               stropt = g_variant_get_string(data, NULL);
+               ret = SR_OK;
+               if (!strcmp(stropt, STR_PATTERN_INTERNAL)) {
+                       sr_info("Enabling internal test mode.");
+                       devc->flag_reg |= FLAG_INTERNAL_TEST_MODE;
+               } else if (!strcmp(stropt, STR_PATTERN_EXTERNAL)) {
+                       sr_info("Enabling external test mode.");
+                       devc->flag_reg |= FLAG_EXTERNAL_TEST_MODE;
+               } else {
+                       ret = SR_ERR;
+               }
+               break;
+       case SR_CONF_SWAP:
+               if (g_variant_get_boolean(data)) {
+                       sr_info("Enabling channel swapping.");
+                       devc->flag_reg |= FLAG_SWAP_PROBES;
+               } else {
+                       sr_info("Disabling channel swapping.");
+                       devc->flag_reg &= ~FLAG_SWAP_PROBES;
+               }
+               ret = SR_OK;
+               break;
+
        case SR_CONF_RLE:
                if (g_variant_get_boolean(data)) {
                        sr_info("Enabling RLE.");
@@ -324,12 +360,14 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
        return ret;
 }
 
-static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
+static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
+               const struct sr_probe_group *probe_group)
 {
        GVariant *gvar;
        GVariantBuilder gvb;
 
        (void)sdi;
+       (void)probe_group;
 
        switch (key) {
        case SR_CONF_SCAN_OPTIONS:
@@ -357,7 +395,7 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
+static int dev_acquisition_start(const struct sr_dev_inst *sdi,
                void *cb_data)
 {
        struct dev_context *devc;
@@ -459,8 +497,10 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        }
 
        sr_info("Setting samplerate to %" PRIu64 "Hz (divider %u, "
-               "demux %s)", devc->cur_samplerate, devc->cur_samplerate_divider,
-               devc->flag_reg & FLAG_DEMUX ? "on" : "off");
+               "demux %s, noise_filter %s)", devc->cur_samplerate,
+               devc->cur_samplerate_divider,
+               devc->flag_reg & FLAG_DEMUX ? "on" : "off",
+               devc->flag_reg & FLAG_FILTER ? "on": "off");
        if (send_longcommand(serial, CMD_SET_DIVIDER,
                        reverse32(devc->cur_samplerate_divider)) != SR_OK)
                return SR_ERR;
@@ -473,7 +513,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
 
        /* The flag register wants them here, and 1 means "disable channel". */
        devc->flag_reg |= ~(changrp_mask << 2) & 0x3c;
-       devc->flag_reg |= FLAG_FILTER;
        devc->rle_count = 0;
        data = (devc->flag_reg << 24) | ((devc->flag_reg << 8) & 0xff0000);
        if (send_longcommand(serial, CMD_SET_FLAGS, data) != SR_OK)
@@ -485,18 +524,18 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
 
        /* Reset all operational states. */
        devc->num_transfers = devc->num_samples = devc->num_bytes = 0;
+       memset(devc->sample, 0, 4);
 
        /* Send header packet to the session bus. */
-       std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
+       std_session_send_df_header(cb_data, LOG_PREFIX);
 
        sr_source_add(serial->fd, G_IO_IN, -1, ols_receive_data, cb_data);
 
        return SR_OK;
 }
 
-static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
+static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
-       /* Avoid compiler warnings. */
        (void)cb_data;
 
        abort_acquisition(sdi);
@@ -508,17 +547,17 @@ SR_PRIV struct sr_dev_driver ols_driver_info = {
        .name = "ols",
        .longname = "Openbench Logic Sniffer",
        .api_version = 1,
-       .init = hw_init,
-       .cleanup = hw_cleanup,
-       .scan = hw_scan,
-       .dev_list = hw_dev_list,
-       .dev_clear = hw_cleanup,
+       .init = init,
+       .cleanup = cleanup,
+       .scan = scan,
+       .dev_list = dev_list,
+       .dev_clear = dev_clear,
        .config_get = config_get,
        .config_set = config_set,
        .config_list = config_list,
-       .dev_open = hw_dev_open,
-       .dev_close = hw_dev_close,
-       .dev_acquisition_start = hw_dev_acquisition_start,
-       .dev_acquisition_stop = hw_dev_acquisition_stop,
+       .dev_open = dev_open,
+       .dev_close = dev_close,
+       .dev_acquisition_start = dev_acquisition_start,
+       .dev_acquisition_stop = dev_acquisition_stop,
        .priv = NULL,
 };