Added limit samples Eveything seems to work find up to 1024 samples

This commit is contained in:
lelazary 2013-01-07 07:49:31 -08:00 committed by Uwe Hermann
parent 087a9161ff
commit eb913174ab
3 changed files with 24 additions and 26 deletions

View File

@ -240,7 +240,6 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
static int hw_dev_close(struct sr_dev_inst *sdi) static int hw_dev_close(struct sr_dev_inst *sdi)
{ {
printf("dev close\n");
struct dev_context *devc; struct dev_context *devc;
devc = sdi->priv; devc = sdi->priv;
@ -340,14 +339,26 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
ret = SR_OK; ret = SR_OK;
break; break;
case SR_HWCAP_LIMIT_SAMPLES: case SR_HWCAP_LIMIT_SAMPLES:
ret = SR_OK; {
const uint64_t num_samples = *(const uint64_t *)value;
if (num_samples < 1024)
{
sr_err("minimum of 1024 samples required");
ret = SR_ERR_ARG;
} else {
devc->limit_samples = num_samples;
sr_dbg("setting limit_samples to %i\n", num_samples);
ret = SR_OK;
}
}
break; break;
case SR_HWCAP_CAPTURE_RATIO: case SR_HWCAP_CAPTURE_RATIO:
ret = SR_OK; ret = SR_OK;
break; break;
case SR_HWCAP_TRIGGER_SLOPE: case SR_HWCAP_TRIGGER_SLOPE:
{ {
uint64_t slope = *(const uint64_t *)value; const uint64_t slope = *(const uint64_t *)value;
if (slope != SLOPE_NEGATIVE && slope != SLOPE_POSITIVE) if (slope != SLOPE_NEGATIVE && slope != SLOPE_POSITIVE)
{ {
sr_err("Invalid trigger slope"); sr_err("Invalid trigger slope");
@ -360,13 +371,12 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
break; break;
case SR_HWCAP_HORIZ_TRIGGERPOS: case SR_HWCAP_HORIZ_TRIGGERPOS:
{ {
float pos = *(const float *)value; const float pos = *(const float *)value;
if (pos < 0 || pos > 255) { if (pos < 0 || pos > 255) {
sr_err("Trigger position (%f) should be between 0 and 255.", pos); sr_err("Trigger position (%f) should be between 0 and 255.", pos);
ret = SR_ERR_ARG; ret = SR_ERR_ARG;
} else { } else {
int trigger_pos = (int)pos; int trigger_pos = (int)pos;
printf("Set trigger posion to %X\n", trigger_pos&0xff);
devc->trigger_holdoff[0] = trigger_pos&0xff; devc->trigger_holdoff[0] = trigger_pos&0xff;
ret = SR_OK; ret = SR_OK;
} }
@ -393,7 +403,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
int ret = SR_ERR; int ret = SR_ERR;
printf("Accquistion start\n");
devc = sdi->priv; devc = sdi->priv;
if (sdi->status != SR_ST_ACTIVE) if (sdi->status != SR_ST_ACTIVE)
@ -413,24 +422,20 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
devc->ctlbase1 &= 0x7f; devc->ctlbase1 &= 0x7f;
// devc->ctlbase1 |= devc->acdcmode; // devc->ctlbase1 |= devc->acdcmode;
printf("Configure rate\n");
ret = mso_configure_rate(sdi, devc->cur_rate); ret = mso_configure_rate(sdi, devc->cur_rate);
if (ret != SR_OK) if (ret != SR_OK)
return ret; return ret;
/* set dac offset */ /* set dac offset */
printf("Configure dac\n");
ret = mso_dac_out(sdi, devc->dac_offset); ret = mso_dac_out(sdi, devc->dac_offset);
if (ret != SR_OK) if (ret != SR_OK)
return ret; return ret;
printf("Configure threshold level\n");
ret = mso_configure_threshold_level(sdi); ret = mso_configure_threshold_level(sdi);
if (ret != SR_OK) if (ret != SR_OK)
return ret; return ret;
printf("Configure trigger\n");
ret = mso_configure_trigger(sdi); ret = mso_configure_trigger(sdi);
if (ret != SR_OK) if (ret != SR_OK)
return ret; return ret;
@ -442,16 +447,13 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
return ret; return ret;
/* Start acquisition on the device. */ /* Start acquisition on the device. */
printf("Check trigger\n");
mso_check_trigger(devc->serial, &devc->trigger_state); mso_check_trigger(devc->serial, &devc->trigger_state);
ret = mso_check_trigger(devc->serial, NULL); ret = mso_check_trigger(devc->serial, NULL);
if (ret != SR_OK) if (ret != SR_OK)
return ret; return ret;
printf("Source add\n");
sr_source_add(devc->serial->fd, G_IO_IN, -1, mso_receive_data, cb_data); sr_source_add(devc->serial->fd, G_IO_IN, -1, mso_receive_data, cb_data);
printf("Create packet\n");
if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) { if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
sr_err("Datafeed packet malloc failed."); sr_err("Datafeed packet malloc failed.");
return SR_ERR_MALLOC; return SR_ERR_MALLOC;
@ -463,6 +465,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
return SR_ERR_MALLOC; return SR_ERR_MALLOC;
} }
packet->type = SR_DF_HEADER; packet->type = SR_DF_HEADER;
packet->payload = (unsigned char *)header; packet->payload = (unsigned char *)header;
header->feed_version = 1; header->feed_version = 1;

View File

@ -387,9 +387,7 @@ SR_PRIV int mso_receive_data(int fd, int revents, void *cb_data)
* to read the data */ * to read the data */
if (devc->trigger_state != MSO_TRIGGER_DATAREADY) { if (devc->trigger_state != MSO_TRIGGER_DATAREADY) {
devc->trigger_state = in[0]; devc->trigger_state = in[0];
//printf("Got %c for trigger \n", in[0]);
if (devc->trigger_state == MSO_TRIGGER_DATAREADY) { if (devc->trigger_state == MSO_TRIGGER_DATAREADY) {
//printf("Trigger is ready %c\n", MSO_TRIGGER_DATAREADY);
mso_read_buffer(sdi); mso_read_buffer(sdi);
devc->buffer_n = 0; devc->buffer_n = 0;
} else { } else {
@ -406,7 +404,6 @@ SR_PRIV int mso_receive_data(int fd, int revents, void *cb_data)
if (devc->buffer_n < 3072) if (devc->buffer_n < 3072)
return TRUE; return TRUE;
printf("Got samples, write out the data\n");
/* do the conversion */ /* do the conversion */
uint8_t logic_out[1024]; uint8_t logic_out[1024];
double analog_out[1024]; double analog_out[1024];
@ -423,9 +420,10 @@ SR_PRIV int mso_receive_data(int fd, int revents, void *cb_data)
logic.length = 1024; logic.length = 1024;
logic.unitsize = 1; logic.unitsize = 1;
logic.data = logic_out; logic.data = logic_out;
printf("Send Data\n");
sr_session_send(cb_data, &packet); sr_session_send(cb_data, &packet);
devc->num_samples += 1024;
// Dont bother fixing this yet, keep it "old style" // Dont bother fixing this yet, keep it "old style"
/* /*
packet.type = SR_DF_ANALOG; packet.type = SR_DF_ANALOG;
@ -435,16 +433,11 @@ SR_PRIV int mso_receive_data(int fd, int revents, void *cb_data)
sr_session_send(ctx->session_dev_id, &packet); sr_session_send(ctx->session_dev_id, &packet);
*/ */
//printf("Send END\n"); if (devc->limit_samples && devc->num_samples >= devc->limit_samples) {
//packet.type = SR_DF_END; sr_info("Requested number of samples reached.");
//sr_session_send(devc->session_dev_id, &packet); sdi->driver->dev_acquisition_stop(sdi, cb_data);
}
// serial_flush(devc->serial);
// abort_acquisition(sdi);
// serial_close(devc->serial);
return FALSE;
printf("REturn \n");
return TRUE; return TRUE;
} }

View File

@ -100,6 +100,8 @@ struct dev_context {
double vbit; double vbit;
uint16_t dac_offset; uint16_t dac_offset;
uint16_t offset_range; uint16_t offset_range;
uint64_t limit_samples;
uint64_t num_samples;
/* register cache */ /* register cache */
uint8_t ctlbase1; uint8_t ctlbase1;
uint8_t ctlbase2; uint8_t ctlbase2;