fixed waiting for capture result status thing
This commit is contained in:
parent
192cb0d897
commit
243b525727
|
@ -84,6 +84,8 @@ static uint64_t dc_msec_to_samples(struct dev_context *dc, uint64_t msec)
|
|||
|
||||
static int dev_clear(const struct sr_dev_driver *di)
|
||||
{
|
||||
sr_err("clear");
|
||||
|
||||
return std_dev_clear_with_callback(di, (std_dev_clear_callback)sq_destroy);
|
||||
}
|
||||
|
||||
|
@ -98,6 +100,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
|
||||
(void)options;
|
||||
|
||||
sr_err("scan");
|
||||
|
||||
if (!(ft = ftdi_new())) {
|
||||
sr_err("Failed to initialize libftdi.");
|
||||
return NULL;
|
||||
|
@ -224,6 +228,8 @@ static int dev_open(struct sr_dev_inst *sdi)
|
|||
struct dev_context *dc;
|
||||
int rv;
|
||||
|
||||
sr_err("open");
|
||||
|
||||
dc = sdi->priv;
|
||||
|
||||
if (!dc || !dc->ft) return SR_ERR_BUG;
|
||||
|
@ -280,6 +286,8 @@ static int config_get(uint32_t key, GVariant **data,
|
|||
|
||||
(void)cg;
|
||||
|
||||
sr_err("get");
|
||||
|
||||
if (!dc) return SR_ERR_BUG;
|
||||
|
||||
rv = SR_OK;
|
||||
|
@ -315,6 +323,8 @@ static int config_set(uint32_t key, GVariant *data,
|
|||
|
||||
(void)cg;
|
||||
|
||||
sr_err("set");
|
||||
|
||||
if (!dc) return SR_ERR_BUG;
|
||||
|
||||
rv = SR_OK;
|
||||
|
@ -345,6 +355,8 @@ static int config_list(uint32_t key, GVariant **data,
|
|||
{
|
||||
int rv;
|
||||
|
||||
sr_err("list");
|
||||
|
||||
rv = SR_OK;
|
||||
switch (key) {
|
||||
case SR_CONF_DEVICE_OPTIONS:
|
||||
|
@ -368,6 +380,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
|||
|
||||
dc = sdi->priv;
|
||||
|
||||
sr_err("start");
|
||||
|
||||
if (!dc || !dc->ft) return SR_ERR_BUG;
|
||||
|
||||
rv = scanaquad_acquisition_start(dc);
|
||||
|
@ -388,13 +402,12 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi)
|
|||
|
||||
if (!dc || !dc->ft) return SR_ERR_BUG;
|
||||
|
||||
rv = scanaquad_acquisition_stop(sdi, dc);
|
||||
/* FIXME */
|
||||
/*CHECK_SQ_RETVAL(rv, "Failed to stop acquisition");*/
|
||||
|
||||
sr_session_source_remove(sdi->session, -1);
|
||||
std_session_send_df_end(sdi);
|
||||
|
||||
rv = scanaquad_acquisition_stop(sdi, dc);
|
||||
CHECK_SQ_RETVAL(rv, "Failed to stop acquisition");
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -240,45 +240,50 @@ SR_PRIV int sq_app_cancel_capture(struct dev_context *dc)
|
|||
|
||||
return SR_OK;
|
||||
}
|
||||
SR_PRIV struct ftdi_transfer_control *sq_app_start_capture(struct dev_context *dc, uint32_t *resbuf)
|
||||
SR_PRIV int sq_app_start_capture(struct dev_context *dc)
|
||||
{
|
||||
static const uint8_t send_start_capture_cmd[] = {0xf0,0x01};
|
||||
int rv;
|
||||
|
||||
if (!dc) return NULL;
|
||||
if (!dc) return SR_ERR_BUG;
|
||||
|
||||
sr_spew("sc/wft");
|
||||
|
||||
rv = ftdi_write_data(dc->ft, send_start_capture_cmd, sizeof send_start_capture_cmd);
|
||||
if (rv < 0) {
|
||||
sr_err("Failed to write FTDI data (%d): %s.\n", rv, ftdi_get_error_string(dc->ft));
|
||||
return NULL;
|
||||
} else if (rv != sizeof send_start_capture_cmd) {
|
||||
sr_err("FTDI write error, only %d/%zu bytes written: %s.", rv,
|
||||
sizeof send_start_capture_cmd, ftdi_get_error_string(dc->ft));
|
||||
return NULL;
|
||||
}
|
||||
CHECK_FTDI_RETVAL(TRUE, dc->ft, rv, sizeof send_start_capture_cmd);
|
||||
|
||||
return ftdi_read_data_submit(dc->ft, (uint8_t *)resbuf, 4);
|
||||
return SR_OK;
|
||||
}
|
||||
SR_PRIV int sq_app_get_capture_result(struct dev_context *dc, struct ftdi_transfer_control *tc, const uint8_t *tcbuf, uint32_t *trig_instant)
|
||||
SR_PRIV int sq_app_try_get_capture_result(struct dev_context *dc, uint32_t *trig_instant)
|
||||
{
|
||||
uint32_t ti;
|
||||
int rv;
|
||||
uint8_t result[4];
|
||||
int rv, todo, done;
|
||||
|
||||
if (!dc || !tc) return SR_ERR;
|
||||
if (!dc) return SR_ERR;
|
||||
|
||||
/* FIXME: don't block here! */
|
||||
//if (!tc->completed) return SR_ERR_ARG;
|
||||
rv = ftdi_transfer_data_done(tc);
|
||||
CHECK_FTDI_RETVAL(FALSE, dc->ft, rv, (size_t)4);
|
||||
todo = 4;
|
||||
done = 0;
|
||||
|
||||
ti = (uint32_t)tcbuf[0] | ((uint32_t)tcbuf[1] << 8) | ((uint32_t)tcbuf[2] << 16);
|
||||
rv = ftdi_read_data(dc->ft, &result[done], todo - done);
|
||||
CHECK_FTDI_RETVAL(FALSE, dc->ft, rv, (size_t)0, FALSE);
|
||||
|
||||
if (rv == 0) return SR_ERR_ARG;
|
||||
|
||||
done += rv;
|
||||
|
||||
while (done < todo) {
|
||||
rv = ftdi_read_data(dc->ft, &result[done], todo - done);
|
||||
CHECK_FTDI_RETVAL(FALSE, dc->ft, rv, (size_t)0, FALSE);
|
||||
done += rv;
|
||||
}
|
||||
|
||||
ti = (uint32_t)result[0] | ((uint32_t)result[1] << 8) | ((uint32_t)result[2] << 16);
|
||||
if (trig_instant) *trig_instant = ti;
|
||||
|
||||
sr_spew("sc/wft -> %06x %02x", ti, tcbuf[3]);
|
||||
sr_spew("sc/wft -> %06x %02x", ti, result[3]);
|
||||
|
||||
return tcbuf[3];
|
||||
return result[3];
|
||||
}
|
||||
SR_PRIV int sq_app_start_generate_inf(struct dev_context *dc)
|
||||
{
|
||||
|
@ -294,26 +299,19 @@ SR_PRIV int sq_app_start_generate_inf(struct dev_context *dc)
|
|||
|
||||
return SR_OK;
|
||||
}
|
||||
SR_PRIV struct ftdi_transfer_control *sq_app_start_capgenmix(struct dev_context *dc, uint32_t *resbuf)
|
||||
SR_PRIV int sq_app_start_capgenmix(struct dev_context *dc)
|
||||
{
|
||||
static const uint8_t send_start_capgenmix_cmd[] = {0xf0,0x03};
|
||||
int rv;
|
||||
|
||||
if (!dc) return NULL;
|
||||
if (!dc) return SR_ERR_BUG;
|
||||
|
||||
sr_spew("start mixed sc/g/wft");
|
||||
|
||||
rv = ftdi_write_data(dc->ft, send_start_capgenmix_cmd, sizeof send_start_capgenmix_cmd);
|
||||
if (rv < 0) {
|
||||
sr_err("Failed to write FTDI data (%d): %s.\n", rv, ftdi_get_error_string(dc->ft));
|
||||
return NULL;
|
||||
} else if (rv != sizeof send_start_capgenmix_cmd) {
|
||||
sr_err("FTDI write error, only %d/%zu bytes written: %s.", rv,
|
||||
sizeof send_start_capgenmix_cmd, ftdi_get_error_string(dc->ft));
|
||||
return NULL;
|
||||
}
|
||||
CHECK_FTDI_RETVAL(TRUE, dc->ft, rv, sizeof send_start_capgenmix_cmd);
|
||||
|
||||
return ftdi_read_data_submit(dc->ft, (uint8_t *)resbuf, 4);
|
||||
return SR_OK;
|
||||
}
|
||||
SR_PRIV int sq_app_upload_genpattern(struct dev_context *dc, const void *data, size_t len)
|
||||
{
|
||||
|
@ -472,6 +470,8 @@ SR_PRIV int sq_app_apply_default_settings(struct dev_context *dc)
|
|||
return SR_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* higher-level routines (finally) */
|
||||
SR_PRIV int scanaquad_init(struct dev_context *dc)
|
||||
{
|
||||
|
@ -543,17 +543,6 @@ SR_PRIV int scanaquad_cancel_all(struct dev_context *dc)
|
|||
|
||||
sr_spew("cancel everything");
|
||||
|
||||
if (dc->tc) {
|
||||
/* TODO: timeout? */
|
||||
ftdi_transfer_data_cancel(dc->tc, NULL);
|
||||
dc->tc = NULL;
|
||||
}
|
||||
if (dc->tcbuf) {
|
||||
g_free(dc->tcbuf);
|
||||
dc->tcbuf = NULL;
|
||||
}
|
||||
dc->tcsize = 0;
|
||||
|
||||
dc->acq_started = FALSE;
|
||||
|
||||
rv = sq_get_status(dc);
|
||||
|
@ -639,7 +628,7 @@ SR_PRIV int scanaquad_acquisition_start(struct dev_context *dc)
|
|||
|
||||
if (!dc) return SR_ERR;
|
||||
|
||||
if (dc->tc || dc->tcbuf || dc->acq_started) return SR_ERR_BUG;
|
||||
if (dc->acq_started) return SR_ERR_BUG;
|
||||
|
||||
sr_spew("data acquisition start");
|
||||
|
||||
|
@ -672,17 +661,8 @@ SR_PRIV int scanaquad_acquisition_start(struct dev_context *dc)
|
|||
rv = sq_app_cancel_capture(dc);
|
||||
CHECK_SQ_RETVAL(rv, "Failed to cancel ongoing ScanaQuad transfers");
|
||||
|
||||
dc->tcbuf = g_malloc0(4);
|
||||
dc->tcsize = 4;
|
||||
dc->tc = sq_app_start_capture(dc, (uint32_t *)dc->tcbuf);
|
||||
|
||||
if (!dc->tc) {
|
||||
sr_err("Couldn't start capture");
|
||||
g_free(dc->tcbuf);
|
||||
dc->tcbuf = NULL;
|
||||
dc->tcsize = 0;
|
||||
return SR_ERR;
|
||||
}
|
||||
rv = sq_app_start_capture(dc);
|
||||
CHECK_SQ_RETVAL(rv, "Failed to start capture");
|
||||
|
||||
dc->acq_started = TRUE;
|
||||
|
||||
|
@ -713,36 +693,12 @@ SR_PRIV int scanaquad_acquisition_finish(struct sr_dev_inst *sdi, struct dev_con
|
|||
uint32_t trig_instant;
|
||||
int rv;
|
||||
|
||||
if (!dc || !dc->tc) return SR_ERR_BUG;
|
||||
if (!dc || !dc->acq_started) return SR_ERR_BUG;
|
||||
|
||||
sr_spew("gracefully finish acquisition");
|
||||
|
||||
/* FIXME: handle this in a better way wrt. sq_app_get_capture_result */
|
||||
/*rv = ftdi_transfer_data_done(dc->tc);
|
||||
dc->tc = NULL;
|
||||
if (rv < 0) {
|
||||
sr_err("Coudln't read async FTDI device status (%d): %s",
|
||||
rv, ftdi_get_error_string(dc->ft));
|
||||
|
||||
g_free(dc->tcbuf);
|
||||
dc->tcbuf = 0;
|
||||
dc->tcsize = 0;
|
||||
return SR_ERR;
|
||||
} else if (rv != 4) {
|
||||
sr_err("Unexpected async FTDI transfer size %d: %s",
|
||||
rv, ftdi_get_error_string(dc->ft));
|
||||
|
||||
g_free(dc->tcbuf);
|
||||
dc->tcbuf = 0;
|
||||
dc->tcsize = 0;
|
||||
return SR_ERR;
|
||||
}*/
|
||||
|
||||
trig_instant = dc->trig_instant;
|
||||
g_free(dc->tcbuf);
|
||||
dc->tcbuf = 0;
|
||||
dc->tcsize = 0;
|
||||
dc->tc = NULL; /* FIXME */
|
||||
dc->acq_started = FALSE;
|
||||
|
||||
sr_spew("trig_instant = %u", trig_instant);
|
||||
|
||||
|
@ -808,20 +764,24 @@ SR_PRIV int scanaquad_acquisition_stop(struct sr_dev_inst *sdi, struct dev_conte
|
|||
int rv;
|
||||
|
||||
sr_spew("force-stop acquisition");
|
||||
/* FIXME: stuff below errors. */
|
||||
|
||||
rv = sq_app_get_capture_result(dc, dc->tc, dc->tcbuf, &dc->trig_instant);
|
||||
if (!dc->acq_started) {
|
||||
sr_spew("already stopped");
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
rv = sq_app_try_get_capture_result(dc, &dc->trig_instant);
|
||||
if (rv == SR_ERR_ARG) { /* still busy */
|
||||
return scanaquad_acquisition_stop(sdi, dc);
|
||||
} else if (rv < SR_OK) {
|
||||
/* FIXME: stuff below errors. */
|
||||
sr_info("Canceling capture");
|
||||
return scanaquad_cancel_all(dc);
|
||||
} else if (rv < 0) {
|
||||
sr_err("Cannot get device state / capture result");
|
||||
return SR_ERR;
|
||||
} else if (rv == SQ_APP_START_CAPTURE_SUCCESS) {
|
||||
return scanaquad_acquisition_finish(sdi, dc);
|
||||
} else {
|
||||
sr_err("Acquisition failed");
|
||||
return SR_ERR;
|
||||
sr_err("Error during capture: %02x", rv);
|
||||
return SR_ERR_BUG;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -832,6 +792,7 @@ SR_PRIV int scanaquad_receive_data(int fd, int revents, void *cb_data)
|
|||
int rv;
|
||||
|
||||
(void)fd;
|
||||
(void)revents;
|
||||
|
||||
/*sr_spew("receive data");*/
|
||||
|
||||
|
@ -841,11 +802,11 @@ SR_PRIV int scanaquad_receive_data(int fd, int revents, void *cb_data)
|
|||
|
||||
/*if (revents != G_IO_IN) return TRUE;*/
|
||||
|
||||
rv = sq_app_get_capture_result(dc, dc->tc, dc->tcbuf, &dc->trig_instant);
|
||||
rv = sq_app_try_get_capture_result(dc, &dc->trig_instant);
|
||||
if (rv == SR_ERR_ARG) { /* still busy */
|
||||
sr_spew("Acquisition still busy...");
|
||||
return TRUE;
|
||||
} else if (rv < SR_OK) {
|
||||
} else if (rv < 0) {
|
||||
sr_err("Cannot get device state / capture result");
|
||||
sr_dev_acquisition_stop(sdi);
|
||||
return FALSE;
|
||||
|
@ -861,7 +822,7 @@ SR_PRIV int scanaquad_receive_data(int fd, int revents, void *cb_data)
|
|||
sr_dev_acquisition_stop(sdi);
|
||||
return TRUE;
|
||||
} else {
|
||||
sr_err("Acquisition failed");
|
||||
sr_err("Error during acquisition: %02x", rv);
|
||||
sr_dev_acquisition_stop(sdi);
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
@ -40,17 +40,14 @@
|
|||
struct dev_context {
|
||||
struct ftdi_context *ft;
|
||||
|
||||
struct ftdi_transfer_control *tc;
|
||||
uint8_t *tcbuf;
|
||||
size_t tcsize;
|
||||
uint32_t trig_instant;
|
||||
|
||||
/* settings for next capture */
|
||||
uint64_t samplerate;
|
||||
uint64_t limit_samples; /* samples */
|
||||
uint64_t capture_ratio; /* 0..100? MAYBE? */
|
||||
float voltage;
|
||||
|
||||
uint32_t trig_instant;
|
||||
|
||||
uint32_t MS_capture;
|
||||
uint32_t MS_generate;
|
||||
|
||||
|
@ -127,12 +124,12 @@ static inline int sq_bl_spi_xfer_read(struct dev_context *dc)
|
|||
/* application mode commands */
|
||||
/* 0xf0 0x0X commands */
|
||||
SR_PRIV int sq_app_cancel_capture(struct dev_context *dc);
|
||||
SR_PRIV struct ftdi_transfer_control *sq_app_start_capture(struct dev_context *dc, uint32_t *resbuf);
|
||||
SR_PRIV int sq_app_get_capture_result(struct dev_context *dc, struct ftdi_transfer_control *tc, const uint8_t *tcbuf, uint32_t *trig_instant);
|
||||
SR_PRIV int sq_app_start_capture(struct dev_context *dc);
|
||||
SR_PRIV int sq_app_try_get_capture_result(struct dev_context *dc, uint32_t *trig_instant);
|
||||
SR_PRIV int sq_app_start_generate_inf(struct dev_context *dc);
|
||||
SR_PRIV struct ftdi_transfer_control *sq_app_start_capgenmix(struct dev_context *dc, uint32_t *resbuf);
|
||||
static inline int sq_app_get_capgenmix_result(struct dev_context *dc, struct ftdi_transfer_control *tc, const uint8_t *tcbuf, uint32_t *trig_instant) {
|
||||
return sq_app_get_capture_result(dc, tc, tcbuf, trig_instant);
|
||||
SR_PRIV int sq_app_start_capgenmix(struct dev_context *dc);
|
||||
static inline int sq_app_try_get_capgenmix_result(struct dev_context *dc, uint32_t *trig_instant) {
|
||||
return sq_app_try_get_capture_result(dc, trig_instant);
|
||||
}
|
||||
/* NOTE: at this point, no checks are done whether the length of the data is
|
||||
* consistent with the current capture/genpattern memory size in the
|
||||
|
|
Loading…
Reference in New Issue