Skip to content

Commit

Permalink
fix: The dso measures error with trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamsource-tai committed Sep 20, 2023
1 parent 735fd59 commit a36a71d
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 50 deletions.
Binary file modified DSView/res/DSCopeU3P100.bin
Binary file not shown.
1 change: 1 addition & 0 deletions DSView/src/appcore/sigsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,7 @@ namespace appcore {
{
if (s->signal_type() == SR_CHANNEL_DSO && (s->enabled())){
view::DsoSignal *dsoSig = (view::DsoSignal*)s;
dsoSig->update_data_param();
dsoSig->paint_prepare();
}
}
Expand Down
118 changes: 69 additions & 49 deletions DSView/src/view/dsosignal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,55 +812,7 @@ void DsoSignal::paint_mid(QPainter &p, int left, int right, QColor fore, QColor
paint_envelope(p, _data, zeroY, left,
start_sample, end_sample, hw_offset,
pixels_offset, samples_per_pixel, enabled_channels);
}

sr_status status;

if (session->get_device()->get_device_status(status, false)) {
_mValid = true;
if (status.measure_valid) {
_min = (index == 0) ? status.ch0_min : status.ch1_min;
_max = (index == 0) ? status.ch0_max : status.ch1_max;

_level_valid = (index == 0) ? status.ch0_level_valid : status.ch1_level_valid;
_low = (index == 0) ? status.ch0_low_level : status.ch1_low_level;
_high = (index == 0) ? status.ch0_high_level : status.ch1_high_level;

const uint32_t count = (index == 0) ? status.ch0_cyc_cnt : status.ch1_cyc_cnt;
const bool plevel = (index == 0) ? status.ch0_plevel : status.ch1_plevel;
const bool startXORend = (index == 0) ? (status.ch0_cyc_llen == 0) : (status.ch1_cyc_llen == 0);
uint16_t total_channels = g_slist_length(session->get_device()->get_channels());

if (total_channels == 1 && _data->is_file()){
total_channels++;
}

const double tfactor = (total_channels / enabled_channels) * SR_GHZ(1) * 1.0 / samplerate;

double samples = (index == 0) ? status.ch0_cyc_tlen : status.ch1_cyc_tlen;
_period = ((count == 0) ? 0 : samples / count) * tfactor;

samples = (index == 0) ? status.ch0_cyc_flen : status.ch1_cyc_flen;
_rise_time = ((count == 0) ? 0 : samples / ((plevel && startXORend) ? count : count + 1)) * tfactor;
samples = (index == 0) ? status.ch0_cyc_rlen : status.ch1_cyc_rlen;
_fall_time = ((count == 0) ? 0 : samples / ((!plevel && startXORend) ? count : count + 1)) * tfactor;

samples = (index == 0) ? (status.ch0_plevel ? status.ch0_cyc_plen - status.ch0_cyc_llen :
status.ch0_cyc_tlen - status.ch0_cyc_plen + status.ch0_cyc_llen) :
(status.ch1_plevel ? status.ch1_cyc_plen - status.ch1_cyc_llen :
status.ch1_cyc_tlen - status.ch1_cyc_plen + status.ch1_cyc_llen);
_high_time = ((count == 0) ? 0 : samples / count) * tfactor;

samples = (index == 0) ? status.ch0_cyc_tlen + status.ch0_cyc_llen : status.ch1_cyc_flen + status.ch1_cyc_llen;
_burst_time = samples * tfactor;

_pcount = count + (plevel & !startXORend);
_rms = (index == 0) ? status.ch0_acc_square : status.ch1_acc_square;
_rms = sqrt(_rms / _data->get_sample_count());
_mean = (index == 0) ? status.ch0_acc_mean : status.ch1_acc_mean;
_mean = hw_offset - _mean / _data->get_sample_count();
}
}
}
}
}

Expand Down Expand Up @@ -1548,5 +1500,73 @@ void DsoSignal::set_data(data::DsoSnapshot *data)
_data = data;
}

void DsoSignal::update_data_param()
{
const uint16_t enabled_channels = _data->get_channel_num();
int index = get_index();
const double samplerate = _data->samplerate();
const int hw_offset = get_hw_offset();

sr_status status;

if (session->get_device()->get_device_status(status, false)) {
_mValid = true;
if (status.measure_valid) {
_min = (index == 0) ? status.ch0_min : status.ch1_min;
_max = (index == 0) ? status.ch0_max : status.ch1_max;

/*
if (index == 0){
dsv_info("get min0:%d", status.ch0_min);
dsv_info("get max0:%d", status.ch0_max);
}
else{
dsv_info("get min1:%d", status.ch1_min);
dsv_info("get max1:%d", status.ch1_max);
}
*/

_level_valid = (index == 0) ? status.ch0_level_valid : status.ch1_level_valid;
_low = (index == 0) ? status.ch0_low_level : status.ch1_low_level;
_high = (index == 0) ? status.ch0_high_level : status.ch1_high_level;

const uint32_t count = (index == 0) ? status.ch0_cyc_cnt : status.ch1_cyc_cnt;
const bool plevel = (index == 0) ? status.ch0_plevel : status.ch1_plevel;
const bool startXORend = (index == 0) ? (status.ch0_cyc_llen == 0) : (status.ch1_cyc_llen == 0);
uint16_t total_channels = g_slist_length(session->get_device()->get_channels());

if (total_channels == 1 && _data->is_file()){
total_channels++;
}

const double tfactor = (total_channels / enabled_channels) * SR_GHZ(1) * 1.0 / samplerate;

double samples = (index == 0) ? status.ch0_cyc_tlen : status.ch1_cyc_tlen;
_period = ((count == 0) ? 0 : samples / count) * tfactor;

samples = (index == 0) ? status.ch0_cyc_flen : status.ch1_cyc_flen;
_rise_time = ((count == 0) ? 0 : samples / ((plevel && startXORend) ? count : count + 1)) * tfactor;
samples = (index == 0) ? status.ch0_cyc_rlen : status.ch1_cyc_rlen;
_fall_time = ((count == 0) ? 0 : samples / ((!plevel && startXORend) ? count : count + 1)) * tfactor;

samples = (index == 0) ? (status.ch0_plevel ? status.ch0_cyc_plen - status.ch0_cyc_llen :
status.ch0_cyc_tlen - status.ch0_cyc_plen + status.ch0_cyc_llen) :
(status.ch1_plevel ? status.ch1_cyc_plen - status.ch1_cyc_llen :
status.ch1_cyc_tlen - status.ch1_cyc_plen + status.ch1_cyc_llen);
_high_time = ((count == 0) ? 0 : samples / count) * tfactor;

samples = (index == 0) ? status.ch0_cyc_tlen + status.ch0_cyc_llen : status.ch1_cyc_flen + status.ch1_cyc_llen;
_burst_time = samples * tfactor;

_pcount = count + (plevel & !startXORend);
_rms = (index == 0) ? status.ch0_acc_square : status.ch1_acc_square;
_rms = sqrt(_rms / _data->get_sample_count());
_mean = (index == 0) ? status.ch0_acc_mean : status.ch1_acc_mean;
_mean = hw_offset - _mean / _data->get_sample_count();
}
}
}

} // namespace view
} // namespace dsv
2 changes: 2 additions & 0 deletions DSView/src/view/dsosignal.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ class DsoSignal : public Signal
_stop_scale = v;
}

void update_data_param();

protected:
void paint_type_options(QPainter &p, int right, const QPoint pt, QColor fore);

Expand Down
1 change: 1 addition & 0 deletions libsigrok4DSL/hardware/DSL/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#define EI2C_ADDR 0x60
#define ADCC_ADDR 0x48
#define HDL_VERSION_ADDR 0x04
#define HW_STATUS_ADDR 0x05

#define bmSECU_READY (1 << 3)
#define bmSECU_PASS (1 << 4)
Expand Down
8 changes: 8 additions & 0 deletions libsigrok4DSL/hardware/DSL/dscope.c
Original file line number Diff line number Diff line change
Expand Up @@ -2113,6 +2113,7 @@ static int dev_acquisition_start(struct sr_dev_inst *sdi, void *cb_data)
return SR_OK;
}

/*
static int dev_acquisition_stop(const struct sr_dev_inst *sdi, void *cb_data)
{
struct DSL_context *devc = sdi->priv;
Expand All @@ -2122,6 +2123,13 @@ static int dev_acquisition_stop(const struct sr_dev_inst *sdi, void *cb_data)
}
return ret;
}
*/

static int dev_acquisition_stop(const struct sr_dev_inst *sdi, void *cb_data)
{
int ret = dsl_dev_acquisition_stop(sdi, cb_data);
return ret;
}

static int dev_status_get(const struct sr_dev_inst *sdi, struct sr_status *status, gboolean prg)
{
Expand Down
21 changes: 20 additions & 1 deletion libsigrok4DSL/hardware/DSL/dsl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2025,6 +2025,20 @@ SR_PRIV int dsl_dev_acquisition_stop(const struct sr_dev_inst *sdi, void *cb_dat
sr_err("%s: Sent acquisition stop command failed!", __func__);
else
sr_info("%s: Sent acquisition stop command!", __func__);

/* check a real stop of FPGA status*/
uint8_t hw_status = 1;
while (hw_status != 0) {
if (dsl_rd_reg(sdi, HW_STATUS_ADDR, &hw_status) != SR_OK)
sr_err("%s: Get hardware status command failed!", __func__);
else
sr_info("%s: Get hardware status command!", __func__);
}

/* adc power down*/
if (devc->profile->dev_caps.feature_caps & CAPS_FEATURE_HMCAD1511) {
dsl_config_adc(sdi, adc_power_down);
}
}

return SR_OK;
Expand Down Expand Up @@ -2391,8 +2405,13 @@ static void receive_transfer(struct libusb_transfer *transfer)
}

/* send data to session bus */
if (packet.status == SR_PKT_OK)
if (packet.status == SR_PKT_OK){
// sr_info("cur min0:%d", devc->mstatus.ch0_min);
// sr_info("cur max0:%d", devc->mstatus.ch0_max);
// sr_info("cur min1:%d", devc->mstatus.ch1_min);
// sr_info("cur max1:%d", devc->mstatus.ch1_max);
ds_data_forward(sdi, &packet);
}
}

devc->num_samples += cur_sample_count;
Expand Down

0 comments on commit a36a71d

Please sign in to comment.