if (serial_write_blocking(serial, buf, 1, serial_timeout(serial, 1)) != 1)
return SR_ERR;
- if (serial_drain(serial) != 0)
+ if (serial_drain(serial) != SR_OK)
return SR_ERR;
return SR_OK;
if (serial_write_blocking(serial, buf, 5, serial_timeout(serial, 1)) != 5)
return SR_ERR;
- if (serial_drain(serial) != 0)
+ if (serial_drain(serial) != SR_OK)
return SR_ERR;
return SR_OK;
struct dev_context *devc;
devc = g_malloc0(sizeof(struct dev_context));
+ devc->trigger_at_smpl = OLS_NO_TRIGGER;
- /* Device-specific settings */
- devc->max_samples = devc->max_samplerate = devc->protocol_version = 0;
+ return devc;
+}
+
+static void ols_channel_new(struct sr_dev_inst *sdi, int num_chan)
+{
+ struct dev_context *devc = sdi->priv;
+ int i;
- /* Acquisition settings */
- devc->limit_samples = devc->capture_ratio = 0;
- devc->trigger_at = -1;
- devc->flag_reg = 0;
+ for (i = 0; i < num_chan; i++)
+ sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE,
+ ols_channel_names[i]);
- return devc;
+ devc->max_channels = num_chan;
+}
+
+static void metadata_quirks(struct sr_dev_inst *sdi)
+{
+ struct dev_context *devc;
+ gboolean is_shrimp;
+
+ if (!sdi)
+ return;
+ devc = sdi->priv;
+ if (!devc)
+ return;
+
+ is_shrimp = sdi->model && strcmp(sdi->model, "Shrimp1.0") == 0;
+ if (is_shrimp) {
+ if (!devc->max_channels)
+ ols_channel_new(sdi, 4);
+ if (!devc->max_samples)
+ devc->max_samples = 256 * 1024;
+ if (!devc->max_samplerate)
+ devc->max_samplerate = SR_MHZ(20);
+ }
}
SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial)
{
struct sr_dev_inst *sdi;
struct dev_context *devc;
- uint32_t tmp_int, ui;
+ uint32_t tmp_int;
uint8_t key, type, token;
int delay_ms;
GString *tmp_str, *devname, *version;
switch (token) {
case 0x00:
/* Number of usable channels */
- for (ui = 0; ui < tmp_int; ui++)
- sr_channel_new(sdi, ui, SR_CHANNEL_LOGIC, TRUE,
- ols_channel_names[ui]);
+ ols_channel_new(sdi, tmp_int);
break;
case 0x01:
/* Amount of sample memory available (bytes) */
switch (token) {
case 0x00:
/* Number of usable channels */
- for (ui = 0; ui < tmp_c; ui++)
- sr_channel_new(sdi, ui, SR_CHANNEL_LOGIC, TRUE,
- ols_channel_names[ui]);
+ ols_channel_new(sdi, tmp_c);
break;
case 0x01:
/* protocol version */
g_string_free(devname, FALSE);
g_string_free(version, FALSE);
+ /* Optionally amend received metadata, model specific quirks. */
+ metadata_quirks(sdi);
+
return sdi;
}
if (samplerate > CLOCK_RATE) {
sr_info("Enabling demux mode.");
- devc->flag_reg |= FLAG_DEMUX;
- devc->flag_reg &= ~FLAG_FILTER;
- devc->max_channels = NUM_CHANNELS / 2;
+ devc->capture_flags |= CAPTURE_FLAG_DEMUX;
+ devc->capture_flags &= ~CAPTURE_FLAG_NOISE_FILTER;
devc->cur_samplerate_divider = (CLOCK_RATE * 2 / samplerate) - 1;
} else {
sr_info("Disabling demux mode.");
- devc->flag_reg &= ~FLAG_DEMUX;
- devc->flag_reg |= FLAG_FILTER;
- devc->max_channels = NUM_CHANNELS;
+ devc->capture_flags &= ~CAPTURE_FLAG_DEMUX;
+ devc->capture_flags |= CAPTURE_FLAG_NOISE_FILTER;
devc->cur_samplerate_divider = (CLOCK_RATE / samplerate) - 1;
}
* from the requested.
*/
devc->cur_samplerate = CLOCK_RATE / (devc->cur_samplerate_divider + 1);
- if (devc->flag_reg & FLAG_DEMUX)
+ if (devc->capture_flags & CAPTURE_FLAG_DEMUX)
devc->cur_samplerate *= 2;
if (devc->cur_samplerate != samplerate)
sr_info("Can't match samplerate %" PRIu64 ", using %"
num_ols_changrp = 0;
for (i = 0x20; i > 0x02; i >>= 1) {
- if ((devc->flag_reg & i) == 0) {
+ if ((devc->capture_flags & i) == 0) {
num_ols_changrp++;
}
}
sample = devc->sample[0] | (devc->sample[1] << 8) \
| (devc->sample[2] << 16) | (devc->sample[3] << 24);
sr_dbg("Received sample 0x%.*x.", devc->num_bytes * 2, sample);
- if (devc->flag_reg & FLAG_RLE) {
+ if (devc->capture_flags & CAPTURE_FLAG_RLE) {
/*
* In RLE mode the high bit of the sample is the
* "count" flag, meaning this sample is the number
j = 0;
memset(devc->tmp_sample, 0, 4);
for (i = 0; i < 4; i++) {
- if (((devc->flag_reg >> 2) & (1 << i)) == 0) {
+ if (((devc->capture_flags >> 2) & (1 << i)) == 0) {
/*
* This channel group was
* enabled, copy from received
* sample.
*/
devc->tmp_sample[i] = devc->sample[j++];
- } else if (devc->flag_reg & FLAG_DEMUX && (i > 2)) {
+ } else if (devc->capture_flags & CAPTURE_FLAG_DEMUX && (i > 2)) {
/* group 2 & 3 get added to 0 & 1 */
devc->tmp_sample[i - 2] = devc->sample[j++];
}
sr_dbg("Received %d bytes, %d samples, %d decompressed samples.",
devc->cnt_bytes, devc->cnt_samples,
devc->cnt_samples_rle);
- if (devc->trigger_at != -1) {
+ if (devc->trigger_at_smpl != OLS_NO_TRIGGER) {
/*
* A trigger was set up, so we need to tell the frontend
* about it.
*/
- if (devc->trigger_at > 0) {
+ if (devc->trigger_at_smpl > 0) {
/* There are pre-trigger samples, send those first. */
packet.type = SR_DF_LOGIC;
packet.payload = &logic;
- logic.length = devc->trigger_at * 4;
+ logic.length = devc->trigger_at_smpl * 4;
logic.unitsize = 4;
logic.data = devc->raw_sample_buf +
(devc->limit_samples - devc->num_samples) * 4;
}
/* Send the trigger. */
- packet.type = SR_DF_TRIGGER;
- sr_session_send(sdi, &packet);
+ std_session_send_df_trigger(sdi);
/* Send post-trigger samples. */
packet.type = SR_DF_LOGIC;
packet.payload = &logic;
- logic.length = (devc->num_samples * 4) - (devc->trigger_at * 4);
+ logic.length = (devc->num_samples * 4) - (devc->trigger_at_smpl * 4);
logic.unitsize = 4;
- logic.data = devc->raw_sample_buf + devc->trigger_at * 4 +
+ logic.data = devc->raw_sample_buf + devc->trigger_at_smpl * 4 +
(devc->limit_samples - devc->num_samples) * 4;
sr_session_send(sdi, &packet);
} else {