"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)
{
goto free;
sigma->cur_samplerate = 0;
+ sigma->period_ps = 0;
sigma->limit_msec = 0;
sigma->cur_firmware = -1;
sigma->num_probes = 0;
}
sigma->cur_samplerate = samplerate;
+ sigma->period_ps = 1000000000000 / samplerate;
sigma->samples_per_event = 16 / sigma->num_probes;
sigma->state.state = SIGMA_IDLE;
*/
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;
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;
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;
/* 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);
}
}
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);
}
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;
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;
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;
&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;
}
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;
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;
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);
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;
sigma = sdi->priv;
- session_device_id = session_device_id;
+ session_data = session_data;
/* Stop acquisition. */
sigma_set_register(WRITE_MODE, 0x11, sigma);
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;
/** 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;
/* 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)
/* 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;
/* Set the new samplerate. */
la8->cur_samplerate = samplerate;
+ la8->period_ps = 1000000000000 / samplerate;
sr_dbg("la8: samplerate set to %" PRIu64 "Hz", la8->cur_samplerate);
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. */
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;
}
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);
}
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);
"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;
fd = fd;
revents = revents;
- if (!(sdi = user_data)) {
+ if (!(sdi = session_data)) {
sr_err("la8: %s: user_data was NULL", __func__);
return FALSE;
}
/* 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;
}
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;
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)
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;
/* 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 = {
uint8_t thread_running;
uint64_t samples_counter;
int device_index;
- gpointer session_device_id;
+ gpointer session_data;
GTimer *timer;
};
/* 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)
{
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;
}
/* 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. */
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);
/* Send last packet. */
packet.type = SR_DF_END;
- sr_session_bus(user_data, &packet);
+ sr_session_bus(session_data, &packet);
return FALSE;
}
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;
}
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;
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);
}
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;
ols->trigger_at = -1;
ols->probe_mask = 0xffffffff;
ols->cur_samplerate = SR_KHZ(200);
+ ols->period_ps = 5000000;
return ols;
}
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;
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;
* 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",
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;
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__);
/* 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);
device_index = device_index;
packet.type = SR_DF_END;
- packet.length = 0;
sr_session_bus(session_device_id, &packet);
}
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;
return SR_ERR;
}
fx2->cur_samplerate = samplerate;
+ fx2->period_ps = 1000000000000 / samplerate;
return SR_OK;
}
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;
* 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);
/*
* 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;
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);
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;
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);
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];
/* 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;
analyzer_set_freq(samplerate, FREQ_SCALE_HZ);
cur_samplerate = samplerate;
+ period_ps = 1000000000000 / samplerate;
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 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;
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;
}
{
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)
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;
{
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;
/* 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);
/* 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 */
/* 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);
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;
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);
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;
/* 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);
struct sr_datafeed_logic {
uint64_t length;
uint16_t unitsize;
- unsigned char *data;
+ void *data;
};
struct sr_datafeed_pd {