Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OLS Improvements #51

Draft
wants to merge 20 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 54 additions & 33 deletions src/hardware/openbench-logic-sniffer/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,22 @@ static const uint32_t devopts[] = {
SR_CONF_RLE | SR_CONF_GET | SR_CONF_SET,
};

static const int32_t trigger_matches[] = {
static const int32_t basic_trigger_matches[] = {
SR_TRIGGER_ZERO,
SR_TRIGGER_ONE,
};

static const char* external_clock_edges[] = {
"rising", // positive edge
"falling" // negative edge
static const int32_t advanced_trigger_matches[] = {
SR_TRIGGER_ZERO,
SR_TRIGGER_ONE,
SR_TRIGGER_RISING,
SR_TRIGGER_FALLING,
SR_TRIGGER_EDGE,
};

static const char *external_clock_edges[] = {
"rising", /* positive edge */
"falling" /* negative edge */
};

v1ne marked this conversation as resolved.
Show resolved Hide resolved
#define STR_PATTERN_NONE "None"
Expand Down Expand Up @@ -146,7 +154,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
return NULL;
}

num_read = serial_read_blocking(serial, buf, 4, serial_timeout(serial, 4));
num_read =
serial_read_blocking(serial, buf, 4, serial_timeout(serial, 4));
if (num_read < 0) {
sr_err("Getting ID reply failed (%d).", num_read);
return NULL;
Expand Down Expand Up @@ -181,13 +190,13 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->version = g_strdup("v1.0");
for (i = 0; i < ARRAY_SIZE(ols_channel_names); i++)
sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE,
ols_channel_names[i]);
ols_channel_names[i]);
sdi->priv = ols_dev_new();
}
/* Configure samplerate and divider. */
if (ols_set_samplerate(sdi, DEFAULT_SAMPLERATE) != SR_OK)
sr_dbg("Failed to set default samplerate (%"PRIu64").",
DEFAULT_SAMPLERATE);
sr_dbg("Failed to set default samplerate (%" PRIu64 ").",
DEFAULT_SAMPLERATE);
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;

Expand All @@ -197,7 +206,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
}

static int config_get(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
struct dev_context *devc;

Expand Down Expand Up @@ -227,15 +237,18 @@ static int config_get(uint32_t key, GVariant **data,
*data = g_variant_new_string(STR_PATTERN_NONE);
break;
case SR_CONF_RLE:
*data = g_variant_new_boolean(devc->capture_flags & CAPTURE_FLAG_RLE ? TRUE : FALSE);
*data = g_variant_new_boolean(
devc->capture_flags & CAPTURE_FLAG_RLE ? TRUE : FALSE);
break;
case SR_CONF_EXTERNAL_CLOCK:
*data = g_variant_new_boolean(
devc->capture_flags & CAPTURE_FLAG_CLOCK_EXTERNAL ? TRUE : FALSE);
devc->capture_flags & CAPTURE_FLAG_CLOCK_EXTERNAL
? TRUE : FALSE);
break;
case SR_CONF_CLOCK_EDGE:
*data = g_variant_new_string(external_clock_edges[
devc->capture_flags & CAPTURE_FLAG_INVERT_EXT_CLOCK ? 1 : 0]);
devc->capture_flags & CAPTURE_FLAG_INVERT_EXT_CLOCK
? 1 : 0]);
break;
default:
return SR_ERR_NA;
Expand All @@ -245,7 +258,8 @@ static int config_get(uint32_t key, GVariant **data,
}

static int config_set(uint32_t key, GVariant *data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
struct dev_context *devc;
uint16_t flag;
Expand Down Expand Up @@ -334,20 +348,27 @@ static int config_set(uint32_t key, GVariant *data,
}

static int config_list(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
struct dev_context *devc;
struct dev_context *devc = sdi ? sdi->priv : NULL;
int num_ols_changrp, i;

switch (key) {
case SR_CONF_SCAN_OPTIONS:
case SR_CONF_DEVICE_OPTIONS:
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts,
devopts);
case SR_CONF_SAMPLERATE:
*data = std_gvar_samplerates_steps(ARRAY_AND_SIZE(samplerates));
break;
case SR_CONF_TRIGGER_MATCH:
*data = std_gvar_array_i32(ARRAY_AND_SIZE(trigger_matches));
if (!devc)
return SR_ERR_ARG;
/* Advanced Triggering is only available on the Demon Core. */
*data = devc->device_flags & DEVICE_FLAG_IS_DEMON_CORE
? std_gvar_array_i32(ARRAY_AND_SIZE(advanced_trigger_matches))
: std_gvar_array_i32(ARRAY_AND_SIZE(basic_trigger_matches));
break;
case SR_CONF_CLOCK_EDGE:
*data = std_gvar_array_str(ARRAY_AND_SIZE(external_clock_edges));
Expand All @@ -356,11 +377,8 @@ static int config_list(uint32_t key, GVariant **data,
*data = g_variant_new_strv(ARRAY_AND_SIZE(patterns));
break;
case SR_CONF_LIMIT_SAMPLES:
if (!sdi)
if (!devc)
return SR_ERR_ARG;
devc = sdi->priv;
if (devc->capture_flags & CAPTURE_FLAG_RLE)
return SR_ERR_NA;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me!

if (devc->max_samples == 0)
/* Device didn't specify sample memory size in metadata. */
return SR_ERR_NA;
Expand All @@ -375,8 +393,8 @@ static int config_list(uint32_t key, GVariant **data,
num_ols_changrp++;
}

*data = std_gvar_tuple_u64(MIN_NUM_SAMPLES,
(num_ols_changrp) ? devc->max_samples / num_ols_changrp : MIN_NUM_SAMPLES);
*data = std_gvar_tuple_u64(MIN_NUM_SAMPLES, (num_ols_changrp)
? devc->max_samples / num_ols_changrp : MIN_NUM_SAMPLES);
break;
default:
return SR_ERR_NA;
Expand All @@ -399,24 +417,27 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
return ret;

/* Start acquisition on the device. */
if (send_shortcommand(serial, CMD_ARM_BASIC_TRIGGER) != SR_OK)
if (send_shortcommand(serial,
devc->device_flags & DEVICE_FLAG_IS_DEMON_CORE ?
CMD_ARM_ADVANCED_TRIGGER :
CMD_ARM_BASIC_TRIGGER) != SR_OK)
return SR_ERR;

/* Reset all operational states. */
devc->rle_count = devc->num_transfers = 0;
devc->num_samples = devc->num_bytes = 0;
devc->cnt_bytes = devc->cnt_samples = devc->cnt_samples_rle = 0;
memset(devc->sample, 0, 4);
devc->rle_count = 0;
devc->trigger_rle_at_smpl_from_end = OLS_NO_TRIGGER;
devc->cnt_samples = devc->raw_sample_size = 0;
devc->cnt_rx_bytes = devc->cnt_rx_raw_samples = 0;
memset(devc->raw_sample, 0, 4);

std_session_send_df_header(sdi);

/* If the device stops sending for longer than it takes to send a byte,
* that means it's finished. But wait at least 100 ms to be safe.
* that means it's finished. Since the device can be used over a slow
* network link, give it 10 seconds to reply.
*/
serial_source_add(sdi->session, serial, G_IO_IN, 100,
ols_receive_data, (struct sr_dev_inst *)sdi);

return SR_OK;
return serial_source_add(sdi->session, serial, G_IO_IN, 10 * 1000,
ols_receive_data, (struct sr_dev_inst *)sdi);
}

static int dev_acquisition_stop(struct sr_dev_inst *sdi)
Expand Down
Loading