From b0238d0e22193563998dbf93e9e6ed8819d39b88 Mon Sep 17 00:00:00 2001 From: yunyaobaihong <896458252@qq.com> Date: Fri, 19 May 2023 14:41:52 +0800 Subject: [PATCH] demo updata:logic random can select probemode --- libsigrok4DSL/hardware/demo/demo.c | 110 ++++++++++++++++++++++++++++- libsigrok4DSL/hardware/demo/demo.h | 41 ++++++++--- 2 files changed, 141 insertions(+), 10 deletions(-) diff --git a/libsigrok4DSL/hardware/demo/demo.c b/libsigrok4DSL/hardware/demo/demo.c index 0ff220fc..8612f1f7 100644 --- a/libsigrok4DSL/hardware/demo/demo.c +++ b/libsigrok4DSL/hardware/demo/demo.c @@ -49,11 +49,23 @@ #define BUFSIZE 512*1024 #define DSO_BUFSIZE 10*1024 +static struct DEMO_channels logic_channel_modes[] = { + {DEMO_LOGIC125x16, LOGIC, SR_CHANNEL_LOGIC, 16, 1, SR_MHZ(1), SR_Mn(1), + SR_KHZ(10), SR_MHZ(125), "Use 16 Channels (Max 125MHz)"}, + {DEMO_LOGIC250x12, LOGIC, SR_CHANNEL_LOGIC, 12, 1, SR_MHZ(1), SR_Mn(1), + SR_KHZ(10), SR_MHZ(250), "Use 12 Channels (Max 250MHz)"}, + {DEMO_LOGIC500x6, LOGIC, SR_CHANNEL_LOGIC, 6, 1, SR_MHZ(1), SR_Mn(1), + SR_KHZ(10), SR_MHZ(500), "Use 6 Channels (Max 500MHz)"}, + {DEMO_LOGIC1000x3, LOGIC, SR_CHANNEL_LOGIC, 3, 1, SR_MHZ(1), SR_Mn(1), + SR_KHZ(10), SR_GHZ(1), "Use 3 Channels (Max 1GHz)"}, +}; + +static struct sr_list_item logic_channel_mode_list[ARRAY_SIZE(logic_channel_modes)+1]; + static struct DEMO_channels channel_modes[] = { // LA Stream {DEMO_LOGIC100x16, LOGIC, SR_CHANNEL_LOGIC, 16, 1, SR_MHZ(1), SR_Mn(1), SR_KHZ(10), SR_GHZ(1), "Use 16 Channels (Max 20MHz)"}, - //updata // DAQ {DEMO_ANALOG10x2, ANALOG, SR_CHANNEL_ANALOG, 2, 8, SR_MHZ(1), SR_Mn(1), @@ -74,6 +86,58 @@ static struct sr_dev_driver *di = &demo_driver_info; extern struct ds_trigger *trigger; +static int logic_adjust_probe(struct sr_dev_inst *sdi, int num_probes) +{ + uint16_t j; + struct sr_channel *probe; + struct DSL_context *devc = sdi->priv; + GSList *l; + + assert(num_probes > 0); + + j = g_slist_length(sdi->channels); + while(j < num_probes) { + if (!(probe = sr_channel_new(j, SR_CHANNEL_LOGIC, + TRUE, probe_names[j]))) + return SR_ERR; + sdi->channels = g_slist_append(sdi->channels, probe); + j++; + } + + while(j > num_probes) { + sdi->channels = g_slist_delete_link(sdi->channels, g_slist_last(sdi->channels)); + j--; + } + + for(l = sdi->channels; l; l = l->next) { + probe = (struct sr_channel *)l->data; + probe->enabled = TRUE; + probe->type = SR_CHANNEL_LOGIC; + } + return SR_OK; +} + +static void logic_adjust_samplerate(struct session_vdev * vdev) +{ + vdev->samplerates_max_index = ARRAY_SIZE(samplerates) - 1; + while (samplerates[vdev->samplerates_max_index] > + logic_channel_modes[logic_index].max_samplerate) + vdev->samplerates_max_index--; + + vdev->samplerates_min_index = 0; + while (samplerates[vdev->samplerates_min_index] < + logic_channel_modes[logic_index].min_samplerate) + vdev->samplerates_min_index++; + + assert(vdev->samplerates_max_index >= vdev->samplerates_min_index); + + if (vdev->samplerate > samplerates[vdev->samplerates_max_index]) + vdev->samplerate = samplerates[vdev->samplerates_max_index]; + + if (vdev->samplerate < samplerates[vdev->samplerates_min_index]) + vdev->samplerate = samplerates[vdev->samplerates_min_index]; +} + static void init_analog_random_data(struct session_vdev * vdev) { @@ -773,6 +837,9 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, case SR_CONF_REF_MAX: *data = g_variant_new_uint32(vdev->ref_max); break; + case SR_CONF_CHANNEL_MODE: + *data = g_variant_new_int16(ch_mode); + break; default: return SR_ERR_NA; } @@ -789,6 +856,7 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, struct session_vdev *vdev; const char *stropt; unsigned int i; + int nv; assert(sdi); assert(sdi->priv); @@ -972,6 +1040,23 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, vdev->is_loop = g_variant_get_boolean(data); sr_info("Set demo loop mode:%d", vdev->is_loop); break; + case SR_CONF_CHANNEL_MODE: + nv = g_variant_get_int16(data); + if(sdi->mode == LOGIC && sample_generator == PATTERN_RANDOM) + { + for(i = 0 ; i < ARRAY_SIZE(logic_channel_modes);i++) + { + if(logic_channel_modes[i].id == nv) + { + logic_index = i; + ch_mode = nv; + logic_adjust_probe(sdi,logic_channel_modes[i].num); + logic_adjust_samplerate(vdev); + break; + } + } + } + break; default: sr_err("Unknown capability: %d.", id); return SR_ERR_NA; @@ -1055,6 +1140,24 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, case SR_CONF_PROBE_MAP_UNIT: *data = g_variant_new_strv(probeMapUnits, ARRAY_SIZE(probeMapUnits)); break; + case SR_CONF_CHANNEL_MODE: + if(sdi->mode == LOGIC&& sample_generator == PATTERN_RANDOM) + { + for(int i = 0;ichannels = g_slist_append(sdi->channels, probe); } - adjust_samplerate(sdi); + + ch_mode = DEMO_LOGIC125x16; + logic_index = LOGIC125x16; + logic_adjust_samplerate(sdi->priv); } else if(sdi->mode == DSO) { diff --git a/libsigrok4DSL/hardware/demo/demo.h b/libsigrok4DSL/hardware/demo/demo.h index 5febfa54..af5d954a 100644 --- a/libsigrok4DSL/hardware/demo/demo.h +++ b/libsigrok4DSL/hardware/demo/demo.h @@ -31,6 +31,26 @@ enum DEMO_PATTERN { PATTERN_DEFAULT = 1, }; +enum DEMO_LOGIC_CHANNEL_ID { + DEMO_LOGIC125x16 = 16, + DEMO_LOGIC250x12 = 17, + DEMO_LOGIC500x6 = 18, + DEMO_LOGIC1000x3 = 19, +}; + +enum DEMO_CHANNEL_ID { + DEMO_LOGIC100x16 = 0, + DEMO_ANALOG10x2 = 1 , + DEMO_DSO200x2 = 2, +}; + +enum DEMO_LOGIC_CHANNEL_INDEX { + LOGIC125x16 = 0, + LOGIC250x12 = 1, + LOGIC500x6 = 2, + LOGIC1000x3 = 3, +}; + static char *pattern_strings_logic[100] = {"random"}; static char *pattern_strings_dso[100] = {"random"}; static char *pattern_strings_analog[100] = {"random"}; @@ -59,6 +79,9 @@ uint8_t sample_generator; static int64_t analog_count = 0; static uint64_t total_num = 0; +static enum DEMO_LOGIC_CHANNEL_ID ch_mode = DEMO_LOGIC125x16; +static enum DEMO_LOGIC_CHANNEL_INDEX logic_index = LOGIC125x16; + struct session_packet_buffer; static const uint64_t vdivs10to2000[] = { @@ -151,11 +174,7 @@ struct DEMO_profile { struct DEMO_caps dev_caps; }; -enum DEMO_CHANNEL_ID { - DEMO_LOGIC100x16 = 0, - DEMO_ANALOG10x2 = 1 , - DEMO_DSO200x2 = 2, -}; + struct DEMO_channels { enum DEMO_CHANNEL_ID id; @@ -233,8 +252,8 @@ static const uint64_t samplerates[] = { SR_MHZ(25), SR_MHZ(40), SR_MHZ(50), - SR_MHZ(100), - SR_MHZ(200), + SR_MHZ(125), + SR_MHZ(250), SR_MHZ(400), SR_MHZ(500), SR_MHZ(800), @@ -286,7 +305,7 @@ static const uint64_t samplerates[] = { #define ANALOG_MIN_PACKET_NUM(n) ((ANALOG_POST_DATA_PER_SECOND(n))/(ANALOG_MIN_PACKET_LEN)) #define ANALOG_PACKET_ALIGN 2 -#define LOGIC_HW_DEPTH (SR_GHZ(16)) +#define LOGIC_HW_DEPTH (SR_GHZ(1)) #define LOGIC_MAX_PROBE_NUM 16 @@ -480,6 +499,12 @@ static const int ranx[] = { -41, 36, -8, 46, 47, -34, 28, -39, 7, -32, 38, -27, 28, -3, -8, 43, -37, -24, 6, 3, }; +static int get_logic_probe_type_index_by_probe_type(int probe_type); + +static int logic_adjust_probe(struct sr_dev_inst *sdi, int num_probes); + +static void logic_adjust_samplerate(struct session_vdev * vdev); + static void init_analog_random_data(struct session_vdev * vdev); static void delay_time();