+ /* Check if the trigger is in the samples we are throwing away */
+ trigger_now = now_address == trigger_address ||
+ ((now_address + 1) % memory_size) == trigger_address;
+
+ /*
+ * STATUS_READY doesn't clear until now_address advances past
+ * addr 0, but for our logic, clear it in that case
+ */
+ if (!now_address)
+ status &= ~STATUS_READY;
+
+ analyzer_read_start(usb->devhdl);
+
+ /* Calculate how much data to discard */
+ discard = 0;
+ if (status & STATUS_READY) {
+ /*
+ * We haven't wrapped around, we need to throw away data from
+ * our current position to the end of the buffer.
+ * Additionally, the first two samples captured are always
+ * bogus.
+ */
+ discard += memory_size - now_address + 2;
+ now_address = 2;
+ }
+
+ /* If we have more samples than we need, discard them */
+ valid_samples = (stop_address - now_address) % memory_size;
+ if (valid_samples > ramsize_trigger + triggerbar) {
+ discard += valid_samples - (ramsize_trigger + triggerbar);
+ now_address += valid_samples - (ramsize_trigger + triggerbar);
+ }
+
+ sr_info("Need to discard %d samples.", discard);
+
+ /* Calculate how far in the trigger is */
+ if (trigger_now)
+ trigger_offset = 0;
+ else
+ trigger_offset = (trigger_address - now_address) % memory_size;
+
+ /* Recalculate the number of samples available */
+ valid_samples = (stop_address - now_address) % memory_size;
+