X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fdemo%2Fapi.c;h=0dd0a38a6b65e4b6c9c73307f32a5e3dd25186f0;hb=f1ba6b4b2c9a8ecf90bb31efb218752aa7e49d1a;hp=92b59fe3a32f07751111e5135b82c408c3fc3c3d;hpb=1b7b72d49e5ce19593ca4b2a793bec441b4cdea4;p=libsigrok.git diff --git a/src/hardware/demo/api.c b/src/hardware/demo/api.c index 92b59fe3..0dd0a38a 100644 --- a/src/hardware/demo/api.c +++ b/src/hardware/demo/api.c @@ -182,14 +182,14 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) static int dev_open(struct sr_dev_inst *sdi) { - sdi->status = SR_ST_ACTIVE; + (void)sdi; return SR_OK; } static int dev_close(struct sr_dev_inst *sdi) { - sdi->status = SR_ST_INACTIVE; + (void)sdi; return SR_OK; } @@ -288,9 +288,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd devc = sdi->priv; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - ret = SR_OK; switch (key) { case SR_CONF_SAMPLERATE: @@ -459,15 +456,19 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct dev_context *devc; GSList *l; struct sr_channel *ch; + int bitpos; + uint8_t mask; GHashTableIter iter; void *value; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; devc->sent_samples = 0; + /* + * Determine the numbers of logic and analog channels that are + * involved in the acquisition. Determine an offset and a mask to + * remove excess logic data content before datafeed submission. + */ devc->enabled_logic_channels = 0; devc->enabled_analog_channels = 0; for (l = sdi->channels; l; l = l->next) { @@ -478,12 +479,34 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) devc->enabled_analog_channels++; continue; } - if (ch->type == SR_CHANNEL_LOGIC) { - devc->enabled_logic_channels++; + if (ch->type != SR_CHANNEL_LOGIC) continue; - } + /* + * TODO: Need we create a channel map here, such that the + * session datafeed packets will have a dense representation + * of the enabled channels' data? For example store channels + * D3 and D5 in bit positions 0 and 1 respectively, when all + * other channels are disabled? The current implementation + * generates a sparse layout, might provide data for logic + * channels that are disabled while it might suppress data + * from enabled channels at the same time. + */ + devc->enabled_logic_channels++; } - + devc->first_partial_logic_index = devc->enabled_logic_channels / 8; + bitpos = devc->enabled_logic_channels % 8; + mask = (1 << bitpos) - 1; + devc->first_partial_logic_mask = mask; + sr_dbg("DBG: %s(), num logic %zu, partial off %zu, mask 0x%02x", + __func__, devc->enabled_logic_channels, + devc->first_partial_logic_index, + devc->first_partial_logic_mask); + + /* + * Have the waveform for analog patterns pre-generated. It's + * supposed to be periodic, so the generator just needs to + * access the prepared sample data (DDS style). + */ g_hash_table_iter_init(&iter, devc->ch_ag); while (g_hash_table_iter_next(&iter, NULL, &value)) demo_generate_analog_pattern(value, devc->cur_samplerate); @@ -503,7 +526,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - sr_dbg("Stopping acquisition."); sr_session_source_remove(sdi->session, -1); std_session_send_df_end(sdi);