X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fdemo%2Fapi.c;h=3dd32433a5a503a37e81cb2c5e5db5d98218a5b4;hb=4d67b9d9dcfbb26f21b5092b79c10da8544e7df1;hp=8ffcfd93d08da939209ded164ca7a95dbdd34f53;hpb=7db9027985c2d59eccb0a20979bf5d7c699c8c8b;p=libsigrok.git diff --git a/src/hardware/demo/api.c b/src/hardware/demo/api.c index 8ffcfd93..3dd32433 100644 --- a/src/hardware/demo/api.c +++ b/src/hardware/demo/api.c @@ -29,17 +29,18 @@ #include "protocol.h" #define DEFAULT_NUM_LOGIC_CHANNELS 8 -#define DEFAULT_ENABLED_LOGIC_CHANNELS 8 #define DEFAULT_LOGIC_PATTERN PATTERN_SIGROK #define DEFAULT_NUM_ANALOG_CHANNELS 4 -#define DEFAULT_ENABLED_ANALOG_CHANNELS 4 #define DEFAULT_ANALOG_AMPLITUDE 10 +/* Note: No spaces allowed because of sigrok-cli. */ static const char *logic_pattern_str[] = { "sigrok", "random", "incremental", + "walking-one", + "walking-zero", "all-low", "all-high", "squid", @@ -95,7 +96,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) GSList *l; int num_logic_channels, num_analog_channels, pattern, i; char channel_name[16]; - gboolean enabled; num_logic_channels = DEFAULT_NUM_LOGIC_CHANNELS; num_analog_channels = DEFAULT_NUM_ANALOG_CHANNELS; @@ -128,14 +128,14 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) cg->name = g_strdup("Logic"); for (i = 0; i < num_logic_channels; i++) { sprintf(channel_name, "D%d", i); - enabled = (i < DEFAULT_ENABLED_LOGIC_CHANNELS) ? TRUE : FALSE; - ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, enabled, channel_name); + ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_name); cg->channels = g_slist_append(cg->channels, ch); } sdi->channel_groups = g_slist_append(NULL, cg); } /* Analog channels, channel groups and pattern generators. */ + devc->ch_ag = g_hash_table_new(g_direct_hash, g_direct_equal); if (num_analog_channels > 0) { pattern = 0; /* An "Analog" channel group with all analog channels in it. */ @@ -143,12 +143,10 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) acg->name = g_strdup("Analog"); sdi->channel_groups = g_slist_append(sdi->channel_groups, acg); - devc->ch_ag = g_hash_table_new(g_direct_hash, g_direct_equal); for (i = 0; i < num_analog_channels; i++) { snprintf(channel_name, 16, "A%d", i); - enabled = (i < DEFAULT_ENABLED_ANALOG_CHANNELS) ? TRUE : FALSE; ch = sr_channel_new(sdi, i + num_logic_channels, SR_CHANNEL_ANALOG, - enabled, channel_name); + TRUE, channel_name); acg->channels = g_slist_append(acg->channels, ch); /* Every analog channel gets its own channel group as well. */ @@ -159,6 +157,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) /* Every channel gets a generator struct. */ ag = g_malloc(sizeof(struct analog_gen)); + ag->ch = ch; ag->amplitude = DEFAULT_ANALOG_AMPLITUDE; sr_analog_init(&ag->packet, &ag->encoding, &ag->meaning, &ag->spec, 2); ag->packet.meaning->channels = cg->channels; @@ -181,20 +180,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) return std_scan_complete(di, g_slist_append(NULL, sdi)); } -static int dev_open(struct sr_dev_inst *sdi) -{ - sdi->status = SR_ST_ACTIVE; - - return SR_OK; -} - -static int dev_close(struct sr_dev_inst *sdi) -{ - sdi->status = SR_ST_INACTIVE; - - return SR_OK; -} - static void clear_helper(void *priv) { struct dev_context *devc; @@ -289,9 +274,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: @@ -458,15 +440,59 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * 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) { + ch = l->data; + if (!ch->enabled) + continue; + if (ch->type == SR_CHANNEL_ANALOG) { + devc->enabled_analog_channels++; + continue; + } + 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("num logic %zu, partial off %zu, mask 0x%02x.", + 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); @@ -486,7 +512,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); @@ -505,8 +530,8 @@ static struct sr_dev_driver demo_driver_info = { .config_get = config_get, .config_set = config_set, .config_list = config_list, - .dev_open = dev_open, - .dev_close = dev_close, + .dev_open = std_dummy_dev_open, + .dev_close = std_dummy_dev_close, .dev_acquisition_start = dev_acquisition_start, .dev_acquisition_stop = dev_acquisition_stop, .context = NULL,