hantek-dso: dso2250: Support sample rates correctly.
Fast mode not done yet, only 125MHz allowed right now.
This commit is contained in:
parent
3b2b703177
commit
11e3319656
|
@ -130,6 +130,28 @@ static const uint64_t timebases[][2] = {
|
||||||
{ 400, 1000 },
|
{ 400, 1000 },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const uint64_t samplerates[] = {
|
||||||
|
SR_KHZ(20),
|
||||||
|
SR_KHZ(25),
|
||||||
|
SR_KHZ(50),
|
||||||
|
SR_KHZ(100),
|
||||||
|
SR_KHZ(200),
|
||||||
|
SR_KHZ(250),
|
||||||
|
SR_KHZ(500),
|
||||||
|
SR_MHZ(1),
|
||||||
|
SR_MHZ(2),
|
||||||
|
SR_MHZ(5),
|
||||||
|
SR_MHZ(10),
|
||||||
|
SR_MHZ(20),
|
||||||
|
SR_MHZ(25),
|
||||||
|
SR_MHZ(50),
|
||||||
|
SR_MHZ(100),
|
||||||
|
SR_MHZ(125),
|
||||||
|
/* fast mode not supported yet
|
||||||
|
SR_MHZ(200),
|
||||||
|
SR_MHZ(250), */
|
||||||
|
};
|
||||||
|
|
||||||
static const uint64_t vdivs[][2] = {
|
static const uint64_t vdivs[][2] = {
|
||||||
/* millivolts */
|
/* millivolts */
|
||||||
{ 10, 1000 },
|
{ 10, 1000 },
|
||||||
|
@ -186,6 +208,7 @@ static struct sr_dev_inst *dso_dev_new(const struct dso_profile *prof)
|
||||||
devc->profile = prof;
|
devc->profile = prof;
|
||||||
devc->dev_state = IDLE;
|
devc->dev_state = IDLE;
|
||||||
devc->timebase = DEFAULT_TIMEBASE;
|
devc->timebase = DEFAULT_TIMEBASE;
|
||||||
|
devc->samplerate = DEFAULT_SAMPLERATE;
|
||||||
devc->ch_enabled[0] = TRUE;
|
devc->ch_enabled[0] = TRUE;
|
||||||
devc->ch_enabled[1] = TRUE;
|
devc->ch_enabled[1] = TRUE;
|
||||||
devc->voltage[0] = DEFAULT_VOLTAGE;
|
devc->voltage[0] = DEFAULT_VOLTAGE;
|
||||||
|
@ -432,9 +455,7 @@ static int config_get(uint32_t key, GVariant **data,
|
||||||
timebases[devc->timebase][1]);
|
timebases[devc->timebase][1]);
|
||||||
break;
|
break;
|
||||||
case SR_CONF_SAMPLERATE:
|
case SR_CONF_SAMPLERATE:
|
||||||
*data = g_variant_new_uint64(
|
*data = g_variant_new_uint64(devc->samplerate);
|
||||||
timebases[devc->timebase][1]/
|
|
||||||
timebases[devc->timebase][0]);
|
|
||||||
break;
|
break;
|
||||||
case SR_CONF_BUFFERSIZE:
|
case SR_CONF_BUFFERSIZE:
|
||||||
*data = g_variant_new_uint64(devc->framesize);
|
*data = g_variant_new_uint64(devc->framesize);
|
||||||
|
@ -512,6 +533,13 @@ static int config_set(uint32_t key, GVariant *data,
|
||||||
return SR_ERR_ARG;
|
return SR_ERR_ARG;
|
||||||
devc->timebase = idx;
|
devc->timebase = idx;
|
||||||
break;
|
break;
|
||||||
|
case SR_CONF_SAMPLERATE:
|
||||||
|
if ((idx = std_u64_idx(data, ARRAY_AND_SIZE(samplerates))) < 0)
|
||||||
|
return SR_ERR_ARG;
|
||||||
|
devc->samplerate = samplerates[idx];
|
||||||
|
if (dso_set_trigger_samplerate(sdi) != SR_OK)
|
||||||
|
return SR_ERR;
|
||||||
|
break;
|
||||||
case SR_CONF_TRIGGER_SOURCE:
|
case SR_CONF_TRIGGER_SOURCE:
|
||||||
if ((idx = std_str_idx(data, ARRAY_AND_SIZE(trigger_sources))) < 0)
|
if ((idx = std_str_idx(data, ARRAY_AND_SIZE(trigger_sources))) < 0)
|
||||||
return SR_ERR_ARG;
|
return SR_ERR_ARG;
|
||||||
|
@ -565,6 +593,9 @@ static int config_list(uint32_t key, GVariant **data,
|
||||||
devc = sdi->priv;
|
devc = sdi->priv;
|
||||||
*data = std_gvar_array_u64(devc->profile->buffersizes, NUM_BUFFER_SIZES);
|
*data = std_gvar_array_u64(devc->profile->buffersizes, NUM_BUFFER_SIZES);
|
||||||
break;
|
break;
|
||||||
|
case SR_CONF_SAMPLERATE:
|
||||||
|
*data = std_gvar_samplerates(ARRAY_AND_SIZE(samplerates));
|
||||||
|
break;
|
||||||
case SR_CONF_TIMEBASE:
|
case SR_CONF_TIMEBASE:
|
||||||
*data = std_gvar_tuple_array(ARRAY_AND_SIZE(timebases));
|
*data = std_gvar_tuple_array(ARRAY_AND_SIZE(timebases));
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -303,20 +303,17 @@ static int dso2250_set_trigger_samplerate(const struct sr_dev_inst *sdi)
|
||||||
|
|
||||||
memset(cmdstring, 0, sizeof(cmdstring));
|
memset(cmdstring, 0, sizeof(cmdstring));
|
||||||
cmdstring[0] = CMD_2250_SET_SAMPLERATE;
|
cmdstring[0] = CMD_2250_SET_SAMPLERATE;
|
||||||
/* Timebase fast */
|
sr_dbg("Sample rate: %u", devc->samplerate);
|
||||||
sr_dbg("Time base index: %d.", devc->timebase);
|
|
||||||
base = 100e6;
|
base = 100e6;
|
||||||
if (devc->timebase < TIME_40us) {
|
if (devc->samplerate > base) {
|
||||||
if (devc->framesize != FRAMESIZE_SMALL) {
|
/* Timebase fast */
|
||||||
sr_err("Timebase < 40us only supported with 10K buffer.");
|
sr_err("Sample rate > 100MHz not yet supported.");
|
||||||
return SR_ERR_ARG;
|
return SR_ERR_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fast mode on */
|
tmp = base / devc->samplerate;
|
||||||
base = 200e6;
|
sr_dbg("sample rate value: %d.", devc->samplerate);
|
||||||
cmdstring[2] |= 1;
|
if (tmp) {
|
||||||
}
|
|
||||||
|
|
||||||
/* Downsampling on */
|
/* Downsampling on */
|
||||||
cmdstring[2] |= 2;
|
cmdstring[2] |= 2;
|
||||||
/* Downsampler = 1comp((Base / Samplerate) - 2)
|
/* Downsampler = 1comp((Base / Samplerate) - 2)
|
||||||
|
@ -326,18 +323,12 @@ static int dso2250_set_trigger_samplerate(const struct sr_dev_inst *sdi)
|
||||||
* 100e6 / 500e3 => 200
|
* 100e6 / 500e3 => 200
|
||||||
* 200 - 2 => 198
|
* 200 - 2 => 198
|
||||||
* 1comp(198) => ff39 */
|
* 1comp(198) => ff39 */
|
||||||
|
|
||||||
tmp = base * timebase_to_time(devc->timebase);
|
|
||||||
tmp = 200;
|
|
||||||
if (tmp < 0)
|
|
||||||
return SR_ERR_ARG;
|
|
||||||
tmp -= 2;
|
tmp -= 2;
|
||||||
if (tmp < 0)
|
|
||||||
return SR_ERR_ARG;
|
|
||||||
tmp = ~tmp;
|
tmp = ~tmp;
|
||||||
sr_dbg("sample rate value: 0x%x.", tmp & 0xffff);
|
sr_dbg("down sampler value: 0x%x.", tmp & 0xffff);
|
||||||
cmdstring[4] = (tmp >> 0) & 0xff;
|
cmdstring[4] = (tmp >> 0) & 0xff;
|
||||||
cmdstring[5] = (tmp >> 8) & 0xff;
|
cmdstring[5] = (tmp >> 8) & 0xff;
|
||||||
|
}
|
||||||
|
|
||||||
if (send_begin(sdi) != SR_OK)
|
if (send_begin(sdi) != SR_OK)
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
|
@ -375,7 +366,6 @@ static int dso2250_set_trigger_samplerate(const struct sr_dev_inst *sdi)
|
||||||
cmdstring[0] = CMD_2250_SET_TRIGGERPOS_AND_BUFFER;
|
cmdstring[0] = CMD_2250_SET_TRIGGERPOS_AND_BUFFER;
|
||||||
|
|
||||||
/* TODO for big buffer */
|
/* TODO for big buffer */
|
||||||
/* TODO */
|
|
||||||
sr_dbg("Trigger position: %3.2f.", devc->triggerposition);
|
sr_dbg("Trigger position: %3.2f.", devc->triggerposition);
|
||||||
// tmp = 0x77fff + 0x8000 * devc->triggerposition;
|
// tmp = 0x77fff + 0x8000 * devc->triggerposition;
|
||||||
// cmdstring[6] = tmp & 0xff;
|
// cmdstring[6] = tmp & 0xff;
|
||||||
|
@ -404,7 +394,7 @@ static int dso2250_set_trigger_samplerate(const struct sr_dev_inst *sdi)
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dso_set_trigger_samplerate(const struct sr_dev_inst *sdi)
|
int dso_set_trigger_samplerate(const struct sr_dev_inst *sdi)
|
||||||
{
|
{
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
struct sr_usb_dev_inst *usb;
|
struct sr_usb_dev_inst *usb;
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#define DEFAULT_VOLTAGE VDIV_500MV
|
#define DEFAULT_VOLTAGE VDIV_500MV
|
||||||
#define DEFAULT_FRAMESIZE FRAMESIZE_SMALL
|
#define DEFAULT_FRAMESIZE FRAMESIZE_SMALL
|
||||||
#define DEFAULT_TIMEBASE TIME_100us
|
#define DEFAULT_TIMEBASE TIME_100us
|
||||||
|
#define DEFAULT_SAMPLERATE SR_KHZ(10)
|
||||||
#define DEFAULT_TRIGGER_SOURCE "CH1"
|
#define DEFAULT_TRIGGER_SOURCE "CH1"
|
||||||
#define DEFAULT_COUPLING COUPLING_DC
|
#define DEFAULT_COUPLING COUPLING_DC
|
||||||
#define DEFAULT_HORIZ_TRIGGERPOS 0.5
|
#define DEFAULT_HORIZ_TRIGGERPOS 0.5
|
||||||
|
@ -187,6 +188,7 @@ struct dev_context {
|
||||||
int dev_state;
|
int dev_state;
|
||||||
|
|
||||||
/* Oscilloscope settings. */
|
/* Oscilloscope settings. */
|
||||||
|
int samplerate;
|
||||||
int timebase;
|
int timebase;
|
||||||
gboolean ch_enabled[2];
|
gboolean ch_enabled[2];
|
||||||
int voltage[2];
|
int voltage[2];
|
||||||
|
@ -220,5 +222,6 @@ SR_PRIV int dso_get_capturestate(const struct sr_dev_inst *sdi,
|
||||||
SR_PRIV int dso_capture_start(const struct sr_dev_inst *sdi);
|
SR_PRIV int dso_capture_start(const struct sr_dev_inst *sdi);
|
||||||
SR_PRIV int dso_get_channeldata(const struct sr_dev_inst *sdi,
|
SR_PRIV int dso_get_channeldata(const struct sr_dev_inst *sdi,
|
||||||
libusb_transfer_cb_fn cb);
|
libusb_transfer_cb_fn cb);
|
||||||
|
SR_PRIV int dso_set_trigger_samplerate(const struct sr_dev_inst *sdi);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue