From 3a1125401fc3f28e8f80779c3f29261aed83181f Mon Sep 17 00:00:00 2001 From: v1ne Date: Tue, 31 Mar 2020 18:48:05 +0200 Subject: [PATCH 1/8] Clean up OLS: Make use of zero-initialization, move comments to declaration --- src/hardware/openbench-logic-sniffer/protocol.c | 7 ------- src/hardware/openbench-logic-sniffer/protocol.h | 2 ++ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/hardware/openbench-logic-sniffer/protocol.c b/src/hardware/openbench-logic-sniffer/protocol.c index 7be70b3da..36a091c73 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.c +++ b/src/hardware/openbench-logic-sniffer/protocol.c @@ -134,14 +134,7 @@ SR_PRIV struct dev_context *ols_dev_new(void) struct dev_context *devc; devc = g_malloc0(sizeof(struct dev_context)); - - /* Device-specific settings */ - devc->max_samples = devc->max_samplerate = devc->protocol_version = 0; - - /* Acquisition settings */ - devc->limit_samples = devc->capture_ratio = 0; devc->trigger_at = -1; - devc->flag_reg = 0; return devc; } diff --git a/src/hardware/openbench-logic-sniffer/protocol.h b/src/hardware/openbench-logic-sniffer/protocol.h index 7bcaed1f6..873b3d8fb 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.h +++ b/src/hardware/openbench-logic-sniffer/protocol.h @@ -67,11 +67,13 @@ #define FLAG_DEMUX (1 << 0) struct dev_context { + /* constant device properties: */ int max_channels; uint32_t max_samples; uint32_t max_samplerate; uint32_t protocol_version; + /* acquisition-related properties: */ uint64_t cur_samplerate; uint32_t cur_samplerate_divider; uint64_t limit_samples; From 4921d76302ed9f7bc78f5787d0be2e4d1c009192 Mon Sep 17 00:00:00 2001 From: v1ne Date: Tue, 31 Mar 2020 21:38:38 +0200 Subject: [PATCH 2/8] Clean up OLS: Remove stray command It's nowhere documented and nowhere used. --- src/hardware/openbench-logic-sniffer/protocol.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/hardware/openbench-logic-sniffer/protocol.h b/src/hardware/openbench-logic-sniffer/protocol.h index 873b3d8fb..eb7478c56 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.h +++ b/src/hardware/openbench-logic-sniffer/protocol.h @@ -37,7 +37,6 @@ #define CMD_RESET 0x00 #define CMD_RUN 0x01 #define CMD_ID 0x02 -#define CMD_TESTMODE 0x03 #define CMD_METADATA 0x04 #define CMD_SET_DIVIDER 0x80 #define CMD_CAPTURE_SIZE 0x81 From 9d1b3944926e8dbef3c5c6c9776d99ccbaac0faa Mon Sep 17 00:00:00 2001 From: v1ne Date: Tue, 31 Mar 2020 18:48:30 +0200 Subject: [PATCH 3/8] Clean up OLS: Be more specific about magic values and units in variable names --- src/hardware/openbench-logic-sniffer/api.c | 2 +- src/hardware/openbench-logic-sniffer/protocol.c | 12 ++++++------ src/hardware/openbench-logic-sniffer/protocol.h | 5 ++++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/hardware/openbench-logic-sniffer/api.c b/src/hardware/openbench-logic-sniffer/api.c index 5cf415df8..c8915fbbe 100644 --- a/src/hardware/openbench-logic-sniffer/api.c +++ b/src/hardware/openbench-logic-sniffer/api.c @@ -440,7 +440,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) return SR_ERR; delaycount = readcount * (1 - devc->capture_ratio / 100.0); - devc->trigger_at = (readcount - delaycount) * 4 - devc->num_stages; + devc->trigger_at_smpl = (readcount - delaycount) * 4 - devc->num_stages; for (i = 0; i <= devc->num_stages; i++) { sr_dbg("Setting OLS stage %d trigger.", i); if ((ret = set_trigger(sdi, i)) != SR_OK) diff --git a/src/hardware/openbench-logic-sniffer/protocol.c b/src/hardware/openbench-logic-sniffer/protocol.c index 36a091c73..a1b168062 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.c +++ b/src/hardware/openbench-logic-sniffer/protocol.c @@ -134,7 +134,7 @@ SR_PRIV struct dev_context *ols_dev_new(void) struct dev_context *devc; devc = g_malloc0(sizeof(struct dev_context)); - devc->trigger_at = -1; + devc->trigger_at_smpl = OLS_NO_TRIGGER; return devc; } @@ -491,16 +491,16 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data) sr_dbg("Received %d bytes, %d samples, %d decompressed samples.", devc->cnt_bytes, devc->cnt_samples, devc->cnt_samples_rle); - if (devc->trigger_at != -1) { + if (devc->trigger_at_smpl != OLS_NO_TRIGGER) { /* * A trigger was set up, so we need to tell the frontend * about it. */ - if (devc->trigger_at > 0) { + if (devc->trigger_at_smpl > 0) { /* There are pre-trigger samples, send those first. */ packet.type = SR_DF_LOGIC; packet.payload = &logic; - logic.length = devc->trigger_at * 4; + logic.length = devc->trigger_at_smpl * 4; logic.unitsize = 4; logic.data = devc->raw_sample_buf + (devc->limit_samples - devc->num_samples) * 4; @@ -513,9 +513,9 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data) /* Send post-trigger samples. */ packet.type = SR_DF_LOGIC; packet.payload = &logic; - logic.length = (devc->num_samples * 4) - (devc->trigger_at * 4); + logic.length = (devc->num_samples * 4) - (devc->trigger_at_smpl * 4); logic.unitsize = 4; - logic.data = devc->raw_sample_buf + devc->trigger_at * 4 + + logic.data = devc->raw_sample_buf + devc->trigger_at_smpl * 4 + (devc->limit_samples - devc->num_samples) * 4; sr_session_send(sdi, &packet); } else { diff --git a/src/hardware/openbench-logic-sniffer/protocol.h b/src/hardware/openbench-logic-sniffer/protocol.h index eb7478c56..2303c3fd2 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.h +++ b/src/hardware/openbench-logic-sniffer/protocol.h @@ -65,6 +65,9 @@ #define FLAG_FILTER (1 << 1) #define FLAG_DEMUX (1 << 0) +/* Capture context magic numbers */ +#define OLS_NO_TRIGGER (-1) + struct dev_context { /* constant device properties: */ int max_channels; @@ -77,7 +80,7 @@ struct dev_context { uint32_t cur_samplerate_divider; uint64_t limit_samples; uint64_t capture_ratio; - int trigger_at; + int trigger_at_smpl; uint32_t channel_mask; uint32_t trigger_mask[NUM_TRIGGER_STAGES]; uint32_t trigger_value[NUM_TRIGGER_STAGES]; From 088f0c75dd0b65e1f5dee43189e780a28aac015b Mon Sep 17 00:00:00 2001 From: v1ne Date: Tue, 31 Mar 2020 19:32:23 +0200 Subject: [PATCH 4/8] Clean up OLS: Rename "flags" to "capture flags". It's only about capture. This is a preparation to introduce "device flags" later that describe the device itself, not a specific operation. --- src/hardware/openbench-logic-sniffer/api.c | 46 +++++++++---------- .../openbench-logic-sniffer/protocol.c | 18 ++++---- .../openbench-logic-sniffer/protocol.h | 28 +++++------ 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/hardware/openbench-logic-sniffer/api.c b/src/hardware/openbench-logic-sniffer/api.c index c8915fbbe..3e632b475 100644 --- a/src/hardware/openbench-logic-sniffer/api.c +++ b/src/hardware/openbench-logic-sniffer/api.c @@ -213,15 +213,15 @@ static int config_get(uint32_t key, GVariant **data, *data = g_variant_new_uint64(devc->limit_samples); break; case SR_CONF_PATTERN_MODE: - if (devc->flag_reg & FLAG_EXTERNAL_TEST_MODE) + if (devc->capture_flags & CAPTURE_FLAG_EXTERNAL_TEST_MODE) *data = g_variant_new_string(STR_PATTERN_EXTERNAL); - else if (devc->flag_reg & FLAG_INTERNAL_TEST_MODE) + else if (devc->capture_flags & CAPTURE_FLAG_INTERNAL_TEST_MODE) *data = g_variant_new_string(STR_PATTERN_INTERNAL); else *data = g_variant_new_string(STR_PATTERN_NONE); break; case SR_CONF_RLE: - *data = g_variant_new_boolean(devc->flag_reg & FLAG_RLE ? TRUE : FALSE); + *data = g_variant_new_boolean(devc->capture_flags & CAPTURE_FLAG_RLE ? TRUE : FALSE); break; default: return SR_ERR_NA; @@ -260,10 +260,10 @@ static int config_set(uint32_t key, GVariant *data, case SR_CONF_EXTERNAL_CLOCK: if (g_variant_get_boolean(data)) { sr_info("Enabling external clock."); - devc->flag_reg |= FLAG_CLOCK_EXTERNAL; + devc->capture_flags |= CAPTURE_FLAG_CLOCK_EXTERNAL; } else { sr_info("Disabled external clock."); - devc->flag_reg &= ~FLAG_CLOCK_EXTERNAL; + devc->capture_flags &= ~CAPTURE_FLAG_CLOCK_EXTERNAL; } break; case SR_CONF_PATTERN_MODE: @@ -273,33 +273,33 @@ static int config_set(uint32_t key, GVariant *data, flag = 0x0000; } else if (!strcmp(stropt, STR_PATTERN_INTERNAL)) { sr_info("Enabling internal test mode."); - flag = FLAG_INTERNAL_TEST_MODE; + flag = CAPTURE_FLAG_INTERNAL_TEST_MODE; } else if (!strcmp(stropt, STR_PATTERN_EXTERNAL)) { sr_info("Enabling external test mode."); - flag = FLAG_EXTERNAL_TEST_MODE; + flag = CAPTURE_FLAG_EXTERNAL_TEST_MODE; } else { return SR_ERR; } - devc->flag_reg &= ~FLAG_INTERNAL_TEST_MODE; - devc->flag_reg &= ~FLAG_EXTERNAL_TEST_MODE; - devc->flag_reg |= flag; + devc->capture_flags &= ~CAPTURE_FLAG_INTERNAL_TEST_MODE; + devc->capture_flags &= ~CAPTURE_FLAG_EXTERNAL_TEST_MODE; + devc->capture_flags |= flag; break; case SR_CONF_SWAP: if (g_variant_get_boolean(data)) { sr_info("Enabling channel swapping."); - devc->flag_reg |= FLAG_SWAP_CHANNELS; + devc->capture_flags |= CAPTURE_FLAG_SWAP_CHANNELS; } else { sr_info("Disabling channel swapping."); - devc->flag_reg &= ~FLAG_SWAP_CHANNELS; + devc->capture_flags &= ~CAPTURE_FLAG_SWAP_CHANNELS; } break; case SR_CONF_RLE: if (g_variant_get_boolean(data)) { sr_info("Enabling RLE."); - devc->flag_reg |= FLAG_RLE; + devc->capture_flags |= CAPTURE_FLAG_RLE; } else { sr_info("Disabling RLE."); - devc->flag_reg &= ~FLAG_RLE; + devc->capture_flags &= ~CAPTURE_FLAG_RLE; } break; default: @@ -332,7 +332,7 @@ static int config_list(uint32_t key, GVariant **data, if (!sdi) return SR_ERR_ARG; devc = sdi->priv; - if (devc->flag_reg & FLAG_RLE) + if (devc->capture_flags & CAPTURE_FLAG_RLE) return SR_ERR_NA; if (devc->max_samples == 0) /* Device didn't specify sample memory size in metadata. */ @@ -492,18 +492,18 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) /* Flag register. */ sr_dbg("Setting intpat %s, extpat %s, RLE %s, noise_filter %s, demux %s", - devc->flag_reg & FLAG_INTERNAL_TEST_MODE ? "on": "off", - devc->flag_reg & FLAG_EXTERNAL_TEST_MODE ? "on": "off", - devc->flag_reg & FLAG_RLE ? "on" : "off", - devc->flag_reg & FLAG_FILTER ? "on": "off", - devc->flag_reg & FLAG_DEMUX ? "on" : "off"); + devc->capture_flags & CAPTURE_FLAG_INTERNAL_TEST_MODE ? "on": "off", + devc->capture_flags & CAPTURE_FLAG_EXTERNAL_TEST_MODE ? "on": "off", + devc->capture_flags & CAPTURE_FLAG_RLE ? "on" : "off", + devc->capture_flags & CAPTURE_FLAG_NOISE_FILTER ? "on": "off", + devc->capture_flags & CAPTURE_FLAG_DEMUX ? "on" : "off"); /* * 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; + devc->capture_flags |= ~(ols_changrp_mask << 2) & 0x3c; + arg[0] = devc->capture_flags & 0xff; + arg[1] = devc->capture_flags >> 8; arg[2] = arg[3] = 0x00; if (send_longcommand(serial, CMD_SET_FLAGS, arg) != SR_OK) return SR_ERR; diff --git a/src/hardware/openbench-logic-sniffer/protocol.c b/src/hardware/openbench-logic-sniffer/protocol.c index a1b168062..0a2bc4dd6 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.c +++ b/src/hardware/openbench-logic-sniffer/protocol.c @@ -322,13 +322,13 @@ SR_PRIV int ols_set_samplerate(const struct sr_dev_inst *sdi, if (samplerate > CLOCK_RATE) { sr_info("Enabling demux mode."); - devc->flag_reg |= FLAG_DEMUX; - devc->flag_reg &= ~FLAG_FILTER; + devc->capture_flags |= CAPTURE_FLAG_DEMUX; + devc->capture_flags &= ~CAPTURE_FLAG_NOISE_FILTER; devc->cur_samplerate_divider = (CLOCK_RATE * 2 / samplerate) - 1; } else { sr_info("Disabling demux mode."); - devc->flag_reg &= ~FLAG_DEMUX; - devc->flag_reg |= FLAG_FILTER; + devc->capture_flags &= ~CAPTURE_FLAG_DEMUX; + devc->capture_flags |= CAPTURE_FLAG_NOISE_FILTER; devc->cur_samplerate_divider = (CLOCK_RATE / samplerate) - 1; } @@ -336,7 +336,7 @@ SR_PRIV int ols_set_samplerate(const struct sr_dev_inst *sdi, * from the requested. */ devc->cur_samplerate = CLOCK_RATE / (devc->cur_samplerate_divider + 1); - if (devc->flag_reg & FLAG_DEMUX) + if (devc->capture_flags & CAPTURE_FLAG_DEMUX) devc->cur_samplerate *= 2; if (devc->cur_samplerate != samplerate) sr_info("Can't match samplerate %" PRIu64 ", using %" @@ -390,7 +390,7 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data) num_ols_changrp = 0; for (i = 0x20; i > 0x02; i >>= 1) { - if ((devc->flag_reg & i) == 0) { + if ((devc->capture_flags & i) == 0) { num_ols_changrp++; } } @@ -416,7 +416,7 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data) sample = devc->sample[0] | (devc->sample[1] << 8) \ | (devc->sample[2] << 16) | (devc->sample[3] << 24); sr_dbg("Received sample 0x%.*x.", devc->num_bytes * 2, sample); - if (devc->flag_reg & FLAG_RLE) { + if (devc->capture_flags & CAPTURE_FLAG_RLE) { /* * In RLE mode the high bit of the sample is the * "count" flag, meaning this sample is the number @@ -452,14 +452,14 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data) j = 0; memset(devc->tmp_sample, 0, 4); for (i = 0; i < 4; i++) { - if (((devc->flag_reg >> 2) & (1 << i)) == 0) { + if (((devc->capture_flags >> 2) & (1 << i)) == 0) { /* * This channel group was * enabled, copy from received * sample. */ devc->tmp_sample[i] = devc->sample[j++]; - } else if (devc->flag_reg & FLAG_DEMUX && (i > 2)) { + } else if (devc->capture_flags & CAPTURE_FLAG_DEMUX && (i > 2)) { /* group 2 & 3 get added to 0 & 1 */ devc->tmp_sample[i - 2] = devc->sample[j++]; } diff --git a/src/hardware/openbench-logic-sniffer/protocol.h b/src/hardware/openbench-logic-sniffer/protocol.h index 2303c3fd2..fa78ca79a 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.h +++ b/src/hardware/openbench-logic-sniffer/protocol.h @@ -50,20 +50,20 @@ /* Trigger config */ #define TRIGGER_START (1 << 3) -/* Bitmasks for CMD_FLAGS */ +/* Bitmasks for capture_flags */ /* 12-13 unused, 14-15 RLE mode (we hardcode mode 0). */ -#define FLAG_INTERNAL_TEST_MODE (1 << 11) -#define FLAG_EXTERNAL_TEST_MODE (1 << 10) -#define FLAG_SWAP_CHANNELS (1 << 9) -#define FLAG_RLE (1 << 8) -#define FLAG_SLOPE_FALLING (1 << 7) -#define FLAG_CLOCK_EXTERNAL (1 << 6) -#define FLAG_CHANNELGROUP_4 (1 << 5) -#define FLAG_CHANNELGROUP_3 (1 << 4) -#define FLAG_CHANNELGROUP_2 (1 << 3) -#define FLAG_CHANNELGROUP_1 (1 << 2) -#define FLAG_FILTER (1 << 1) -#define FLAG_DEMUX (1 << 0) +#define CAPTURE_FLAG_INTERNAL_TEST_MODE (1 << 11) +#define CAPTURE_FLAG_EXTERNAL_TEST_MODE (1 << 10) +#define CAPTURE_FLAG_SWAP_CHANNELS (1 << 9) +#define CAPTURE_FLAG_RLE (1 << 8) +#define CAPTURE_FLAG_SLOPE_FALLING (1 << 7) +#define CAPTURE_FLAG_CLOCK_EXTERNAL (1 << 6) +#define CAPTURE_FLAG_CHANNELGROUP_4 (1 << 5) +#define CAPTURE_FLAG_CHANNELGROUP_3 (1 << 4) +#define CAPTURE_FLAG_CHANNELGROUP_2 (1 << 3) +#define CAPTURE_FLAG_CHANNELGROUP_1 (1 << 2) +#define CAPTURE_FLAG_NOISE_FILTER (1 << 1) +#define CAPTURE_FLAG_DEMUX (1 << 0) /* Capture context magic numbers */ #define OLS_NO_TRIGGER (-1) @@ -85,7 +85,7 @@ struct dev_context { uint32_t trigger_mask[NUM_TRIGGER_STAGES]; uint32_t trigger_value[NUM_TRIGGER_STAGES]; int num_stages; - uint16_t flag_reg; + uint16_t capture_flags; unsigned int num_transfers; unsigned int num_samples; From a14522b2b9ff9965bf1938d8c078d1da4b23f5a4 Mon Sep 17 00:00:00 2001 From: v1ne Date: Tue, 31 Mar 2020 20:20:25 +0200 Subject: [PATCH 5/8] Clean up OLS: Make constant names more precise, clarify comment --- src/hardware/openbench-logic-sniffer/api.c | 3 ++ .../openbench-logic-sniffer/protocol.h | 32 +++++++++++-------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/hardware/openbench-logic-sniffer/api.c b/src/hardware/openbench-logic-sniffer/api.c index 3e632b475..dbf7296a8 100644 --- a/src/hardware/openbench-logic-sniffer/api.c +++ b/src/hardware/openbench-logic-sniffer/api.c @@ -502,6 +502,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) * to the channel mask. 1 means "disable channel". */ devc->capture_flags |= ~(ols_changrp_mask << 2) & 0x3c; + + /* RLE mode is always zero, for now. */ + arg[0] = devc->capture_flags & 0xff; arg[1] = devc->capture_flags >> 8; arg[2] = arg[3] = 0x00; diff --git a/src/hardware/openbench-logic-sniffer/protocol.h b/src/hardware/openbench-logic-sniffer/protocol.h index fa78ca79a..25e37a006 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.h +++ b/src/hardware/openbench-logic-sniffer/protocol.h @@ -50,20 +50,24 @@ /* Trigger config */ #define TRIGGER_START (1 << 3) -/* Bitmasks for capture_flags */ -/* 12-13 unused, 14-15 RLE mode (we hardcode mode 0). */ -#define CAPTURE_FLAG_INTERNAL_TEST_MODE (1 << 11) -#define CAPTURE_FLAG_EXTERNAL_TEST_MODE (1 << 10) -#define CAPTURE_FLAG_SWAP_CHANNELS (1 << 9) -#define CAPTURE_FLAG_RLE (1 << 8) -#define CAPTURE_FLAG_SLOPE_FALLING (1 << 7) -#define CAPTURE_FLAG_CLOCK_EXTERNAL (1 << 6) -#define CAPTURE_FLAG_CHANNELGROUP_4 (1 << 5) -#define CAPTURE_FLAG_CHANNELGROUP_3 (1 << 4) -#define CAPTURE_FLAG_CHANNELGROUP_2 (1 << 3) -#define CAPTURE_FLAG_CHANNELGROUP_1 (1 << 2) -#define CAPTURE_FLAG_NOISE_FILTER (1 << 1) -#define CAPTURE_FLAG_DEMUX (1 << 0) +/* Bit mask used for "set flags" command (0x82) */ +/* Take care about bit positions in diagrams, they are inverted. */ +#define CAPTURE_FLAG_RLEMODE1 (1 << 15) +#define CAPTURE_FLAG_RLEMODE0 (1 << 14) +#define CAPTURE_FLAG_RESERVED1 (1 << 13) +#define CAPTURE_FLAG_RESERVED0 (1 << 12) +#define CAPTURE_FLAG_INTERNAL_TEST_MODE (1 << 11) +#define CAPTURE_FLAG_EXTERNAL_TEST_MODE (1 << 10) +#define CAPTURE_FLAG_SWAP_CHANNELS (1 << 9) +#define CAPTURE_FLAG_RLE (1 << 8) +#define CAPTURE_FLAG_INVERT_EXT_CLOCK (1 << 7) +#define CAPTURE_FLAG_CLOCK_EXTERNAL (1 << 6) +#define CAPTURE_FLAG_DISABLE_CHANGROUP_4 (1 << 5) +#define CAPTURE_FLAG_DISABLE_CHANGROUP_3 (1 << 4) +#define CAPTURE_FLAG_DISABLE_CHANGROUP_2 (1 << 3) +#define CAPTURE_FLAG_DISABLE_CHANGROUP_1 (1 << 2) +#define CAPTURE_FLAG_NOISE_FILTER (1 << 1) +#define CAPTURE_FLAG_DEMUX (1 << 0) /* Capture context magic numbers */ #define OLS_NO_TRIGGER (-1) From 7dd371964d91d64a5e430d4433a125fd328730f1 Mon Sep 17 00:00:00 2001 From: v1ne Date: Wed, 1 Apr 2020 16:45:17 +0200 Subject: [PATCH 6/8] Clean up OLS: Use symbolic (non-)error names --- src/hardware/openbench-logic-sniffer/protocol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hardware/openbench-logic-sniffer/protocol.c b/src/hardware/openbench-logic-sniffer/protocol.c index 0a2bc4dd6..9a36c8c89 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.c +++ b/src/hardware/openbench-logic-sniffer/protocol.c @@ -30,7 +30,7 @@ SR_PRIV int send_shortcommand(struct sr_serial_dev_inst *serial, if (serial_write_blocking(serial, buf, 1, serial_timeout(serial, 1)) != 1) return SR_ERR; - if (serial_drain(serial) != 0) + if (serial_drain(serial) != SR_OK) return SR_ERR; return SR_OK; @@ -51,7 +51,7 @@ SR_PRIV int send_longcommand(struct sr_serial_dev_inst *serial, if (serial_write_blocking(serial, buf, 5, serial_timeout(serial, 1)) != 5) return SR_ERR; - if (serial_drain(serial) != 0) + if (serial_drain(serial) != SR_OK) return SR_ERR; return SR_OK; From aa4736b60ac959b2af1b8c766a58d754d14c791f Mon Sep 17 00:00:00 2001 From: v1ne Date: Tue, 31 Mar 2020 19:02:29 +0200 Subject: [PATCH 7/8] Refactor OLS: Deduplicate code --- .../openbench-logic-sniffer/protocol.c | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/hardware/openbench-logic-sniffer/protocol.c b/src/hardware/openbench-logic-sniffer/protocol.c index 9a36c8c89..0e7ebd793 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.c +++ b/src/hardware/openbench-logic-sniffer/protocol.c @@ -509,25 +509,19 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data) /* Send the trigger. */ std_session_send_df_trigger(sdi); - - /* Send post-trigger samples. */ - packet.type = SR_DF_LOGIC; - packet.payload = &logic; - logic.length = (devc->num_samples * 4) - (devc->trigger_at_smpl * 4); - logic.unitsize = 4; - logic.data = devc->raw_sample_buf + devc->trigger_at_smpl * 4 + - (devc->limit_samples - devc->num_samples) * 4; - sr_session_send(sdi, &packet); - } else { - /* no trigger was used */ - packet.type = SR_DF_LOGIC; - packet.payload = &logic; - logic.length = devc->num_samples * 4; - logic.unitsize = 4; - logic.data = devc->raw_sample_buf + - (devc->limit_samples - devc->num_samples) * 4; - sr_session_send(sdi, &packet); } + + /* Send post-trigger / all captured samples. */ + int num_pre_trigger_samples = devc->trigger_at_smpl == OLS_NO_TRIGGER + ? 0 : devc->trigger_at_smpl; + packet.type = SR_DF_LOGIC; + packet.payload = &logic; + logic.length = (devc->num_samples - num_pre_trigger_samples) * 4; + logic.unitsize = 4; + logic.data = devc->raw_sample_buf + (num_pre_trigger_samples + + devc->limit_samples - devc->num_samples) * 4; + sr_session_send(sdi, &packet); + g_free(devc->raw_sample_buf); serial_flush(serial); From eb05786ab0ea841f59ea100364a085e2971c5dd4 Mon Sep 17 00:00:00 2001 From: v1ne Date: Tue, 31 Mar 2020 21:51:22 +0200 Subject: [PATCH 8/8] OLS: Document Demon Core commands, use canonic their names, detect it See http://web.archive.org/web/20190317154112/ http://mygizmos.org/ols/Logic-Sniffer-FPGA-Spec.pdf for documentation. --- src/hardware/openbench-logic-sniffer/api.c | 14 ++--- .../openbench-logic-sniffer/protocol.c | 52 ++++++++---------- .../openbench-logic-sniffer/protocol.h | 55 ++++++++++++++----- 3 files changed, 72 insertions(+), 49 deletions(-) diff --git a/src/hardware/openbench-logic-sniffer/api.c b/src/hardware/openbench-logic-sniffer/api.c index dbf7296a8..8e4efb940 100644 --- a/src/hardware/openbench-logic-sniffer/api.c +++ b/src/hardware/openbench-logic-sniffer/api.c @@ -358,7 +358,7 @@ static int config_list(uint32_t key, GVariant **data, return SR_OK; } -static int set_trigger(const struct sr_dev_inst *sdi, int stage) +static int set_basic_trigger(const struct sr_dev_inst *sdi, int stage) { struct dev_context *devc; struct sr_serial_dev_inst *serial; @@ -367,7 +367,7 @@ static int set_trigger(const struct sr_dev_inst *sdi, int stage) devc = sdi->priv; serial = sdi->conn; - cmd = CMD_SET_TRIGGER_MASK + stage * 4; + cmd = CMD_SET_BASIC_TRIGGER_MASK0 + stage * 4; arg[0] = devc->trigger_mask[stage] & 0xff; arg[1] = (devc->trigger_mask[stage] >> 8) & 0xff; arg[2] = (devc->trigger_mask[stage] >> 16) & 0xff; @@ -375,7 +375,7 @@ static int set_trigger(const struct sr_dev_inst *sdi, int stage) if (send_longcommand(serial, cmd, arg) != SR_OK) return SR_ERR; - cmd = CMD_SET_TRIGGER_VALUE + stage * 4; + cmd = CMD_SET_BASIC_TRIGGER_VALUE0 + stage * 4; arg[0] = devc->trigger_value[stage] & 0xff; arg[1] = (devc->trigger_value[stage] >> 8) & 0xff; arg[2] = (devc->trigger_value[stage] >> 16) & 0xff; @@ -383,7 +383,7 @@ static int set_trigger(const struct sr_dev_inst *sdi, int stage) if (send_longcommand(serial, cmd, arg) != SR_OK) return SR_ERR; - cmd = CMD_SET_TRIGGER_CONFIG + stage * 4; + cmd = CMD_SET_BASIC_TRIGGER_CONFIG0 + stage * 4; arg[0] = arg[1] = arg[3] = 0x00; arg[2] = stage; if (stage == devc->num_stages) @@ -443,13 +443,13 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) devc->trigger_at_smpl = (readcount - delaycount) * 4 - devc->num_stages; for (i = 0; i <= devc->num_stages; i++) { sr_dbg("Setting OLS stage %d trigger.", i); - if ((ret = set_trigger(sdi, i)) != SR_OK) + if ((ret = set_basic_trigger(sdi, i)) != SR_OK) return ret; } } else { /* No triggers configured, force trigger on first stage. */ sr_dbg("Forcing trigger at stage 0."); - if ((ret = set_trigger(sdi, 0)) != SR_OK) + if ((ret = set_basic_trigger(sdi, 0)) != SR_OK) return ret; delaycount = readcount; } @@ -512,7 +512,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) return SR_ERR; /* Start acquisition on the device. */ - if (send_shortcommand(serial, CMD_RUN) != SR_OK) + if (send_shortcommand(serial, CMD_ARM_BASIC_TRIGGER) != SR_OK) return SR_ERR; /* Reset all operational states. */ diff --git a/src/hardware/openbench-logic-sniffer/protocol.c b/src/hardware/openbench-logic-sniffer/protocol.c index 0e7ebd793..4101995e5 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.c +++ b/src/hardware/openbench-logic-sniffer/protocol.c @@ -171,6 +171,9 @@ static void metadata_quirks(struct sr_dev_inst *sdi) if (!devc->max_samplerate) devc->max_samplerate = SR_MHZ(20); } + + if (sdi->version && strstr(sdi->version, "FPGA version 3.07")) + devc->device_flags |= DEVICE_FLAG_IS_DEMON_CORE; } SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) @@ -178,7 +181,7 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) struct sr_dev_inst *sdi; struct dev_context *devc; uint32_t tmp_int; - uint8_t key, type, token; + uint8_t key, type; int delay_ms; GString *tmp_str, *devname, *version; guchar tmp_c; @@ -196,12 +199,11 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) delay_ms = serial_timeout(serial, 1); if (serial_read_blocking(serial, &key, 1, delay_ms) != 1) break; - if (key == 0x00) { + if (key == METADATA_TOKEN_END) { sr_dbg("Got metadata key 0x00, metadata ends."); break; } type = key >> 5; - token = key & 0x1f; switch (type) { case 0: /* NULL-terminated string */ @@ -209,21 +211,20 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) delay_ms = serial_timeout(serial, 1); while (serial_read_blocking(serial, &tmp_c, 1, delay_ms) == 1 && tmp_c != '\0') g_string_append_c(tmp_str, tmp_c); - sr_dbg("Got metadata key 0x%.2x value '%s'.", - key, tmp_str->str); - switch (token) { - case 0x01: + sr_dbg("Got metadata token 0x%.2x value '%s'.", key, tmp_str->str); + switch (key) { + case METADATA_TOKEN_DEVICE_NAME: /* Device name */ devname = g_string_append(devname, tmp_str->str); break; - case 0x02: + case METADATA_TOKEN_FPGA_VERSION: /* FPGA firmware version */ if (version->len) g_string_append(version, ", "); g_string_append(version, "FPGA version "); g_string_append(version, tmp_str->str); break; - case 0x03: + case METADATA_TOKEN_ANCILLARY_VERSION: /* Ancillary version */ if (version->len) g_string_append(version, ", "); @@ -231,8 +232,7 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) g_string_append(version, tmp_str->str); break; default: - sr_info("ols: unknown token 0x%.2x: '%s'", - token, tmp_str->str); + sr_info("ols: unknown token 0x%.2x: '%s'", key, tmp_str->str); break; } g_string_free(tmp_str, TRUE); @@ -243,32 +243,30 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) if (serial_read_blocking(serial, &tmp_int, 4, delay_ms) != 4) break; tmp_int = RB32(&tmp_int); - sr_dbg("Got metadata key 0x%.2x value 0x%.8x.", - key, tmp_int); - switch (token) { - case 0x00: + sr_dbg("Got metadata token 0x%.2x value 0x%.8x.", key, tmp_int); + switch (key) { + case METADATA_TOKEN_NUM_PROBES_LONG: /* Number of usable channels */ ols_channel_new(sdi, tmp_int); break; - case 0x01: + case METADATA_TOKEN_SAMPLE_MEMORY_BYTES: /* Amount of sample memory available (bytes) */ devc->max_samples = tmp_int; break; - case 0x02: + case METADATA_TOKEN_DYNAMIC_MEMORY_BYTES: /* Amount of dynamic memory available (bytes) */ /* what is this for? */ break; - case 0x03: + case METADATA_TOKEN_MAX_SAMPLE_RATE_HZ: /* Maximum sample rate (Hz) */ devc->max_samplerate = tmp_int; break; - case 0x04: + case METADATA_TOKEN_PROTOCOL_VERSION_LONG: /* protocol version */ devc->protocol_version = tmp_int; break; default: - sr_info("Unknown token 0x%.2x: 0x%.8x.", - token, tmp_int); + sr_info("Unknown token 0x%.2x: 0x%.8x.", key, tmp_int); break; } break; @@ -277,20 +275,18 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) delay_ms = serial_timeout(serial, 1); if (serial_read_blocking(serial, &tmp_c, 1, delay_ms) != 1) break; - sr_dbg("Got metadata key 0x%.2x value 0x%.2x.", - key, tmp_c); - switch (token) { - case 0x00: + sr_dbg("Got metadata token 0x%.2x value 0x%.2x.", key, tmp_c); + switch (key) { + case METADATA_TOKEN_NUM_PROBES_SHORT: /* Number of usable channels */ ols_channel_new(sdi, tmp_c); break; - case 0x01: + case METADATA_TOKEN_PROTOCOL_VERSION_SHORT: /* protocol version */ devc->protocol_version = tmp_c; break; default: - sr_info("Unknown token 0x%.2x: 0x%.2x.", - token, tmp_c); + sr_info("Unknown token 0x%.2x: 0x%.2x.", key, tmp_c); break; } break; diff --git a/src/hardware/openbench-logic-sniffer/protocol.h b/src/hardware/openbench-logic-sniffer/protocol.h index 25e37a006..e164b9fa1 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.h +++ b/src/hardware/openbench-logic-sniffer/protocol.h @@ -34,20 +34,46 @@ #define DEFAULT_SAMPLERATE SR_KHZ(200) /* Command opcodes */ -#define CMD_RESET 0x00 -#define CMD_RUN 0x01 -#define CMD_ID 0x02 -#define CMD_METADATA 0x04 -#define CMD_SET_DIVIDER 0x80 -#define CMD_CAPTURE_SIZE 0x81 -#define CMD_SET_FLAGS 0x82 -#define CMD_CAPTURE_DELAYCOUNT 0x83 /* extension for Pepino */ -#define CMD_CAPTURE_READCOUNT 0x84 /* extension for Pepino */ -#define CMD_SET_TRIGGER_MASK 0xc0 -#define CMD_SET_TRIGGER_VALUE 0xc1 -#define CMD_SET_TRIGGER_CONFIG 0xc2 - -/* Trigger config */ +#define CMD_RESET 0x00 +#define CMD_ARM_BASIC_TRIGGER 0x01 +#define CMD_ID 0x02 +#define CMD_METADATA 0x04 +#define CMD_FINISH_NOW 0x05 /* extension of Demon Core */ +#define CMD_QUERY_INPUT_DATA 0x06 /* extension of Demon Core */ +#define CMD_QUERY_CAPTURE_STATE 0x07 /* extension of Demon Core */ +#define CMD_RETURN_CAPTURE_DATA 0x08 /* extension of Demon Core */ +#define CMD_ARM_ADVANCED_TRIGGER 0x0F /* extension of Demon Core */ +#define CMD_XON 0x11 +#define CMD_XOFF 0x13 +#define CMD_SET_DIVIDER 0x80 +#define CMD_CAPTURE_SIZE 0x81 +#define CMD_SET_FLAGS 0x82 +#define CMD_CAPTURE_DELAYCOUNT 0x83 /* extension of Pepino */ +#define CMD_CAPTURE_READCOUNT 0x84 /* extension of Pepino */ +#define CMD_SET_ADVANCED_TRIG_SEL 0x9E /* extension of Demon Core */ +#define CMD_SET_ADVANCED_TRIG_WRITE 0x9F /* extension of Demon Core */ +#define CMD_SET_BASIC_TRIGGER_MASK0 0xC0 /* 4 stages: 0xC0, 0xC4, 0xC8, 0xCC */ +#define CMD_SET_BASIC_TRIGGER_VALUE0 0xC1 /* 4 stages: 0xC1, 0xC5, 0xC9, 0xCD */ +#define CMD_SET_BASIC_TRIGGER_CONFIG0 0xC2 /* 4 stages: 0xC2, 0xC6, 0xCA, 0xCE */ + +/* Metadata tokens */ +#define METADATA_TOKEN_END 0x0 +#define METADATA_TOKEN_DEVICE_NAME 0x1 +#define METADATA_TOKEN_FPGA_VERSION 0x2 +#define METADATA_TOKEN_ANCILLARY_VERSION 0x3 +#define METADATA_TOKEN_NUM_PROBES_LONG 0x20 +#define METADATA_TOKEN_SAMPLE_MEMORY_BYTES 0x21 +#define METADATA_TOKEN_DYNAMIC_MEMORY_BYTES 0x22 +#define METADATA_TOKEN_MAX_SAMPLE_RATE_HZ 0x23 +#define METADATA_TOKEN_PROTOCOL_VERSION_LONG 0x24 +#define METADATA_TOKEN_CAPABILITIES 0x25 /* not implemented in Demon Core v3.07 */ +#define METADATA_TOKEN_NUM_PROBES_SHORT 0x40 +#define METADATA_TOKEN_PROTOCOL_VERSION_SHORT 0x41 + +/* Device config flags */ +#define DEVICE_FLAG_IS_DEMON_CORE (1 << 0) + +/* Basic Trigger Config */ #define TRIGGER_START (1 << 3) /* Bit mask used for "set flags" command (0x82) */ @@ -78,6 +104,7 @@ struct dev_context { uint32_t max_samples; uint32_t max_samplerate; uint32_t protocol_version; + uint16_t device_flags; /* acquisition-related properties: */ uint64_t cur_samplerate;