diff --git a/libsigrok4DSL/hardware/demo/demo.c b/libsigrok4DSL/hardware/demo/demo.c index ddb53017..1218b51e 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); @@ -799,18 +867,10 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, { case SR_CONF_SAMPLERATE: vdev->samplerate = g_variant_get_uint64(data); - if(sdi->mode == LOGIC && sample_generator >PATTERN_RANDOM) - { - samplerates_file[0] = vdev->samplerate; - } sr_dbg("Setting samplerate to %llu.", vdev->samplerate); break; case SR_CONF_LIMIT_SAMPLES: vdev->total_samples = g_variant_get_uint64(data); - if(sdi->mode == LOGIC && sample_generator >PATTERN_RANDOM) - { - samplecounts_file[0] = vdev->total_samples; - } sr_dbg("Setting limit samples to %llu.", vdev->total_samples); break; case SR_CONF_LIMIT_MSEC: @@ -821,9 +881,13 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, { case LOGIC: if(SR_OK == reset_dsl_path(sdi,sdi->mode ,PATTERN_DEFAULT)) + { sample_generator = PATTERN_DEFAULT; + } else + { sample_generator = PATTERN_RANDOM; + } break; case DSO: reset_dsl_path(sdi,sdi->mode ,PATTERN_RANDOM); @@ -845,7 +909,6 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, { sample_generator = PATTERN_RANDOM; } - sr_dbg("%s: setting pattern to %d", __func__, sample_generator); break; @@ -892,11 +955,14 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, } else{ if(ch->coupling == 0) + { ch->hw_offset = 178; + } else + { ch->hw_offset = 128; + } } - break; case SR_CONF_PROBE_HW_OFFSET: ch->hw_offset = g_variant_get_uint16(data); @@ -918,12 +984,18 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, ch->coupling = g_variant_get_byte(data); ch->hw_offset = ch->offset; } - else{ + else + { ch->coupling = g_variant_get_byte(data); if(ch->coupling == 0) + { ch->hw_offset = 178; + } else + { ch->hw_offset = 128; + } + } } break; @@ -972,6 +1044,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 +1144,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;ipost_buf + i) = (uint8_t)tem; } } @@ -2308,258 +2414,248 @@ static int load_virtual_device_session(struct sr_dev_inst *sdi) unz_file_info64 fileInfo; struct sr_channel *probe; - int ret, devcnt, i, j; - uint16_t probenum; + int devcnt, i, j; uint64_t tmp_u64, total_probes, enabled_probes; - uint16_t p; - int64_t tmp_64; - char **sections, **keys, *metafile, *val; - char probename[SR_MAX_PROBENAME_LEN + 1]; + char **sections, **keys, *metafile, *val,*probe_name; int mode = LOGIC; int channel_type = SR_CHANNEL_LOGIC; - double tmp_double; int version = 1; + struct session_vdev * vdev = sdi->priv; + assert(sdi); if (sample_generator != PATTERN_RANDOM) { assert(sdi->path); } - - if (sdi->mode == LOGIC && sample_generator == PATTERN_RANDOM) + + switch (sdi->mode) { - sdi->driver->config_set(SR_CONF_SAMPLERATE, - g_variant_new_uint64(SR_MHZ(1)), sdi, NULL, NULL); - sdi->driver->config_set(SR_CONF_LIMIT_SAMPLES, - g_variant_new_uint64(SR_MHZ(1)), sdi, NULL, NULL); - sr_dev_probes_free(sdi); - sdi->driver->config_set(SR_CONF_CAPTURE_NUM_PROBES, - g_variant_new_uint64(16), sdi, NULL, NULL); - sdi->driver->config_set(SR_CONF_NUM_BLOCKS, - g_variant_new_uint64(6), sdi, NULL, NULL); - - char* probe_val; - for (int i = 0; i < 16; i++) - { - probe_val = probe_names[i]; - if (!(probe = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, probe_val))) + case LOGIC: + if(sample_generator != PATTERN_RANDOM){ + archive = unzOpen64(sdi->path); + if (NULL == archive) { - sr_err("%s: create channel failed", __func__); - sr_dev_inst_free(sdi); + sr_err("%s: Load zip file error.", __func__); + return SR_ERR; + } + if (unzLocateFile(archive, "header", 0) != UNZ_OK) + { + unzClose(archive); + sr_err("%s: unzLocateFile error.", __func__); + return SR_ERR; + } + if (unzGetCurrentFileInfo64(archive, &fileInfo, szFilePath, + sizeof(szFilePath), NULL, 0, NULL, 0) != UNZ_OK) + { + unzClose(archive); + sr_err("%s: unzGetCurrentFileInfo64 error.", __func__); + return SR_ERR; + } + if (unzOpenCurrentFile(archive) != UNZ_OK) + { + sr_err("%s: Cant't open zip inner file.", __func__); + unzClose(archive); return SR_ERR; } - sdi->channels = g_slist_append(sdi->channels, probe); - } - adjust_samplerate(sdi); - } - else if(sdi->mode == DSO) - { - sdi->driver->config_set(SR_CONF_SAMPLERATE, - g_variant_new_uint64(SR_MHZ(100)), sdi, NULL, NULL); - sdi->driver->config_set(SR_CONF_LIMIT_SAMPLES, - g_variant_new_uint64(SR_KHZ(10)), sdi, NULL, NULL); - sr_dev_probes_free(sdi); - sdi->driver->config_set(SR_CONF_CAPTURE_NUM_PROBES, - g_variant_new_uint64(2), sdi, NULL, NULL); - sdi->driver->config_set(SR_CONF_NUM_BLOCKS, - g_variant_new_uint64(1), sdi, NULL, NULL); - char* probe_val; - for (int i = 0; i < 2; i++) - { - probe_val = probe_names[i]; - if (!(probe = sr_channel_new(i, SR_CHANNEL_DSO, TRUE, probe_val))) + if (!(metafile = g_try_malloc(fileInfo.uncompressed_size))) { - sr_err("%s: create channel failed", __func__); - sr_dev_inst_free(sdi); + sr_err("%s: metafile malloc failed", __func__); + return SR_ERR_MALLOC; + } + + unzReadCurrentFile(archive, metafile, fileInfo.uncompressed_size); + unzCloseCurrentFile(archive); + + if (unzClose(archive) != UNZ_OK) + { + sr_err("%s: Close zip archive error.", __func__); return SR_ERR; } - probe->enabled = TRUE; - probe->coupling = 1; - probe->vdiv = 1000; - probe->vfactor = 1000; - probe->hw_offset = 128; - probe->offset = 128; - probe->trig_value = 0.5; - sdi->channels = g_slist_append(sdi->channels, probe); - } - adjust_samplerate(sdi); - } - else if(sdi->mode == ANALOG) - { - sdi->driver->config_set(SR_CONF_SAMPLERATE, - g_variant_new_uint64(SR_MHZ(1)), sdi, NULL, NULL); - sdi->driver->config_set(SR_CONF_LIMIT_SAMPLES, - g_variant_new_uint64(SR_MHZ(1)), sdi, NULL, NULL); - sr_dev_probes_free(sdi); - sdi->driver->config_set(SR_CONF_CAPTURE_NUM_PROBES, - g_variant_new_uint64(2), sdi, NULL, NULL); - sdi->driver->config_set(SR_CONF_NUM_BLOCKS, - g_variant_new_uint64(1), sdi, NULL, NULL); - char* probe_val; - for (int i = 0; i < 2; i++) - { - probe_val = probe_names[i]; - if (!(probe = sr_channel_new(i, SR_CHANNEL_ANALOG, TRUE, probe_val))) + archive = NULL; + + kf = g_key_file_new(); + if (!g_key_file_load_from_data(kf, metafile, fileInfo.uncompressed_size, 0, NULL)) { - sr_err("%s: create channel failed", __func__); - sr_dev_inst_free(sdi); + sr_err("Failed to parse metadata."); return SR_ERR; } - probe->enabled = TRUE; - probe->bits = 8; - probe->vdiv = 1000; - probe->hw_offset = 128; - probe->offset = 128; - probe->coupling = 1; - probe->vfactor = 1; - probe->trig_value = 128; - probe->map_default = TRUE; - probe->map_unit = "V"; - probe->map_min = -(probe->vdiv * probe->vfactor * DS_CONF_DSO_VDIVS / 2000.0); - probe->map_max = probe->vdiv * probe->vfactor * DS_CONF_DSO_VDIVS / 2000.0; + devcnt = 0; + sections = g_key_file_get_groups(kf, NULL); - sdi->channels = g_slist_append(sdi->channels, probe); - } - adjust_samplerate(sdi); - } - else - { - archive = unzOpen64(sdi->path); - if (NULL == archive) - { - sr_err("%s: Load zip file error.", __func__); - return SR_ERR; - } - if (unzLocateFile(archive, "header", 0) != UNZ_OK) - { - unzClose(archive); - sr_err("%s: unzLocateFile error.", __func__); - return SR_ERR; - } - if (unzGetCurrentFileInfo64(archive, &fileInfo, szFilePath, - sizeof(szFilePath), NULL, 0, NULL, 0) != UNZ_OK) - { - unzClose(archive); - sr_err("%s: unzGetCurrentFileInfo64 error.", __func__); - return SR_ERR; - } - if (unzOpenCurrentFile(archive) != UNZ_OK) - { - sr_err("%s: Cant't open zip inner file.", __func__); - unzClose(archive); - return SR_ERR; - } - - if (!(metafile = g_try_malloc(fileInfo.uncompressed_size))) - { - sr_err("%s: metafile malloc failed", __func__); - return SR_ERR_MALLOC; - } - - unzReadCurrentFile(archive, metafile, fileInfo.uncompressed_size); - unzCloseCurrentFile(archive); - - if (unzClose(archive) != UNZ_OK) - { - sr_err("%s: Close zip archive error.", __func__); - return SR_ERR; - } - archive = NULL; - - kf = g_key_file_new(); - if (!g_key_file_load_from_data(kf, metafile, fileInfo.uncompressed_size, 0, NULL)) - { - sr_err("Failed to parse metadata."); - return SR_ERR; - } - - devcnt = 0; - sections = g_key_file_get_groups(kf, NULL); - - for (i = 0; sections[i]; i++) - { - if (!strcmp(sections[i], "version")) + for (i = 0; sections[i]; i++) { - keys = g_key_file_get_keys(kf, sections[i], NULL, NULL); - for (j = 0; keys[j]; j++) + if (!strcmp(sections[i], "version")) { - val = g_key_file_get_string(kf, sections[i], keys[j], NULL); - if (!strcmp(keys[j], "version")) + keys = g_key_file_get_keys(kf, sections[i], NULL, NULL); + for (j = 0; keys[j]; j++) { - version = strtoull(val, NULL, 10); - sr_info("The 'header' file format version:%d", version); - } - } - } - - if (!strncmp(sections[i], "header", 6)) - { - enabled_probes = total_probes = 0; - keys = g_key_file_get_keys(kf, sections[i], NULL, NULL); - - for (j = 0; keys[j]; j++) - { - val = g_key_file_get_string(kf, sections[i], keys[j], NULL); - - if (!strcmp(keys[j], "device mode")) - { - mode = strtoull(val, NULL, 10); - } - else if (!strcmp(keys[j], "samplerate")) - { - sr_parse_sizestring(val, &tmp_u64); - sdi->driver->config_set(SR_CONF_SAMPLERATE, - g_variant_new_uint64(tmp_u64), sdi, NULL, NULL); - } - else if (!strcmp(keys[j], "total samples")) - { - tmp_u64 = strtoull(val, NULL, 10); - sdi->driver->config_set(SR_CONF_LIMIT_SAMPLES, - g_variant_new_uint64(tmp_u64), sdi, NULL, NULL); - - } - else if (!strcmp(keys[j], "total blocks")) - { - tmp_u64 = strtoull(val, NULL, 10); - sdi->driver->config_set(SR_CONF_NUM_BLOCKS, - g_variant_new_uint64(tmp_u64), sdi, NULL, NULL); - } - else if (!strcmp(keys[j], "total probes")) - { - sr_dev_probes_free(sdi); - total_probes = strtoull(val, NULL, 10); - sdi->driver->config_set(SR_CONF_CAPTURE_NUM_PROBES, - g_variant_new_uint64(total_probes), sdi, NULL, NULL); - } - else if (!strncmp(keys[j], "probe", 5)) - { - enabled_probes++; - tmp_u64 = strtoul(keys[j] + 5, NULL, 10); - channel_type = (mode == DSO) ? SR_CHANNEL_DSO : (mode == ANALOG) ? SR_CHANNEL_ANALOG - : SR_CHANNEL_LOGIC; - if (!(probe = sr_channel_new(tmp_u64, channel_type, TRUE, val))) + val = g_key_file_get_string(kf, sections[i], keys[j], NULL); + if (!strcmp(keys[j], "version")) { - sr_err("%s: create channel failed", __func__); - sr_dev_inst_free(sdi); - return SR_ERR; + version = strtoull(val, NULL, 10); + sr_info("The 'header' file format version:%d", version); } - - sdi->channels = g_slist_append(sdi->channels, probe); } } - adjust_samplerate(sdi); - g_strfreev(keys); + + if (!strncmp(sections[i], "header", 6)) + { + enabled_probes = total_probes = 0; + keys = g_key_file_get_keys(kf, sections[i], NULL, NULL); + + for (j = 0; keys[j]; j++) + { + val = g_key_file_get_string(kf, sections[i], keys[j], NULL); + + if (!strcmp(keys[j], "device mode")) + { + mode = strtoull(val, NULL, 10); + } + else if (!strcmp(keys[j], "samplerate")) + { + sr_parse_sizestring(val, &tmp_u64); + vdev->samplerate = tmp_u64; + if(sdi->mode == LOGIC && sample_generator >PATTERN_RANDOM) + { + samplerates_file[0] = vdev->samplerate; + } + } + else if (!strcmp(keys[j], "total samples")) + { + tmp_u64 = strtoull(val, NULL, 10); + vdev->total_samples = tmp_u64; + if(sdi->mode == LOGIC && sample_generator >PATTERN_RANDOM) + { + samplecounts_file[0] = vdev->total_samples; + } + } + else if (!strcmp(keys[j], "total blocks")) + { + tmp_u64 = strtoull(val, NULL, 10); + vdev->num_blocks = tmp_u64; + } + else if (!strcmp(keys[j], "total probes")) + { + sr_dev_probes_free(sdi); + total_probes = strtoull(val, NULL, 10); + vdev->num_probes = total_probes; + } + else if (!strncmp(keys[j], "probe", 5)) + { + enabled_probes++; + tmp_u64 = strtoul(keys[j] + 5, NULL, 10); + channel_type = (mode == DSO) ? SR_CHANNEL_DSO : (mode == ANALOG) ? SR_CHANNEL_ANALOG + : SR_CHANNEL_LOGIC; + if (!(probe = sr_channel_new(tmp_u64, channel_type, TRUE, val))) + { + sr_err("%s: create channel failed", __func__); + sr_dev_inst_free(sdi); + return SR_ERR; + } + + sdi->channels = g_slist_append(sdi->channels, probe); + } + } + adjust_samplerate(sdi); + g_strfreev(keys); + } + devcnt++; } - devcnt++; + + g_strfreev(sections); + g_key_file_free(kf); + g_safe_free(metafile); } + else + { + vdev->samplerate = LOGIC_DEFAULT_SAMPLERATE; + vdev->total_samples = LOGIC_DEFAULT_TOTAL_SAMPLES; + vdev->num_probes = LOGIC_DEFAULT_NUM_PROBE; + sr_dev_probes_free(sdi); - g_strfreev(sections); - g_key_file_free(kf); - g_safe_free(metafile); + for (int i = 0; i < LOGIC_DEFAULT_NUM_PROBE; i++) + { + probe_name = probe_names[i]; + if (!(probe = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, probe_name))) + { + sr_err("%s: create channel failed", __func__); + sr_dev_inst_free(sdi); + return SR_ERR; + } + sdi->channels = g_slist_append(sdi->channels, probe); + } + //updata + ch_mode = DEMO_LOGIC125x16; + logic_index = LOGIC125x16; + logic_adjust_samplerate(sdi->priv); + } + break; + case DSO: + vdev->samplerate = DSO_DEFAULT_SAMPLERATE; + vdev->total_samples = DSO_DEFAULT_TOTAL_SAMPLES; + vdev->num_probes = DSO_DEFAULT_NUM_PROBE; + vdev->num_blocks = DSO_DEFAULT_NUM_BLOCK; + sr_dev_probes_free(sdi); + + for (int i = 0; i < DSO_DEFAULT_NUM_PROBE; i++) + { + probe_name = probe_names[i]; + if (!(probe = sr_channel_new(i, SR_CHANNEL_DSO, TRUE, probe_name))) + { + sr_err("%s: create channel failed", __func__); + sr_dev_inst_free(sdi); + return SR_ERR; + } + probe->enabled = DSO_DEFAULT_ENABLE; + probe->coupling = DSO_DEFAULT_COUPLING; + probe->vdiv = DSO_DEFAULT_VIDV; + probe->vfactor = DSO_DEFAULT_VFACOTR; + probe->hw_offset = DSO_DEFAULT_HW_OFFSET; + probe->offset = DSO_DEFAULT_OFFSET; + probe->trig_value = DSO_DEFAULT_TRIG_VAL; + sdi->channels = g_slist_append(sdi->channels, probe); + } + adjust_samplerate(sdi); + break; + case ANALOG: + vdev->samplerate = ANALOG_DEFAULT_SAMPLERATE; + vdev->total_samples = ANALOG_DEFAULT_TOTAL_SAMPLES; + vdev->num_probes = ANALOG_DEFAULT_NUM_PROBE; + vdev->num_blocks = ANALOG_DEFAULT_NUM_BLOCK; + sr_dev_probes_free(sdi); + + for (int i = 0; i < ANALOG_DEFAULT_NUM_PROBE; i++) + { + probe_name = probe_names[i]; + if (!(probe = sr_channel_new(i, SR_CHANNEL_ANALOG, TRUE, probe_name))) + { + sr_err("%s: create channel failed", __func__); + sr_dev_inst_free(sdi); + return SR_ERR; + } + probe->bits = ANALOG_DEFAULT_BIT; + probe->enabled = ANALOG_DEFAULT_ENABLE; + probe->coupling = ANALOG_DEFAULT_COUPLING; + probe->vdiv = ANALOG_DEFAULT_VIDV; + probe->vfactor = ANALOG_DEFAULT_VFACOTR; + probe->hw_offset = ANALOG_DEFAULT_HW_OFFSET; + probe->offset = ANALOG_DEFAULT_OFFSET; + probe->trig_value = ANALOG_DEFAULT_TRIG_VAL; + probe->map_default = ANALOG_DEFAULT_MAP_DEFAULT; + probe->map_unit = ANALOG_DEFAULT_MAP_UNIT; + probe->map_min = ANALOG_DEFAULT_MAP_MIN; + probe->map_max = ANALOG_DEFAULT_MAP_MAX; + + sdi->channels = g_slist_append(sdi->channels, probe); + } + adjust_samplerate(sdi); + break; + default: + break; } - return SR_OK; } diff --git a/libsigrok4DSL/hardware/demo/demo.h b/libsigrok4DSL/hardware/demo/demo.h index 5febfa54..17553697 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; @@ -234,7 +253,8 @@ static const uint64_t samplerates[] = { 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 +306,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 @@ -316,6 +336,40 @@ static const uint64_t samplerates[] = { #define ANALOG_RETE(n) ((n/SR_HZ(10))) +//defult value +#define LOGIC_DEFAULT_SAMPLERATE SR_MHZ(1) +#define LOGIC_DEFAULT_TOTAL_SAMPLES SR_MHZ(1) +#define LOGIC_DEFAULT_NUM_PROBE 16 + +#define DSO_DEFAULT_SAMPLERATE SR_MHZ(100) +#define DSO_DEFAULT_TOTAL_SAMPLES SR_KHZ(10) +#define DSO_DEFAULT_NUM_PROBE 2 +#define DSO_DEFAULT_NUM_BLOCK 1 +#define DSO_DEFAULT_ENABLE TRUE +#define DSO_DEFAULT_COUPLING 1 +#define DSO_DEFAULT_VIDV SR_V(1) +#define DSO_DEFAULT_VFACOTR SR_V(1) +#define DSO_DEFAULT_HW_OFFSET 128 +#define DSO_DEFAULT_OFFSET 128 +#define DSO_DEFAULT_TRIG_VAL 0.5 + +#define ANALOG_DEFAULT_SAMPLERATE SR_MHZ(1) +#define ANALOG_DEFAULT_TOTAL_SAMPLES SR_MHZ(1) +#define ANALOG_DEFAULT_NUM_PROBE 2 +#define ANALOG_DEFAULT_NUM_BLOCK 1 +#define ANALOG_DEFAULT_BIT 8 +#define ANALOG_DEFAULT_ENABLE TRUE +#define ANALOG_DEFAULT_COUPLING 1 +#define ANALOG_DEFAULT_VIDV SR_V(1) +#define ANALOG_DEFAULT_VFACOTR SR_mV(1) +#define ANALOG_DEFAULT_HW_OFFSET 128 +#define ANALOG_DEFAULT_OFFSET 128 +#define ANALOG_DEFAULT_TRIG_VAL 128 +#define ANALOG_DEFAULT_MAP_DEFAULT TRUE +#define ANALOG_DEFAULT_MAP_UNIT "V" +#define ANALOG_DEFAULT_MAP_MIN (gdouble)-5 +#define ANALOG_DEFAULT_MAP_MAX (gdouble)+5 + static const char *maxHeights[] = { @@ -480,6 +534,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();