]> sigrok.org Git - libsigrok.git/commitdiff
zeroplus: Rework triggerbar/trigger address logic
authorRuss Dill <redacted>
Tue, 3 Dec 2013 06:00:30 +0000 (22:00 -0800)
committerBert Vermeulen <redacted>
Thu, 5 Dec 2013 00:09:51 +0000 (01:09 +0100)
This reworks the triggerbar/trigger address logic to match the values sent
by the windows app for all models (The zerominus tool was used to reprogram
the USB device ID on a single device). Additionally, the DONT_CARE_TRIGGERBAR
register is always set by the windows app and does not seem to indicate that
these registers are "don't care"'s.

hardware/zeroplus-logic-cube/protocol.c

index 158b77cab6312c26f99ede655fd23db9ee92b0e6..0f68350e3ad1f700390abc888876ec20e0b6abfa 100644 (file)
@@ -93,27 +93,26 @@ SR_PRIV int set_capture_ratio(struct dev_context *devc, uint64_t ratio)
 
 SR_PRIV void set_triggerbar(struct dev_context *devc)
 {
-       unsigned int ramsize, n, triggerbar;
-
-       ramsize = get_memory_size(devc->memory_size) / 4;
-       if (devc->trigger) {
-               n = ramsize;
-               if (devc->max_sample_depth < n)
-                       n = devc->max_sample_depth;
-               if (devc->limit_samples < n)
-                       n = devc->limit_samples;
-               n = n * devc->capture_ratio / 100;
-               if (n > ramsize - 8)
-                       triggerbar = ramsize - 8;
-               else
-                       triggerbar = n;
-       } else {
+       unsigned int trigger_depth, triggerbar, ramsize_trigger;
+
+       trigger_depth = get_memory_size(devc->memory_size) / 4;
+       if (devc->limit_samples < trigger_depth)
+               trigger_depth = devc->limit_samples;
+       triggerbar = trigger_depth * devc->capture_ratio / 100;
+
+       ramsize_trigger = trigger_depth - triggerbar;
+       /* Matches USB packet captures from official app/driver */
+       if (triggerbar > 2)
+               triggerbar -= 2;
+       else {
+               ramsize_trigger -= 1;
                triggerbar = 0;
        }
+
        analyzer_set_triggerbar_address(triggerbar);
-       analyzer_set_ramsize_trigger_address(ramsize - triggerbar);
+       analyzer_set_ramsize_trigger_address(ramsize_trigger);
 
        sr_dbg("triggerbar_address = %d(0x%x)", triggerbar, triggerbar);
        sr_dbg("ramsize_triggerbar_address = %d(0x%x)",
-              ramsize - triggerbar, ramsize - triggerbar);
+              ramsize_trigger, ramsize_trigger);
 }