diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index e33b5b79..185861c4 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -98,7 +98,7 @@ static const char *firmware_files[] = { "asix-sigma-phasor.fw", /* Frequency counter */ }; -static void hw_stop_acquisition(int device_index, gpointer session_device_id); +static void hw_stop_acquisition(int device_index, gpointer session_data); static int sigma_read(void *buf, size_t size, struct sigma *sigma) { @@ -415,6 +415,7 @@ static int hw_init(const char *deviceinfo) goto free; sigma->cur_samplerate = 0; + sigma->period_ps = 0; sigma->limit_msec = 0; sigma->cur_firmware = -1; sigma->num_probes = 0; @@ -585,6 +586,7 @@ static int set_samplerate(struct sr_device_instance *sdi, } sigma->cur_samplerate = samplerate; + sigma->period_ps = 1000000000000 / samplerate; sigma->samples_per_event = 16 / sigma->num_probes; sigma->state.state = SIGMA_IDLE; @@ -841,13 +843,14 @@ static int get_trigger_offset(uint16_t *samples, uint16_t last_sample, */ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, uint16_t *lastsample, int triggerpos, - uint16_t limit_chunk, void *user_data) + uint16_t limit_chunk, void *session_data) { - struct sr_device_instance *sdi = user_data; + struct sr_device_instance *sdi = session_data; struct sigma *sigma = sdi->priv; uint16_t tsdiff, ts; uint16_t samples[65536 * sigma->samples_per_event]; struct sr_datafeed_packet packet; + struct sr_datafeed_logic logic; int i, j, k, l, numpad, tosend; size_t n = 0, sent = 0; int clustersize = EVENTS_PER_CLUSTER * sigma->samples_per_event; @@ -892,9 +895,13 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, tosend = MIN(2048, n - sent); packet.type = SR_DF_LOGIC; - packet.length = tosend * sizeof(uint16_t); - packet.unitsize = 2; - packet.payload = samples + sent; + /* TODO: fill in timeoffset and duration */ + packet.timeoffset = 0; + packet.duration = 0; + packet.payload = &logic; + logic.length = tosend * sizeof(uint16_t); + logic.unitsize = 2; + logic.data = samples + sent; sr_session_bus(sigma->session_id, &packet); sent += tosend; @@ -936,9 +943,13 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, if (tosend > 0) { packet.type = SR_DF_LOGIC; - packet.length = tosend * sizeof(uint16_t); - packet.unitsize = 2; - packet.payload = samples; + /* TODO: fill in timeoffset and duration */ + packet.timeoffset = 0; + packet.duration = 0; + packet.payload = &logic; + logic.length = tosend * sizeof(uint16_t); + logic.unitsize = 2; + logic.data = samples; sr_session_bus(sigma->session_id, &packet); sent += tosend; @@ -947,8 +958,9 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, /* Only send trigger if explicitly enabled. */ if (sigma->use_triggers) { packet.type = SR_DF_TRIGGER; - packet.length = 0; - packet.payload = 0; + /* TODO: fill in timeoffset only */ + packet.timeoffset = 0; + packet.duration = 0; sr_session_bus(sigma->session_id, &packet); } } @@ -958,9 +970,13 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, if (tosend > 0) { packet.type = SR_DF_LOGIC; - packet.length = tosend * sizeof(uint16_t); - packet.unitsize = 2; - packet.payload = samples + sent; + /* TODO: fill in timeoffset and duration */ + packet.timeoffset = 0; + packet.duration = 0; + packet.payload = &logic; + logic.length = tosend * sizeof(uint16_t); + logic.unitsize = 2; + logic.data = samples + sent; sr_session_bus(sigma->session_id, &packet); } @@ -970,9 +986,9 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, return SR_OK; } -static int receive_data(int fd, int revents, void *user_data) +static int receive_data(int fd, int revents, void *session_data) { - struct sr_device_instance *sdi = user_data; + struct sr_device_instance *sdi = session_data; struct sigma *sigma = sdi->priv; struct sr_datafeed_packet packet; const int chunks_per_read = 32; @@ -999,7 +1015,7 @@ static int receive_data(int fd, int revents, void *user_data) if (running_msec < sigma->limit_msec && numchunks < 32767) return FALSE; - hw_stop_acquisition(sdi->index, user_data); + hw_stop_acquisition(sdi->index, session_data); return FALSE; @@ -1007,7 +1023,6 @@ static int receive_data(int fd, int revents, void *user_data) if (sigma->state.chunks_downloaded >= numchunks) { /* End of samples. */ packet.type = SR_DF_END; - packet.length = 0; sr_session_bus(sigma->session_id, &packet); sigma->state.state = SIGMA_IDLE; @@ -1046,12 +1061,12 @@ static int receive_data(int fd, int revents, void *user_data) &sigma->state.lastts, &sigma->state.lastsample, sigma->state.triggerpos & 0x1ff, - limit_chunk, user_data); + limit_chunk, session_data); else decode_chunk_ts(buf + (i * CHUNK_SIZE), &sigma->state.lastts, &sigma->state.lastsample, - -1, limit_chunk, user_data); + -1, limit_chunk, session_data); ++sigma->state.chunks_downloaded; } @@ -1216,7 +1231,7 @@ static int build_basic_trigger(struct triggerlut *lut, struct sigma *sigma) return SR_OK; } -static int hw_start_acquisition(int device_index, gpointer session_device_id) +static int hw_start_acquisition(int device_index, gpointer session_data) { struct sr_device_instance *sdi; struct sigma *sigma; @@ -1228,7 +1243,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) struct triggerinout triggerinout_conf; struct triggerlut lut; - session_device_id = session_device_id; + session_data = session_data; if (!(sdi = sr_get_device_instance(device_instances, device_index))) return SR_ERR; @@ -1313,19 +1328,17 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) gettimeofday(&sigma->start_tv, 0); sigma_set_register(WRITE_MODE, 0x0d, sigma); - sigma->session_id = session_device_id; + sigma->session_id = session_data; /* Send header packet to the session bus. */ packet.type = SR_DF_HEADER; - packet.length = sizeof(struct sr_datafeed_header); packet.payload = &header; header.feed_version = 1; gettimeofday(&header.starttime, NULL); header.samplerate = sigma->cur_samplerate; - header.protocol_id = SR_PROTO_RAW; header.num_logic_probes = sigma->num_probes; header.num_analog_probes = 0; - sr_session_bus(session_device_id, &packet); + sr_session_bus(session_data, &packet); /* Add capture source. */ sr_source_add(0, G_IO_IN, 10, receive_data, sdi); @@ -1335,7 +1348,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) return SR_OK; } -static void hw_stop_acquisition(int device_index, gpointer session_device_id) +static void hw_stop_acquisition(int device_index, gpointer session_data) { struct sr_device_instance *sdi; struct sigma *sigma; @@ -1346,7 +1359,7 @@ static void hw_stop_acquisition(int device_index, gpointer session_device_id) sigma = sdi->priv; - session_device_id = session_device_id; + session_data = session_data; /* Stop acquisition. */ sigma_set_register(WRITE_MODE, 0x11, sigma); diff --git a/hardware/asix-sigma/asix-sigma.h b/hardware/asix-sigma/asix-sigma.h index 10152bf5..9e35805a 100644 --- a/hardware/asix-sigma/asix-sigma.h +++ b/hardware/asix-sigma/asix-sigma.h @@ -176,6 +176,7 @@ struct sigma_state { struct sigma { struct ftdi_context ftdic; uint64_t cur_samplerate; + uint64_t period_ps; uint64_t limit_msec; struct timeval start_tv; int cur_firmware; diff --git a/hardware/chronovu-la8/chronovu-la8.c b/hardware/chronovu-la8/chronovu-la8.c index 95d6c038..05af43b9 100644 --- a/hardware/chronovu-la8/chronovu-la8.c +++ b/hardware/chronovu-la8/chronovu-la8.c @@ -48,6 +48,9 @@ struct la8 { /** The currently configured samplerate of the device. */ uint64_t cur_samplerate; + /** period in picoseconds corresponding to the samplerate */ + uint64_t period_ps; + /** The current sampling limit (in ms). */ uint64_t limit_msec; @@ -123,7 +126,7 @@ static int capabilities[] = { /* Function prototypes. */ static int la8_close_usb_reset_sequencer(struct la8 *la8); -static void hw_stop_acquisition(int device_index, gpointer session_device_id); +static void hw_stop_acquisition(int device_index, gpointer session_data); static int la8_reset(struct la8 *la8); static void fill_supported_samplerates_if_needed(void) @@ -479,6 +482,7 @@ static int hw_init(const char *deviceinfo) /* Set some sane defaults. */ la8->ftdic = NULL; la8->cur_samplerate = SR_MHZ(100); /* 100MHz == max. samplerate */ + la8->period_ps = 10000; la8->limit_msec = 0; la8->limit_samples = 0; la8->session_id = NULL; @@ -633,6 +637,7 @@ static int set_samplerate(struct sr_device_instance *sdi, uint64_t samplerate) /* Set the new samplerate. */ la8->cur_samplerate = samplerate; + la8->period_ps = 1000000000000 / samplerate; sr_dbg("la8: samplerate set to %" PRIu64 "Hz", la8->cur_samplerate); @@ -879,6 +884,7 @@ static void send_block_to_session_bus(struct la8 *la8, int block) int i; uint8_t sample, expected_sample; struct sr_datafeed_packet packet; + struct sr_datafeed_logic logic; int trigger_point; /* Relative trigger point (in this block). */ /* Note: No sanity checks on la8/block, caller is responsible. */ @@ -914,9 +920,12 @@ static void send_block_to_session_bus(struct la8 *la8, int block) sr_spew("la8: sending SR_DF_LOGIC packet (%d bytes) for " "block %d", BS, block); packet.type = SR_DF_LOGIC; - packet.length = BS; - packet.unitsize = 1; - packet.payload = la8->final_buf + (block * BS); + packet.timeoffset = block * BS * la8->period_ps; + packet.duration = BS * la8->period_ps; + packet.payload = &logic; + logic.length = BS; + logic.unitsize = 1; + logic.data = la8->final_buf + (block * BS); sr_session_bus(la8->session_id, &packet); return; } @@ -936,9 +945,12 @@ static void send_block_to_session_bus(struct la8 *la8, int block) sr_spew("la8: sending pre-trigger SR_DF_LOGIC packet, " "start = %d, length = %d", block * BS, trigger_point); packet.type = SR_DF_LOGIC; - packet.length = trigger_point; - packet.unitsize = 1; - packet.payload = la8->final_buf + (block * BS); + packet.timeoffset = block * BS * la8->period_ps; + packet.duration = trigger_point * la8->period_ps; + packet.payload = &logic; + logic.length = trigger_point; + logic.unitsize = 1; + logic.data = la8->final_buf + (block * BS); sr_session_bus(la8->session_id, &packet); } @@ -946,8 +958,8 @@ static void send_block_to_session_bus(struct la8 *la8, int block) sr_spew("la8: sending SR_DF_TRIGGER packet, sample = %d", (block * BS) + trigger_point); packet.type = SR_DF_TRIGGER; - packet.length = 0; - packet.unitsize = 0; + packet.timeoffset = (block * BS + trigger_point) * la8->period_ps; + packet.duration = 0; packet.payload = NULL; sr_session_bus(la8->session_id, &packet); @@ -958,14 +970,17 @@ static void send_block_to_session_bus(struct la8 *la8, int block) "start = %d, length = %d", (block * BS) + trigger_point, BS - trigger_point); packet.type = SR_DF_LOGIC; - packet.length = BS - trigger_point; - packet.unitsize = 1; - packet.payload = la8->final_buf + (block * BS) + trigger_point; + packet.timeoffset = (block * BS + trigger_point) * la8->period_ps; + packet.duration = (BS - trigger_point) * la8->period_ps; + packet.payload = &logic; + logic.length = BS - trigger_point; + logic.unitsize = 1; + logic.data = la8->final_buf + (block * BS) + trigger_point; sr_session_bus(la8->session_id, &packet); } } -static int receive_data(int fd, int revents, void *user_data) +static int receive_data(int fd, int revents, void *session_data) { int i, ret; struct sr_device_instance *sdi; @@ -975,7 +990,7 @@ static int receive_data(int fd, int revents, void *user_data) fd = fd; revents = revents; - if (!(sdi = user_data)) { + if (!(sdi = session_data)) { sr_err("la8: %s: user_data was NULL", __func__); return FALSE; } @@ -988,7 +1003,7 @@ static int receive_data(int fd, int revents, void *user_data) /* Get one block of data. */ if ((ret = la8_read_block(la8)) < 0) { sr_err("la8: %s: la8_read_block error: %d", __func__, ret); - hw_stop_acquisition(sdi->index, user_data); + hw_stop_acquisition(sdi->index, session_data); return FALSE; } @@ -1004,13 +1019,13 @@ static int receive_data(int fd, int revents, void *user_data) for (i = 0; i < NUM_BLOCKS; i++) send_block_to_session_bus(la8, i); - hw_stop_acquisition(sdi->index, user_data); + hw_stop_acquisition(sdi->index, session_data); // return FALSE; /* FIXME? */ return TRUE; } -static int hw_start_acquisition(int device_index, gpointer session_device_id) +static int hw_start_acquisition(int device_index, gpointer session_data) { struct sr_device_instance *sdi; struct la8 *la8; @@ -1061,21 +1076,18 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) sr_dbg("la8: acquisition started successfully"); - la8->session_id = session_device_id; + la8->session_id = session_data; /* Send header packet to the session bus. */ sr_dbg("la8: %s: sending SR_DF_HEADER", __func__); packet.type = SR_DF_HEADER; - packet.length = sizeof(struct sr_datafeed_header); - packet.unitsize = 0; packet.payload = &header; header.feed_version = 1; gettimeofday(&header.starttime, NULL); header.samplerate = la8->cur_samplerate; - header.protocol_id = SR_PROTO_RAW; header.num_logic_probes = NUM_PROBES; header.num_analog_probes = 0; - sr_session_bus(session_device_id, &packet); + sr_session_bus(session_data, &packet); /* Time when we should be done (for detecting trigger timeouts). */ la8->done = (la8->divcount + 1) * 0.08388608 + time(NULL) @@ -1089,7 +1101,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) return SR_OK; } -static void hw_stop_acquisition(int device_index, gpointer session_device_id) +static void hw_stop_acquisition(int device_index, gpointer session_data) { struct sr_device_instance *sdi; struct la8 *la8; @@ -1110,10 +1122,7 @@ static void hw_stop_acquisition(int device_index, gpointer session_device_id) /* Send end packet to the session bus. */ sr_dbg("la8: %s: sending SR_DF_END", __func__); packet.type = SR_DF_END; - packet.length = 0; - packet.unitsize = 0; - packet.payload = NULL; - sr_session_bus(session_device_id, &packet); + sr_session_bus(session_data, &packet); } struct sr_device_plugin chronovu_la8_plugin_info = { diff --git a/hardware/demo/demo.c b/hardware/demo/demo.c index c10316ab..c06a814a 100644 --- a/hardware/demo/demo.c +++ b/hardware/demo/demo.c @@ -73,7 +73,7 @@ struct databag { uint8_t thread_running; uint64_t samples_counter; int device_index; - gpointer session_device_id; + gpointer session_data; GTimer *timer; }; @@ -116,13 +116,14 @@ static uint8_t pattern_sigrok[] = { /* List of struct sr_device_instance, maintained by opendev()/closedev(). */ static GSList *device_instances = NULL; static uint64_t cur_samplerate = SR_KHZ(200); +static uint64_t period_ps = 5000000; static uint64_t limit_samples = 0; static uint64_t limit_msec = 0; static int default_pattern = PATTERN_SIGROK; static GThread *my_thread; static int thread_running; -static void hw_stop_acquisition(int device_index, gpointer session_device_id); +static void hw_stop_acquisition(int device_index, gpointer session_data); static int hw_init(const char *deviceinfo) { @@ -224,6 +225,7 @@ static int hw_set_configuration(int device_index, int capability, void *value) ret = SR_OK; } else if (capability == SR_HWCAP_SAMPLERATE) { cur_samplerate = *(uint64_t *)value; + period_ps = 1000000000000 / cur_samplerate; sr_dbg("demo: %s: setting samplerate to %" PRIu64, __func__, cur_samplerate); ret = SR_OK; @@ -348,10 +350,12 @@ static void thread_func(void *data) } /* Callback handling data */ -static int receive_data(int fd, int revents, void *user_data) +static int receive_data(int fd, int revents, void *session_data) { struct sr_datafeed_packet packet; - char c[BUFSIZE]; + struct sr_datafeed_logic logic; + static uint64_t samples_received = 0; + unsigned char c[BUFSIZE]; gsize z; /* Avoid compiler warnings. */ @@ -364,10 +368,14 @@ static int receive_data(int fd, int revents, void *user_data) if (z > 0) { packet.type = SR_DF_LOGIC; - packet.length = z; - packet.unitsize = 1; - packet.payload = c; - sr_session_bus(user_data, &packet); + packet.payload = &logic; + packet.timeoffset = samples_received * period_ps; + packet.duration = z * period_ps; + logic.length = z; + logic.unitsize = 1; + logic.data = c; + sr_session_bus(session_data, &packet); + samples_received += z; } } while (z > 0); @@ -377,7 +385,7 @@ static int receive_data(int fd, int revents, void *user_data) /* Send last packet. */ packet.type = SR_DF_END; - sr_session_bus(user_data, &packet); + sr_session_bus(session_data, &packet); return FALSE; } @@ -385,7 +393,7 @@ static int receive_data(int fd, int revents, void *user_data) return TRUE; } -static int hw_start_acquisition(int device_index, gpointer session_device_id) +static int hw_start_acquisition(int device_index, gpointer session_data) { struct sr_datafeed_packet *packet; struct sr_datafeed_header *header; @@ -398,7 +406,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) } mydata->sample_generator = default_pattern; - mydata->session_device_id = session_device_id; + mydata->session_data = session_data; mydata->device_index = device_index; mydata->samples_counter = 0; @@ -420,7 +428,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) g_io_channel_set_buffered(channels[1], FALSE); sr_source_add(mydata->pipe_fds[0], G_IO_IN | G_IO_ERR, 40, - receive_data, session_device_id); + receive_data, session_data); /* Run the demo thread. */ g_thread_init(NULL); @@ -445,26 +453,26 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) } packet->type = SR_DF_HEADER; - packet->length = sizeof(struct sr_datafeed_header); - packet->payload = (unsigned char *)header; + packet->payload = header; + packet->timeoffset = 0; + packet->duration = 0; header->feed_version = 1; gettimeofday(&header->starttime, NULL); header->samplerate = cur_samplerate; - header->protocol_id = SR_PROTO_RAW; header->num_logic_probes = NUM_PROBES; header->num_analog_probes = 0; - sr_session_bus(session_device_id, packet); + sr_session_bus(session_data, packet); g_free(header); g_free(packet); return SR_OK; } -static void hw_stop_acquisition(int device_index, gpointer session_device_id) +static void hw_stop_acquisition(int device_index, gpointer session_data) { /* Avoid compiler warnings. */ device_index = device_index; - session_device_id = session_device_id; + session_data = session_data; /* Stop generate thread. */ thread_running = 0; diff --git a/hardware/openbench-logic-sniffer/ols.c b/hardware/openbench-logic-sniffer/ols.c index e9f0c2d3..e7daa016 100644 --- a/hardware/openbench-logic-sniffer/ols.c +++ b/hardware/openbench-logic-sniffer/ols.c @@ -180,6 +180,7 @@ static struct ols_device *ols_device_new(void) ols->trigger_at = -1; ols->probe_mask = 0xffffffff; ols->cur_samplerate = SR_KHZ(200); + ols->period_ps = 5000000; return ols; } @@ -553,6 +554,7 @@ static int set_configuration_samplerate(struct sr_device_instance *sdi, return SR_ERR_SAMPLERATE; ols->cur_samplerate = samplerate; + ols->period_ps = 1000000000000 / samplerate; if (samplerate > CLOCK_RATE) { ols->flag_reg |= FLAG_DEMUX; ols->cur_samplerate_divider = (CLOCK_RATE * 2 / samplerate) - 1; @@ -610,9 +612,10 @@ static int hw_set_configuration(int device_index, int capability, void *value) return ret; } -static int receive_data(int fd, int revents, void *user_data) +static int receive_data(int fd, int revents, void *session_data) { struct sr_datafeed_packet packet; + struct sr_datafeed_logic logic; struct sr_device_instance *sdi; struct ols_device *ols; GSList *l; @@ -640,7 +643,7 @@ static int receive_data(int fd, int revents, void *user_data) * finished. We'll double that to 30ms to be sure... */ sr_source_remove(fd); - sr_source_add(fd, G_IO_IN, 30, receive_data, user_data); + sr_source_add(fd, G_IO_IN, 30, receive_data, session_data); ols->raw_sample_buf = g_try_malloc(ols->limit_samples * 4); if (!ols->raw_sample_buf) { sr_err("ols: %s: ols->raw_sample_buf malloc failed", @@ -759,41 +762,55 @@ static int receive_data(int fd, int revents, void *user_data) if (ols->trigger_at > 0) { /* there are pre-trigger samples, send those first */ packet.type = SR_DF_LOGIC; - packet.length = ols->trigger_at * 4; - packet.unitsize = 4; - packet.payload = ols->raw_sample_buf; - sr_session_bus(user_data, &packet); + packet.timeoffset = 0; + packet.duration = ols->trigger_at * ols->period_ps; + packet.payload = &logic; + logic.length = ols->trigger_at * 4; + logic.unitsize = 4; + logic.data = ols->raw_sample_buf; + sr_session_bus(session_data, &packet); } + /* send the trigger */ packet.type = SR_DF_TRIGGER; - packet.length = 0; - sr_session_bus(user_data, &packet); + packet.timeoffset = ols->trigger_at * ols->period_ps; + packet.duration = 0; + sr_session_bus(session_data, &packet); + /* send post-trigger samples */ packet.type = SR_DF_LOGIC; - packet.length = (ols->limit_samples * 4) - (ols->trigger_at * 4); - packet.unitsize = 4; - packet.payload = ols->raw_sample_buf + ols->trigger_at * 4; - sr_session_bus(user_data, &packet); + packet.timeoffset = ols->trigger_at * ols->period_ps; + packet.duration = (ols->limit_samples - ols->trigger_at) * ols->period_ps; + packet.payload = &logic; + logic.length = (ols->limit_samples * 4) - (ols->trigger_at * 4); + logic.unitsize = 4; + logic.data = ols->raw_sample_buf + ols->trigger_at * 4; + sr_session_bus(session_data, &packet); } else { + /* no trigger was used */ packet.type = SR_DF_LOGIC; - packet.length = ols->limit_samples * 4; - packet.unitsize = 4; - packet.payload = ols->raw_sample_buf; - sr_session_bus(user_data, &packet); + packet.timeoffset = 0; + packet.duration = ols->limit_samples * ols->period_ps; + packet.payload = &logic; + logic.length = ols->limit_samples * 4; + logic.unitsize = 4; + logic.data = ols->raw_sample_buf; + sr_session_bus(session_data, &packet); } g_free(ols->raw_sample_buf); serial_flush(fd); serial_close(fd); packet.type = SR_DF_END; - packet.length = 0; - sr_session_bus(user_data, &packet); + packet.timeoffset = ols->limit_samples * ols->period_ps; + packet.duration = 0; + sr_session_bus(session_data, &packet); } return TRUE; } -static int hw_start_acquisition(int device_index, gpointer session_device_id) +static int hw_start_acquisition(int device_index, gpointer session_data) { struct sr_datafeed_packet *packet; struct sr_datafeed_header *header; @@ -908,7 +925,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) return SR_ERR; sr_source_add(sdi->serial->fd, G_IO_IN, -1, receive_data, - session_device_id); + session_data); if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) { sr_err("ols: %s: packet malloc failed", __func__); @@ -923,15 +940,13 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) /* Send header packet to the session bus. */ packet->type = SR_DF_HEADER; - packet->length = sizeof(struct sr_datafeed_header); packet->payload = (unsigned char *)header; header->feed_version = 1; gettimeofday(&header->starttime, NULL); header->samplerate = ols->cur_samplerate; - header->protocol_id = SR_PROTO_RAW; header->num_logic_probes = NUM_PROBES; header->num_analog_probes = 0; - sr_session_bus(session_device_id, packet); + sr_session_bus(session_data, packet); g_free(header); g_free(packet); @@ -947,7 +962,6 @@ static void hw_stop_acquisition(int device_index, gpointer session_device_id) device_index = device_index; packet.type = SR_DF_END; - packet.length = 0; sr_session_bus(session_device_id, &packet); } diff --git a/hardware/openbench-logic-sniffer/ols.h b/hardware/openbench-logic-sniffer/ols.h index e0161b08..e6afd0e0 100644 --- a/hardware/openbench-logic-sniffer/ols.h +++ b/hardware/openbench-logic-sniffer/ols.h @@ -67,6 +67,7 @@ struct ols_device { uint64_t cur_samplerate; uint32_t cur_samplerate_divider; + uint64_t period_ps; uint64_t limit_samples; /* Current state of the flag register */ uint32_t flag_reg; diff --git a/hardware/saleae-logic/saleae-logic.c b/hardware/saleae-logic/saleae-logic.c index 0940fab4..c5a81e36 100644 --- a/hardware/saleae-logic/saleae-logic.c +++ b/hardware/saleae-logic/saleae-logic.c @@ -517,6 +517,7 @@ static int set_configuration_samplerate(struct sr_device_instance *sdi, return SR_ERR; } fx2->cur_samplerate = samplerate; + fx2->period_ps = 1000000000000 / samplerate; return SR_OK; } @@ -565,9 +566,11 @@ static int receive_data(int fd, int revents, void *user_data) void receive_transfer(struct libusb_transfer *transfer) { + /* TODO: these statics have to move to fx2_device struct */ static int num_samples = 0; static int empty_transfer_count = 0; struct sr_datafeed_packet packet; + struct sr_datafeed_logic logic; struct fx2_device *fx2; int cur_buflen, trigger_offset, i; unsigned char *cur_buf, *new_buf; @@ -639,7 +642,9 @@ void receive_transfer(struct libusb_transfer *transfer) * Tell the frontend we hit the trigger here. */ packet.type = SR_DF_TRIGGER; - packet.length = 0; + packet.timeoffset = (num_samples - fx2->trigger_stage) * fx2->period_ps; + packet.duration = 0; + packet.payload = NULL; sr_session_bus(fx2->session_data, &packet); /* @@ -647,9 +652,12 @@ void receive_transfer(struct libusb_transfer *transfer) * skipping past them. */ packet.type = SR_DF_LOGIC; - packet.length = fx2->trigger_stage; - packet.unitsize = 1; - packet.payload = fx2->trigger_buffer; + packet.timeoffset = (num_samples - fx2->trigger_stage) * fx2->period_ps; + packet.duration = fx2->trigger_stage * fx2->period_ps; + packet.payload = &logic; + logic.length = fx2->trigger_stage; + logic.unitsize = 1; + logic.data = fx2->trigger_buffer; sr_session_bus(fx2->session_data, &packet); fx2->trigger_stage = TRIGGER_FIRED; @@ -678,9 +686,12 @@ void receive_transfer(struct libusb_transfer *transfer) if (fx2->trigger_stage == TRIGGER_FIRED) { /* Send the incoming transfer to the session bus. */ packet.type = SR_DF_LOGIC; - packet.length = cur_buflen - trigger_offset; - packet.unitsize = 1; - packet.payload = cur_buf + trigger_offset; + packet.timeoffset = num_samples * fx2->period_ps; + packet.duration = cur_buflen * fx2->period_ps; + packet.payload = &logic; + logic.length = cur_buflen - trigger_offset; + logic.unitsize = 1; + logic.data = cur_buf + trigger_offset; sr_session_bus(fx2->session_data, &packet); g_free(cur_buf); @@ -716,7 +727,7 @@ static int hw_start_acquisition(int device_index, gpointer session_data) sr_err("saleae: %s: packet malloc failed", __func__); return SR_ERR_MALLOC; } - + if (!(header = g_try_malloc(sizeof(struct sr_datafeed_header)))) { sr_err("saleae: %s: header malloc failed", __func__); return SR_ERR_MALLOC; @@ -749,12 +760,10 @@ static int hw_start_acquisition(int device_index, gpointer session_data) free(lupfd); packet->type = SR_DF_HEADER; - packet->length = sizeof(struct sr_datafeed_header); - packet->payload = (unsigned char *)header; + packet->payload = header; header->feed_version = 1; gettimeofday(&header->starttime, NULL); header->samplerate = fx2->cur_samplerate; - header->protocol_id = SR_PROTO_RAW; header->num_logic_probes = fx2->profile->num_probes; header->num_analog_probes = 0; sr_session_bus(session_data, packet); diff --git a/hardware/saleae-logic/saleae-logic.h b/hardware/saleae-logic/saleae-logic.h index b01eebb0..9ccd8a1a 100644 --- a/hardware/saleae-logic/saleae-logic.h +++ b/hardware/saleae-logic/saleae-logic.h @@ -60,6 +60,7 @@ struct fx2_device { GTimeVal fw_updated; /* device/capture settings */ uint64_t cur_samplerate; + uint64_t period_ps; uint64_t limit_samples; uint8_t probe_mask; uint8_t trigger_mask[NUM_TRIGGER_STAGES]; diff --git a/hardware/zeroplus-logic-cube/zeroplus.c b/hardware/zeroplus-logic-cube/zeroplus.c index 875291ee..b25ce364 100644 --- a/hardware/zeroplus-logic-cube/zeroplus.c +++ b/hardware/zeroplus-logic-cube/zeroplus.c @@ -118,6 +118,7 @@ static struct sr_samplerates samplerates = { /* TODO: All of these should go in a device-specific struct. */ static uint64_t cur_samplerate = 0; +static uint64_t period_ps = 0; static uint64_t limit_samples = 0; static int num_channels = 32; /* TODO: This isn't initialized before it's needed :( */ static uint64_t memory_size = 0; @@ -461,6 +462,7 @@ static int set_configuration_samplerate(uint64_t samplerate) analyzer_set_freq(samplerate, FREQ_SCALE_HZ); cur_samplerate = samplerate; + period_ps = 1000000000000 / samplerate; return SR_OK; } @@ -488,11 +490,13 @@ static int hw_set_configuration(int device_index, int capability, void *value) } } -static int hw_start_acquisition(int device_index, gpointer session_device_id) +static int hw_start_acquisition(int device_index, gpointer session_data) { struct sr_device_instance *sdi; struct sr_datafeed_packet packet; + struct sr_datafeed_logic logic; struct sr_datafeed_header header; + uint64_t samples_read; int res; unsigned int packet_num; unsigned char *buf; @@ -507,50 +511,48 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) sr_info("Waiting for data"); analyzer_wait_data(sdi->usb->devhdl); - sr_info("Stop address = 0x%x", - analyzer_get_stop_address(sdi->usb->devhdl)); - sr_info("Now address = 0x%x", - analyzer_get_now_address(sdi->usb->devhdl)); - sr_info("Trigger address = 0x%x", - analyzer_get_trigger_address(sdi->usb->devhdl)); + sr_info("Stop address = 0x%x", analyzer_get_stop_address(sdi->usb->devhdl)); + sr_info("Now address = 0x%x", analyzer_get_now_address(sdi->usb->devhdl)); + sr_info("Trigger address = 0x%x", analyzer_get_trigger_address(sdi->usb->devhdl)); packet.type = SR_DF_HEADER; - packet.length = sizeof(struct sr_datafeed_header); - packet.payload = (unsigned char *)&header; + packet.payload = &header; header.feed_version = 1; gettimeofday(&header.starttime, NULL); header.samplerate = cur_samplerate; - header.protocol_id = SR_PROTO_RAW; header.num_logic_probes = num_channels; header.num_analog_probes = 0; - sr_session_bus(session_device_id, &packet); + sr_session_bus(session_data, &packet); if (!(buf = g_try_malloc(PACKET_SIZE))) { sr_err("lap-c: %s: buf malloc failed", __func__); return SR_ERR_MALLOC; } + samples_read = 0; analyzer_read_start(sdi->usb->devhdl); /* Send the incoming transfer to the session bus. */ for (packet_num = 0; packet_num < (memory_size * 4 / PACKET_SIZE); packet_num++) { res = analyzer_read_data(sdi->usb->devhdl, buf, PACKET_SIZE); -#if 0 sr_info("Tried to read %llx bytes, actually read %x bytes", PACKET_SIZE, res); -#endif packet.type = SR_DF_LOGIC; - packet.length = PACKET_SIZE; - packet.unitsize = 4; - packet.payload = buf; - sr_session_bus(session_device_id, &packet); + packet.timeoffset = samples_read * period_ps; + packet.duration = res / 4 * period_ps; + packet.payload = &logic; + logic.length = PACKET_SIZE; + logic.unitsize = 4; + logic.data = buf; + sr_session_bus(session_data, &packet); + samples_read += res / 4; } analyzer_read_stop(sdi->usb->devhdl); g_free(buf); packet.type = SR_DF_END; - sr_session_bus(session_device_id, &packet); + sr_session_bus(session_data, &packet); return SR_OK; } diff --git a/input/input_binary.c b/input/input_binary.c index 2b5580d9..d9a53cb6 100644 --- a/input/input_binary.c +++ b/input/input_binary.c @@ -60,7 +60,8 @@ static int loadfile(struct sr_input *in, const char *filename) { struct sr_datafeed_header header; struct sr_datafeed_packet packet; - char buffer[CHUNKSIZE]; + struct sr_datafeed_logic logic; + unsigned char buffer[CHUNKSIZE]; int fd, size, num_probes; if ((fd = open(filename, O_RDONLY)) == -1) @@ -72,27 +73,25 @@ static int loadfile(struct sr_input *in, const char *filename) header.feed_version = 1; header.num_logic_probes = num_probes; header.num_analog_probes = 0; - header.protocol_id = SR_PROTO_RAW; header.samplerate = 0; gettimeofday(&header.starttime, NULL); packet.type = SR_DF_HEADER; - packet.length = sizeof(struct sr_datafeed_header); packet.payload = &header; sr_session_bus(in->vdevice, &packet); /* chop up the input file into chunks and feed it into the session bus */ packet.type = SR_DF_LOGIC; - packet.unitsize = (num_probes + 7) / 8; - packet.payload = buffer; + packet.payload = &logic; + logic.unitsize = (num_probes + 7) / 8; + logic.data = buffer; while ((size = read(fd, buffer, CHUNKSIZE)) > 0) { - packet.length = size; + logic.length = size; sr_session_bus(in->vdevice, &packet); } close(fd); /* end of stream */ packet.type = SR_DF_END; - packet.length = 0; sr_session_bus(in->vdevice, &packet); return SR_OK; diff --git a/input/input_chronovu_la8.c b/input/input_chronovu_la8.c index dc6a0117..6ce66c0c 100644 --- a/input/input_chronovu_la8.c +++ b/input/input_chronovu_la8.c @@ -99,6 +99,7 @@ static int loadfile(struct sr_input *in, const char *filename) { struct sr_datafeed_header header; struct sr_datafeed_packet packet; + struct sr_datafeed_logic logic; uint8_t buf[PACKET_SIZE], divcount; int i, fd, size, num_probes; uint64_t samplerate; @@ -125,14 +126,11 @@ static int loadfile(struct sr_input *in, const char *filename) /* Send header packet to the session bus. */ sr_dbg("la8input: %s: sending SR_DF_HEADER packet", __func__); packet.type = SR_DF_HEADER; - packet.length = sizeof(struct sr_datafeed_header); - packet.unitsize = 0; packet.payload = &header; header.feed_version = 1; gettimeofday(&header.starttime, NULL); header.num_logic_probes = num_probes; header.num_analog_probes = 0; - header.protocol_id = SR_PROTO_RAW; header.samplerate = samplerate; sr_session_bus(in->vdevice, &packet); @@ -141,14 +139,15 @@ static int loadfile(struct sr_input *in, const char *filename) /* Send data packets to the session bus. */ sr_dbg("la8input: %s: sending SR_DF_LOGIC data packets", __func__); packet.type = SR_DF_LOGIC; - packet.unitsize = (num_probes + 7) / 8; - packet.payload = buf; + packet.payload = &logic; + logic.unitsize = (num_probes + 7) / 8; + logic.data = buf; /* Send 8MB of total data to the session bus in small chunks. */ for (i = 0; i < NUM_PACKETS; i++) { /* TODO: Handle errors, handle incomplete reads. */ size = read(fd, buf, PACKET_SIZE); - packet.length = PACKET_SIZE; + logic.length = PACKET_SIZE; sr_session_bus(in->vdevice, &packet); } close(fd); /* FIXME */ @@ -156,8 +155,6 @@ static int loadfile(struct sr_input *in, const char *filename) /* Send end packet to the session bus. */ sr_dbg("la8input: %s: sending SR_DF_END", __func__); packet.type = SR_DF_END; - packet.length = 0; - packet.unitsize = 0; packet.payload = NULL; sr_session_bus(in->vdevice, &packet); diff --git a/session_driver.c b/session_driver.c index 9ad4fb8a..f0b4b0f9 100644 --- a/session_driver.c +++ b/session_driver.c @@ -60,11 +60,12 @@ static struct session_vdevice *get_vdevice_by_index(int device_index) return vdevice; } -static int feed_chunk(int fd, int revents, void *user_data) +static int feed_chunk(int fd, int revents, void *session_data) { struct sr_device_instance *sdi; struct session_vdevice *vdevice; struct sr_datafeed_packet packet; + struct sr_datafeed_logic logic; GSList *l; void *buf; int ret, got_data; @@ -93,10 +94,13 @@ static int feed_chunk(int fd, int revents, void *user_data) if (ret > 0) { got_data = TRUE; packet.type = SR_DF_LOGIC; - packet.length = ret; - packet.unitsize = vdevice->unitsize; - packet.payload = buf; - sr_session_bus(user_data, &packet); + packet.timeoffset = 0; + packet.duration = 0; + packet.payload = &logic; + logic.length = ret; + logic.unitsize = vdevice->unitsize; + logic.data = buf; + sr_session_bus(session_data, &packet); } else { /* done with this capture file */ zip_fclose(vdevice->capfile); @@ -108,8 +112,7 @@ static int feed_chunk(int fd, int revents, void *user_data) if (!got_data) { packet.type = SR_DF_END; - packet.length = 0; - sr_session_bus(user_data, &packet); + sr_session_bus(session_data, &packet); } return TRUE; @@ -270,12 +273,10 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) /* Send header packet to the session bus. */ packet->type = SR_DF_HEADER; - packet->length = sizeof(struct sr_datafeed_header); packet->payload = (unsigned char *)header; header->feed_version = 1; gettimeofday(&header->starttime, NULL); header->samplerate = 0; - header->protocol_id = SR_PROTO_RAW; header->num_logic_probes = vdevice->num_probes; header->num_analog_probes = 0; sr_session_bus(session_device_id, packet); diff --git a/sigrok.h b/sigrok.h index cc3b99c1..c3629831 100644 --- a/sigrok.h +++ b/sigrok.h @@ -123,7 +123,7 @@ struct sr_datafeed_header { struct sr_datafeed_logic { uint64_t length; uint16_t unitsize; - unsigned char *data; + void *data; }; struct sr_datafeed_pd {