return ret;
}
+/* Software trigger to determine exact trigger position. */
+static int get_trigger_offset(uint16_t *samples, uint16_t last_sample,
+ struct sigma_trigger *t)
+{
+ int i;
+
+ for (i = 0; i < 8; ++i) {
+ if (i > 0)
+ last_sample = samples[i-1];
+
+ /* Simple triggers. */
+ if ((samples[i] & t->simplemask) != t->simplevalue)
+ continue;
+
+ /* Rising edge. */
+ if ((last_sample & t->risingmask) != 0 || (samples[i] &
+ t->risingmask) != t->risingmask)
+ continue;
+
+ /* Falling edge. */
+ if ((last_sample & t->fallingmask) != t->fallingmask ||
+ (samples[i] & t->fallingmask) != 0)
+ continue;
+
+ break;
+ }
+
+ /* If we did not match, return original trigger pos. */
+ return i & 0x7;
+}
+
/*
* Decode chunk of 1024 bytes, 64 clusters, 7 events per cluster.
* Each event is 20ns apart, and can contain multiple samples.
uint16_t *event;
uint16_t cur_sample;
int triggerts = -1;
- int triggeroff = 0;
/* Check if trigger is in this chunk. */
if (triggerpos != -1) {
if (cur_samplerate <= MHZ(50))
- triggerpos -= EVENTS_PER_CLUSTER;
- else
- triggeroff = 3;
+ triggerpos -= EVENTS_PER_CLUSTER - 1;
if (triggerpos < 0)
triggerpos = 0;
while (sent < n) {
tosend = MIN(2048, n - sent);
- packet.type = DF_LOGIC16;
+ packet.type = DF_LOGIC;
packet.length = tosend * sizeof(uint16_t);
+ packet.unitsize = 2;
packet.payload = samples + sent;
session_bus(user_data, &packet);
sent = 0;
if (i == triggerts) {
/*
- * Trigger is presumptively not accurate to sample.
- * However, it always trigger before the actual event,
- * so it would be possible to forward to correct position
- * here by manually checking for trigger condition.
+ * Trigger is not always accurate to sample because of
+ * pipeline delay. However, it always triggers before
+ * the actual event. We therefore look at the next
+ * samples to pinpoint the exact position of the trigger.
*/
-
- tosend = (triggerpos % 7) - triggeroff;
+ tosend = get_trigger_offset(samples, *lastsample,
+ &trigger);
if (tosend > 0) {
- packet.type = DF_LOGIC16;
+ packet.type = DF_LOGIC;
packet.length = tosend * sizeof(uint16_t);
+ packet.unitsize = 2;
packet.payload = samples;
session_bus(user_data, &packet);
/* Send rest of the chunk to sigrok. */
tosend = n - sent;
- packet.type = DF_LOGIC16;
+ packet.type = DF_LOGIC;
packet.length = tosend * sizeof(uint16_t);
+ packet.unitsize = 2;
packet.payload = samples + sent;
session_bus(user_data, &packet);
gettimeofday(&header.starttime, NULL);
header.samplerate = cur_samplerate;
header.protocol_id = PROTO_RAW;
- header.num_probes = num_probes;
+ header.num_logic_probes = num_probes;
+ header.num_analog_probes = 0;
session_bus(session_device_id, &packet);
/* Add capture source. */