]> sigrok.org Git - libsigrok.git/blobdiff - hardware/openbench-logic-sniffer/api.c
ols: add external clock support
[libsigrok.git] / hardware / openbench-logic-sniffer / api.c
index 04a06b2e1c0878f213796b72ccaa4f01e5deda46..87e430806af78d60c96f461a2384978c0ee479a2 100644 (file)
@@ -32,9 +32,26 @@ 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_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,6 +70,11 @@ 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 dev_clear(void)
+{
+       return std_dev_clear(di, NULL);
+}
+
 static int init(struct sr_context *sr_ctx)
 {
        return std_init(sr_ctx, di, LOG_PREFIX);
@@ -207,9 +229,9 @@ static int dev_close(struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-static int dev_clear(void)
+static int cleanup(void)
 {
-       return std_dev_clear(di, NULL);
+       return dev_clear();
 }
 
 static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi)
@@ -230,6 +252,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;
@@ -245,6 +273,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
        struct dev_context *devc;
        int ret;
        uint64_t tmp_u64;
+       const char *stropt;
 
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
@@ -273,6 +302,29 @@ 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_RLE:
                if (g_variant_get_boolean(data)) {
                        sr_info("Enabling RLE.");
@@ -474,7 +526,7 @@ SR_PRIV struct sr_dev_driver ols_driver_info = {
        .longname = "Openbench Logic Sniffer",
        .api_version = 1,
        .init = init,
-       .cleanup = dev_clear,
+       .cleanup = cleanup,
        .scan = scan,
        .dev_list = dev_list,
        .dev_clear = dev_clear,