From: Bert Vermeulen Date: Tue, 27 May 2014 22:21:45 +0000 (+0200) Subject: ols: Use new trigger API. X-Git-Tag: libsigrok-0.4.0~1302 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=91fd0f7246b2cfe7adbdcd8c8cdefe89b6607afb;p=libsigrok.git ols: Use new trigger API. --- diff --git a/hardware/openbench-logic-sniffer/api.c b/hardware/openbench-logic-sniffer/api.c index b99d8e72..47a938b0 100644 --- a/hardware/openbench-logic-sniffer/api.c +++ b/hardware/openbench-logic-sniffer/api.c @@ -30,7 +30,7 @@ static const int32_t hwopts[] = { 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, @@ -39,6 +39,11 @@ static const int32_t hwcaps[] = { 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" @@ -189,8 +194,6 @@ static GSList *scan(GSList *options) 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; @@ -354,7 +357,7 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, struct dev_context *devc; GVariant *gvar, *grange[2]; GVariantBuilder gvb; - int num_channels, i; + int num_ols_changrp, i; (void)cg; @@ -374,8 +377,10 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, 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)); @@ -393,20 +398,17 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, * 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: @@ -459,8 +461,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, 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) @@ -469,22 +471,14 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, 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++; } } @@ -492,7 +486,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, * 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. */ @@ -500,12 +494,15 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, 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; } @@ -544,8 +541,11 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, 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; diff --git a/hardware/openbench-logic-sniffer/protocol.c b/hardware/openbench-logic-sniffer/protocol.c index 45304473..e9d17963 100644 --- a/hardware/openbench-logic-sniffer/protocol.c +++ b/hardware/openbench-logic-sniffer/protocol.c @@ -54,56 +54,61 @@ SR_PRIV int send_longcommand(struct sr_serial_dev_inst *serial, 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; @@ -328,7 +333,7 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data) 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; @@ -356,10 +361,10 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data) 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++; } } @@ -374,7 +379,7 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data) 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++; /* @@ -407,7 +412,7 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data) 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 diff --git a/hardware/openbench-logic-sniffer/protocol.h b/hardware/openbench-logic-sniffer/protocol.h index 98831b58..c0f101dc 100644 --- a/hardware/openbench-logic-sniffer/protocol.h +++ b/hardware/openbench-logic-sniffer/protocol.h @@ -30,7 +30,6 @@ #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 @@ -82,8 +81,8 @@ struct dev_context { 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; @@ -109,7 +108,8 @@ SR_PRIV int send_shortcommand(struct sr_serial_dev_inst *serial, 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,