X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Frigol-ds%2Fapi.c;h=95de8f6a0d7b30339a7fd6756ba3d4bfe556d0f6;hb=73c575cf9e4b82770d8a6f7c916903e54e9fe7e7;hp=6846068965c4b9a31aa13de4786ee57ade64f4d2;hpb=f6129c8f0c92e45de5d70b4101bf2bd759a5fdf7;p=libsigrok.git diff --git a/src/hardware/rigol-ds/api.c b/src/hardware/rigol-ds/api.c index 68460689..95de8f6a 100644 --- a/src/hardware/rigol-ds/api.c +++ b/src/hardware/rigol-ds/api.c @@ -42,7 +42,7 @@ static const uint32_t drvopts[] = { }; static const uint32_t devopts[] = { - SR_CONF_LIMIT_FRAMES | SR_CONF_SET, + SR_CONF_LIMIT_FRAMES | SR_CONF_GET | SR_CONF_SET, SR_CONF_SAMPLERATE | SR_CONF_GET, SR_CONF_TIMEBASE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_NUM_HDIV | SR_CONF_GET, @@ -242,6 +242,7 @@ static const struct rigol_ds_model supported_models[] = { {SERIES(DS1000), "DS1052E", {5, 1000000000}, CH_INFO(2, false), std_cmd}, {SERIES(DS1000), "DS1102E", {2, 1000000000}, CH_INFO(2, false), std_cmd}, {SERIES(DS1000), "DS1152E", {2, 1000000000}, CH_INFO(2, false), std_cmd}, + {SERIES(DS1000), "DS1152E-EDU", {2, 1000000000}, CH_INFO(2, false), std_cmd}, {SERIES(DS1000), "DS1052D", {5, 1000000000}, CH_INFO(2, true), std_cmd}, {SERIES(DS1000), "DS1102D", {2, 1000000000}, CH_INFO(2, true), std_cmd}, {SERIES(DS1000), "DS1152D", {2, 1000000000}, CH_INFO(2, true), std_cmd}, @@ -274,6 +275,8 @@ static const struct rigol_ds_model supported_models[] = { {SERIES(DS1000Z), "DS1104Z-S", {5, 1000000000}, CH_INFO(4, false), std_cmd}, {SERIES(DS1000Z), "DS1074Z Plus", {5, 1000000000}, CH_INFO(4, false), std_cmd}, {SERIES(DS1000Z), "DS1104Z Plus", {5, 1000000000}, CH_INFO(4, false), std_cmd}, + {SERIES(DS1000Z), "DS1102Z-E", {2, 1000000000}, CH_INFO(2, false), std_cmd}, + {SERIES(DS1000Z), "DS1202Z-E", {2, 1000000000}, CH_INFO(2, false), std_cmd}, {SERIES(DS1000Z), "MSO1074Z", {5, 1000000000}, CH_INFO(4, true), std_cmd}, {SERIES(DS1000Z), "MSO1104Z", {5, 1000000000}, CH_INFO(4, true), std_cmd}, {SERIES(DS1000Z), "MSO1074Z-S", {5, 1000000000}, CH_INFO(4, true), std_cmd}, @@ -291,6 +294,8 @@ static const struct rigol_ds_model supported_models[] = { static struct sr_dev_driver rigol_ds_driver_info; +static int analog_frame_size(const struct sr_dev_inst *); + static void clear_helper(struct dev_context *devc) { unsigned int i; @@ -498,6 +503,7 @@ static int analog_frame_size(const struct sr_dev_inst *sdi) case DATA_SOURCE_LIVE: return devc->model->series->live_samples; case DATA_SOURCE_MEMORY: + case DATA_SOURCE_SEGMENTED: return devc->model->series->buffer_samples / analog_channels; default: return 0; @@ -512,6 +518,7 @@ static int digital_frame_size(const struct sr_dev_inst *sdi) case DATA_SOURCE_LIVE: return devc->model->series->live_samples * 2; case DATA_SOURCE_MEMORY: + case DATA_SOURCE_SEGMENTED: return devc->model->series->buffer_samples * 2; default: return 0; @@ -524,7 +531,6 @@ static int config_get(uint32_t key, GVariant **data, struct dev_context *devc; struct sr_channel *ch; const char *tmp_str; - uint64_t samplerate; int analog_channel = -1; float smallest_diff = INFINITY; int idx = -1; @@ -567,15 +573,11 @@ static int config_get(uint32_t key, GVariant **data, else *data = g_variant_new_string("Segmented"); break; + case SR_CONF_LIMIT_FRAMES: + *data = g_variant_new_uint64(devc->limit_frames); + break; case SR_CONF_SAMPLERATE: - if (devc->data_source == DATA_SOURCE_LIVE) { - samplerate = analog_frame_size(sdi) / - (devc->timebase * devc->model->series->num_horizontal_divs); - *data = g_variant_new_uint64(samplerate); - } else { - sr_dbg("Unknown data source: %d.", devc->data_source); - return SR_ERR_NA; - } + *data = g_variant_new_uint64(devc->sample_rate); break; case SR_CONF_TRIGGER_SOURCE: if (!strcmp(devc->trigger_source, "ACL")) @@ -877,15 +879,17 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct sr_scpi_dev_inst *scpi; struct dev_context *devc; struct sr_channel *ch; - struct sr_datafeed_packet packet; gboolean some_digital; GSList *l; char *cmd; + int protocol; scpi = sdi->conn; devc = sdi->priv; + protocol = devc->model->series->protocol; devc->num_frames = 0; + devc->num_frames_segmented = 0; some_digital = FALSE; for (l = sdi->channels; l; l = l->next) { @@ -906,7 +910,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) /* Only one list entry for older protocols. All channels are * retrieved together when this entry is processed. */ if (ch->enabled && ( - devc->model->series->protocol > PROTOCOL_V3 || + protocol > PROTOCOL_V3 || !some_digital)) devc->enabled_channels = g_slist_append( devc->enabled_channels, ch); @@ -914,8 +918,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) some_digital = TRUE; /* Turn on LA module if currently off. */ if (!devc->la_enabled) { - if (rigol_ds_config_set(sdi, - devc->model->series->protocol >= PROTOCOL_V3 ? + if (rigol_ds_config_set(sdi, protocol >= PROTOCOL_V3 ? ":LA:STAT ON" : ":LA:DISP ON") != SR_OK) return SR_ERR; devc->la_enabled = TRUE; @@ -923,9 +926,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) } if (ch->enabled != devc->digital_channels[ch->index]) { /* Enabled channel is currently disabled, or vice versa. */ - if (devc->model->series->protocol >= PROTOCOL_V5) + if (protocol >= PROTOCOL_V5) cmd = ":LA:DISP D%d,%s"; - else if (devc->model->series->protocol >= PROTOCOL_V3) + else if (protocol >= PROTOCOL_V3) cmd = ":LA:DIG%d:DISP %s"; else cmd = ":DIG%d:TURN %s"; @@ -950,8 +953,37 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) /* Set memory mode. */ if (devc->data_source == DATA_SOURCE_SEGMENTED) { - sr_err("Data source 'Segmented' not yet supported"); - return SR_ERR; + switch (protocol) { + case PROTOCOL_V1: + case PROTOCOL_V2: + /* V1 and V2 do not have segmented data */ + sr_err("Data source 'Segmented' not supported on this model"); + break; + case PROTOCOL_V3: + case PROTOCOL_V4: + { + int frames = 0; + if (sr_scpi_get_int(sdi->conn, + protocol == PROTOCOL_V4 ? "FUNC:WREP:FEND?" : + "FUNC:WREP:FMAX?", &frames) != SR_OK) + return SR_ERR; + if (frames <= 0) { + sr_err("No segmented data available"); + return SR_ERR; + } + devc->num_frames_segmented = frames; + break; + } + case PROTOCOL_V5: + /* The frame limit has to be read on the fly, just set up + * reading of the first frame */ + if (rigol_ds_config_set(sdi, "REC:CURR 1") != SR_OK) + return SR_ERR; + break; + default: + sr_err("Data source 'Segmented' not yet supported"); + return SR_ERR; + } } devc->analog_frame_size = analog_frame_size(sdi); @@ -989,12 +1021,25 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) devc->channel_entry = devc->enabled_channels; + if (devc->data_source == DATA_SOURCE_LIVE) + devc->sample_rate = analog_frame_size(sdi) / + (devc->timebase * devc->model->series->num_horizontal_divs); + else { + float xinc; + if (devc->model->series->protocol >= PROTOCOL_V3 && + sr_scpi_get_float(sdi->conn, "WAV:XINC?", &xinc) != SR_OK) { + sr_err("Couldn't get sampling rate"); + return SR_ERR; + } + devc->sample_rate = 1. / xinc; + } + + if (rigol_ds_capture_start(sdi) != SR_OK) return SR_ERR; /* Start of first frame. */ - packet.type = SR_DF_FRAME_BEGIN; - sr_session_send(sdi, &packet); + std_session_send_df_frame_begin(sdi); return SR_OK; }