From: Daniel Elstner Date: Sun, 30 Aug 2015 16:20:41 +0000 (+0200) Subject: sysclk-lwla: Streamline trigger setup logic X-Git-Tag: libsigrok-0.4.0~284 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=225d3cb0c52fc3df5b26fec94d3b3d2de796a41c;p=libsigrok.git sysclk-lwla: Streamline trigger setup logic Prepare the trigger masks at config_commit() time, so that the trigger setup can be validated before starting an acquisition. Accordingly, do actually report validation errors back to the caller. --- diff --git a/src/hardware/sysclk-lwla/api.c b/src/hardware/sysclk-lwla/api.c index 98b1b7c6..928bab75 100644 --- a/src/hardware/sysclk-lwla/api.c +++ b/src/hardware/sysclk-lwla/api.c @@ -413,12 +413,84 @@ static int config_channel_set(const struct sr_dev_inst *sdi, return SR_OK; } +static int prepare_trigger_masks(const struct sr_dev_inst *sdi) +{ + uint64_t trigger_mask; + uint64_t trigger_values; + uint64_t trigger_edge_mask; + uint64_t channel_bit; + struct dev_context *devc; + struct sr_trigger *trigger; + struct sr_trigger_stage *stage; + struct sr_trigger_match *match; + const GSList *node; + + devc = sdi->priv; + + trigger = sr_session_trigger_get(sdi->session); + if (!trigger || !trigger->stages) + return SR_OK; + + if (trigger->stages->next) { + sr_err("This device only supports 1 trigger stage."); + return SR_ERR_ARG; + } + stage = trigger->stages->data; + + trigger_mask = 0; + trigger_values = 0; + trigger_edge_mask = 0; + + for (node = stage->matches; node; node = node->next) { + match = node->data; + + if (!match->channel->enabled) + continue; /* ignore disabled channel */ + + channel_bit = (uint64_t)1 << match->channel->index; + trigger_mask |= channel_bit; + + switch (match->match) { + case SR_TRIGGER_ZERO: + break; + case SR_TRIGGER_ONE: + trigger_values |= channel_bit; + break; + case SR_TRIGGER_RISING: + trigger_values |= channel_bit; + /* Fall through for edge mask. */ + case SR_TRIGGER_FALLING: + trigger_edge_mask |= channel_bit; + break; + default: + sr_err("Unsupported trigger match for CH%d.", + match->channel->index + 1); + return SR_ERR_ARG; + } + } + devc->trigger_mask = trigger_mask; + devc->trigger_values = trigger_values; + devc->trigger_edge_mask = trigger_edge_mask; + + return SR_OK; +} + static int config_commit(const struct sr_dev_inst *sdi) { - if (sdi->status != SR_ST_ACTIVE) { - sr_err("Device not ready (status %d).", (int)sdi->status); + struct dev_context *devc; + int rc; + + if (sdi->status != SR_ST_ACTIVE) + return SR_ERR_DEV_CLOSED; + + devc = sdi->priv; + if (devc->acquisition) { + sr_err("Acquisition still in progress?"); return SR_ERR; } + rc = prepare_trigger_masks(sdi); + if (rc != SR_OK) + return rc; return lwla_set_clock_config(sdi); } @@ -499,7 +571,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) sr_info("Starting acquisition."); devc->acquisition = acq; - lwla_convert_trigger(sdi); ret = lwla_setup_acquisition(sdi); if (ret != SR_OK) { sr_err("Failed to set up acquisition."); diff --git a/src/hardware/sysclk-lwla/protocol.c b/src/hardware/sysclk-lwla/protocol.c index ccabdddf..c00a92fd 100644 --- a/src/hardware/sysclk-lwla/protocol.c +++ b/src/hardware/sysclk-lwla/protocol.c @@ -110,10 +110,10 @@ static int capture_setup(const struct sr_dev_inst *sdi) switch (devc->cfg_trigger_slope) { case EDGE_POSITIVE: trigger_mask |= (uint64_t)1 << 35; - break; + break; case EDGE_NEGATIVE: trigger_mask |= (uint64_t)1 << 34; - break; + break; } command[19] = LWLA_WORD_0(trigger_mask); @@ -132,8 +132,8 @@ static int capture_setup(const struct sr_dev_inst *sdi) command[25] = LWLA_WORD_2(memory_limit); command[26] = LWLA_WORD_3(memory_limit); - /* Fill remaining 64-bit words with zeroes. */ - memset(&command[27], 0, 16 * sizeof(uint16_t)); + /* Fill remaining words with zeroes. */ + memset(&command[27], 0, sizeof(command) - 27 * sizeof(command[0])); return lwla_send_command(sdi->conn, command, ARRAY_SIZE(command)); } @@ -743,55 +743,6 @@ SR_PRIV int lwla_init_device(const struct sr_dev_inst *sdi) return ret; } -SR_PRIV int lwla_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; - uint64_t channel_index; - - devc = sdi->priv; - - devc->trigger_mask = 0; - devc->trigger_values = 0; - devc->trigger_edge_mask = 0; - - if (!(trigger = sr_session_trigger_get(sdi->session))) - return SR_OK; - - if (g_slist_length(trigger->stages) > 1) { - sr_err("This device only supports 1 trigger stage."); - 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; - channel_index = (uint64_t)1 << match->channel->index; - devc->trigger_mask |= channel_index; - switch (match->match) { - case SR_TRIGGER_ONE: - devc->trigger_values |= channel_index; - break; - case SR_TRIGGER_RISING: - devc->trigger_values |= channel_index; - /* Fall through for edge mask. */ - case SR_TRIGGER_FALLING: - devc->trigger_edge_mask |= channel_index; - break; - } - } - } - - return SR_OK; -} - /* Select the LWLA clock configuration. If the clock source changed from * the previous setting, this will download a new bitstream to the FPGA. */ diff --git a/src/hardware/sysclk-lwla/protocol.h b/src/hardware/sysclk-lwla/protocol.h index 25f349d1..61ed4c5f 100644 --- a/src/hardware/sysclk-lwla/protocol.h +++ b/src/hardware/sysclk-lwla/protocol.h @@ -252,7 +252,6 @@ SR_PRIV struct acquisition_state *lwla_alloc_acquisition_state(void); SR_PRIV void lwla_free_acquisition_state(struct acquisition_state *acq); SR_PRIV int lwla_init_device(const struct sr_dev_inst *sdi); -SR_PRIV int lwla_convert_trigger(const struct sr_dev_inst *sdi); SR_PRIV int lwla_set_clock_config(const struct sr_dev_inst *sdi); SR_PRIV int lwla_setup_acquisition(const struct sr_dev_inst *sdi); SR_PRIV int lwla_start_acquisition(const struct sr_dev_inst *sdi);