static const int32_t hwcaps[] = {
SR_CONF_LOGIC_ANALYZER,
SR_CONF_SAMPLERATE,
- SR_CONF_TRIGGER_TYPE,
+ SR_CONF_TRIGGER_MATCH,
SR_CONF_CAPTURE_RATIO,
SR_CONF_LIMIT_SAMPLES,
SR_CONF_EXTERNAL_CLOCK,
SR_CONF_RLE,
};
+static const int32_t trigger_matches[] = {
+ SR_TRIGGER_ZERO,
+ SR_TRIGGER_ONE,
+};
+
#define STR_PATTERN_NONE "None"
#define STR_PATTERN_EXTERNAL "External"
#define STR_PATTERN_INTERNAL "Internal"
if (ols_set_samplerate(sdi, DEFAULT_SAMPLERATE) != SR_OK)
sr_dbg("Failed to set default samplerate (%"PRIu64").",
DEFAULT_SAMPLERATE);
- /* Clear trigger masks, values and stages. */
- ols_configure_channels(sdi);
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
struct dev_context *devc;
GVariant *gvar, *grange[2];
GVariantBuilder gvb;
- int num_channels, i;
+ int num_ols_changrp, i;
(void)cg;
g_variant_builder_add(&gvb, "{sv}", "samplerate-steps", gvar);
*data = g_variant_builder_end(&gvb);
break;
- case SR_CONF_TRIGGER_TYPE:
- *data = g_variant_new_string(TRIGGER_TYPE);
+ case SR_CONF_TRIGGER_MATCH:
+ *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
+ trigger_matches, ARRAY_SIZE(trigger_matches),
+ sizeof(int32_t));
break;
case SR_CONF_PATTERN_MODE:
*data = g_variant_new_strv(patterns, ARRAY_SIZE(patterns));
* Channel groups are turned off if no channels in that group are
* enabled, making more room for samples for the enabled group.
*/
- ols_configure_channels(sdi);
- num_channels = 0;
+ ols_channel_mask(sdi);
+ num_ols_changrp = 0;
for (i = 0; i < 4; i++) {
if (devc->channel_mask & (0xff << (i * 8)))
- num_channels++;
- }
- if (num_channels == 0) {
- /* This can happen, but shouldn't cause too much drama.
- * However we can't continue because the code below would
- * divide by zero. */
- break;
+ num_ols_changrp++;
}
grange[0] = g_variant_new_uint64(MIN_NUM_SAMPLES);
- grange[1] = g_variant_new_uint64(devc->max_samples / num_channels);
+ if (num_ols_changrp)
+ grange[1] = g_variant_new_uint64(devc->max_samples / num_ols_changrp);
+ else
+ grange[1] = g_variant_new_uint64(MIN_NUM_SAMPLES);
*data = g_variant_new_tuple(grange, 2);
break;
default:
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
uint16_t samplecount, readcount, delaycount;
- uint8_t changrp_mask, arg[4];
- int num_channels;
+ uint8_t ols_changrp_mask, arg[4];
+ int num_ols_changrp;
int ret, i;
if (sdi->status != SR_ST_ACTIVE)
devc = sdi->priv;
serial = sdi->conn;
- if (ols_configure_channels(sdi) != SR_OK) {
- sr_err("Failed to configure channels.");
- return SR_ERR;
- }
+ ols_channel_mask(sdi);
- /*
- * Enable/disable channel groups in the flag register according to the
- * channel mask. Calculate this here, because num_channels is needed
- * to limit readcount.
- */
- changrp_mask = 0;
- num_channels = 0;
+ num_ols_changrp = 0;
+ ols_changrp_mask = 0;
for (i = 0; i < 4; i++) {
if (devc->channel_mask & (0xff << (i * 8))) {
- changrp_mask |= (1 << i);
- num_channels++;
+ ols_changrp_mask |= (1 << i);
+ num_ols_changrp++;
}
}
* Limit readcount to prevent reading past the end of the hardware
* buffer.
*/
- samplecount = MIN(devc->max_samples / num_channels, devc->limit_samples);
+ samplecount = MIN(devc->max_samples / num_ols_changrp, devc->limit_samples);
readcount = samplecount / 4;
/* Rather read too many samples than too few. */
readcount++;
/* Basic triggers. */
- if (devc->trigger_mask[0] != 0x00000000) {
- /* At least one channel has a trigger on it. */
+ if (ols_convert_trigger(sdi) != SR_OK) {
+ sr_err("Failed to configure channels.");
+ return SR_ERR;
+ }
+ if (devc->num_stages > 0) {
delaycount = readcount * (1 - devc->capture_ratio / 100.0);
devc->trigger_at = (readcount - delaycount) * 4 - devc->num_stages;
for (i = 0; i <= devc->num_stages; i++) {
- sr_dbg("Setting stage %d trigger.", i);
+ sr_dbg("Setting OLS stage %d trigger.", i);
if ((ret = set_trigger(sdi, i)) != SR_OK)
return ret;
}
devc->flag_reg & FLAG_RLE ? "on" : "off",
devc->flag_reg & FLAG_FILTER ? "on": "off",
devc->flag_reg & FLAG_DEMUX ? "on" : "off");
- /* 1 means "disable channel". */
- devc->flag_reg |= ~(changrp_mask << 2) & 0x3c;
+ /*
+ * Enable/disable OLS channel groups in the flag register according
+ * to the channel mask. 1 means "disable channel".
+ */
+ devc->flag_reg |= ~(ols_changrp_mask << 2) & 0x3c;
arg[0] = devc->flag_reg & 0xff;
arg[1] = devc->flag_reg >> 8;
arg[2] = arg[3] = 0x00;
return SR_OK;
}
-SR_PRIV int ols_configure_channels(const struct sr_dev_inst *sdi)
+/* Configures the channel mask based on which channels are enabled. */
+SR_PRIV void ols_channel_mask(const struct sr_dev_inst *sdi)
{
struct dev_context *devc;
- const struct sr_channel *ch;
+ struct sr_channel *channel;
const GSList *l;
- int channel_bit, stage, i;
- char *tc;
devc = sdi->priv;
devc->channel_mask = 0;
+ for (l = sdi->channels; l; l = l->next) {
+ channel = l->data;
+ if (channel->enabled)
+ devc->channel_mask |= 1 << channel->index;
+ }
+}
+
+SR_PRIV int ols_convert_trigger(const struct sr_dev_inst *sdi)
+{
+ struct dev_context *devc;
+ struct sr_trigger *trigger;
+ struct sr_trigger_stage *stage;
+ struct sr_trigger_match *match;
+ const GSList *l, *m;
+ int i;
+
+ devc = sdi->priv;
+
+ devc->num_stages = 0;
for (i = 0; i < NUM_TRIGGER_STAGES; i++) {
devc->trigger_mask[i] = 0;
devc->trigger_value[i] = 0;
}
- devc->num_stages = 0;
- for (l = sdi->channels; l; l = l->next) {
- ch = (const struct sr_channel *)l->data;
- if (!ch->enabled)
- continue;
+ if (!(trigger = sr_session_trigger_get()))
+ return SR_OK;
- if (ch->index >= devc->max_channels) {
- sr_err("Channels over the limit of %d\n", devc->max_channels);
- return SR_ERR;
- }
+ devc->num_stages = g_slist_length(trigger->stages);
+ if (devc->num_stages > NUM_TRIGGER_STAGES) {
+ sr_err("This device only supports %d trigger stages.",
+ NUM_TRIGGER_STAGES);
+ return SR_ERR;
+ }
- /*
- * Set up the channel mask for later configuration into the
- * flag register.
- */
- channel_bit = 1 << (ch->index);
- devc->channel_mask |= channel_bit;
-
- if (!ch->trigger)
- continue;
-
- /* Configure trigger mask and value. */
- stage = 0;
- for (tc = ch->trigger; tc && *tc; tc++) {
- devc->trigger_mask[stage] |= channel_bit;
- if (*tc == '1')
- devc->trigger_value[stage] |= channel_bit;
- stage++;
- /* Only supporting parallel mode, with up to 4 stages. */
- if (stage > 4)
- return SR_ERR;
+ for (l = trigger->stages; l; l = l->next) {
+ stage = l->data;
+ for (m = stage->matches; m; m = m->next) {
+ match = m->data;
+ if (!match->channel->enabled)
+ /* Ignore disabled channels with a trigger. */
+ continue;
+ devc->trigger_mask[stage->stage] |= 1 << match->channel->index;
+ if (match->match == SR_TRIGGER_ONE)
+ devc->trigger_value[stage->stage] |= 1 << match->channel->index;
}
- if (stage > devc->num_stages)
- devc->num_stages = stage - 1;
}
return SR_OK;
struct sr_datafeed_packet packet;
struct sr_datafeed_logic logic;
uint32_t sample;
- int num_channels, offset, j;
+ int num_ols_changrp, offset, j;
unsigned int i;
unsigned char byte;
memset(devc->raw_sample_buf, 0x82, devc->limit_samples * 4);
}
- num_channels = 0;
+ num_ols_changrp = 0;
for (i = NUM_CHANNELS; i > 0x02; i /= 2) {
if ((devc->flag_reg & i) == 0) {
- num_channels++;
+ num_ols_changrp++;
}
}
devc->sample[devc->num_bytes++] = byte;
sr_spew("Received byte 0x%.2x.", byte);
- if (devc->num_bytes == num_channels) {
+ if (devc->num_bytes == num_ols_changrp) {
devc->cnt_samples++;
devc->cnt_samples_rle++;
/*
devc->num_samples = devc->limit_samples;
}
- if (num_channels < 4) {
+ if (num_ols_changrp < 4) {
/*
* Some channel groups may have been turned
* off, to speed up transfer between the
#define NUM_CHANNELS 32
#define NUM_TRIGGER_STAGES 4
-#define TRIGGER_TYPE "01"
#define SERIAL_SPEED B115200
#define CLOCK_RATE SR_MHZ(100)
#define MIN_NUM_SAMPLES 4
int capture_ratio;
int trigger_at;
uint32_t channel_mask;
- uint32_t trigger_mask[4];
- uint32_t trigger_value[4];
+ uint32_t trigger_mask[NUM_TRIGGER_STAGES];
+ uint32_t trigger_value[NUM_TRIGGER_STAGES];
int num_stages;
uint16_t flag_reg;
uint8_t command);
SR_PRIV int send_longcommand(struct sr_serial_dev_inst *serial,
uint8_t command, uint8_t *data);
-SR_PRIV int ols_configure_channels(const struct sr_dev_inst *sdi);
+SR_PRIV void ols_channel_mask(const struct sr_dev_inst *sdi);
+SR_PRIV int ols_convert_trigger(const struct sr_dev_inst *sdi);
SR_PRIV struct dev_context *ols_dev_new(void);
SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial);
SR_PRIV int ols_set_samplerate(const struct sr_dev_inst *sdi,