it runs now

This commit is contained in:
Triss 2021-06-26 00:42:56 +02:00
parent 32817ebeaa
commit 78cf266f90
2 changed files with 48 additions and 19 deletions

View File

@ -118,10 +118,30 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
if (rv != -3) { /* -3: device not found */
sr_err("Failed to open device (%d): %s", rv, ftdi_get_error_string(ft));
sq_destroy(dc);
g_free(dc);
return NULL;
}
}
rv = ftdi_read_eeprom(ft);
if (rv < 0) {
sr_err("Failted to read FTDI EEPROM (%d): %s", rv, ftdi_get_error_string(ft));
sq_destroy(dc);
g_free(dc);
return NULL;
}
rv = ftdi_eeprom_decode(ft, 0);
/* retval -1 means a checksum error, which current libftdi
* is not equipped to deal with yet, as it only knows of the
* FT230X, while the SQ uses an FT240X */
if (rv < 0) {
sr_err("Failed to decode FTDI EEPROM (%d): %s", rv, ftdi_get_error_string(ft));
sq_destroy(dc);
g_free(dc);
return NULL;
}
manuf = g_malloc0(256);
prod = g_malloc0(256);
serial = g_malloc0(256);
@ -132,12 +152,13 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
g_free(prod );
g_free(manuf );
sq_destroy(dc);
g_free(dc);
return NULL;
}
ftdi_usb_close(ft); /* enough for now */
if (!strcmp(manuf, "IKALOGIC")) {
if (strcmp(manuf, "IKALOGIC")) {
sr_warn("Unexpected manufacturer name %s!", manuf);
}
@ -164,7 +185,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
}
dc->limit_samples = dc->memsize_max;
sr_info("ScanaQuad serial number: %s", serial);
sr_info("%s ScanaQuad serial number: %s", manuf, serial);
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
@ -185,7 +206,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
#define CHECK_FTDI_RETVAL(msg, ft, rv) \
do { \
if ((rv) < 0) { \
sr_err(msg " (%d): %s.\n", (rv), ftdi_get_error_string(ft)); \
sr_err(msg " in %s (%d): %s.\n", __func__, (rv), ftdi_get_error_string(ft)); \
return SR_ERR; \
} \
} while (0) \
@ -193,7 +214,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
#define CHECK_SQ_RETVAL(rv, msg) \
do { \
if ((rv) < 0) { \
sr_err(msg " (%d).\n", (rv)); \
sr_err(msg "in %s (%d).\n", __func__, (rv)); \
return SR_ERR; \
} \
} while (0) \

View File

@ -45,17 +45,17 @@ SR_PRIV void sq_destroy(struct dev_context *dc)
ftdi_free(dc->ft);
dc->ft = NULL;
}
g_free(dc);
/*g_free(dc);*/
}
#define CHECK_FTDI_RETVAL(write, ft, rv, expect, ...) \
do { \
if ((rv) < 0) { \
sr_err("Failed to %s FTDI data (%d): %s.\n", (write)?"write":"read", (rv), \
sr_err("Failed to %s FTDI data in %s (%d): %s.\n", (write)?"write":"read", __func__, (rv), \
ftdi_get_error_string(ft)); \
return SR_ERR; \
} else if ((size_t)(rv) != (expect) __VA_OPT__(&& __VA_ARGS__)) { \
sr_err("FTDI %s error, only %d/%zu bytes %s: %s.", (write)?"write":"read",\
sr_err("FTDI %s error in %s, only %d/%zu bytes %s: %s.", (write)?"write":"read", __func__,\
(rv), expect, (write)?"written":"read", ftdi_get_error_string(ft)); \
return SR_ERR; \
} \
@ -65,9 +65,9 @@ SR_PRIV void sq_destroy(struct dev_context *dc)
do { \
if ((rv) < SR_ERR) { \
if (FALSE) { \
sr_err(fmt " (%d): %s", ##__VA_ARGS__ , (rv), ftdi_get_error_string(/*ft*/NULL)); \
sr_err(fmt " in %s (%d)", ##__VA_ARGS__ , __func__, (rv)); \
} else { \
sr_err(fmt, ##__VA_ARGS__); \
sr_err(fmt "in %s", ##__VA_ARGS__, __func__); \
} \
return rv; \
} \
@ -75,6 +75,19 @@ SR_PRIV void sq_destroy(struct dev_context *dc)
/* low-level commands */
/* this is a macro instead of an inline static fn, because CHECK_FTDI_RETVAL
* uses the __func__ pseudomacro for diagnostic purposes, which would be
* rendered useless if this were a real function */
#define read_ftdi_blocking(ft, data, s) ({\
size_t __i = 0; \
int __rv = 0; \
do { \
__rv = ftdi_read_data(ft, (uint8_t *)(data)+__i, (s)-__i); \
CHECK_FTDI_RETVAL(FALSE, ft, __rv, (s)-__i, FALSE); \
__i += __rv; \
} while (__i < s); \
__rv;}) \
SR_PRIV int sq_get_status(struct dev_context *dc)
{
static const uint8_t get_status_cmd[] = {0xfd,0x00,0x01,0x02,0xfe};
@ -86,7 +99,7 @@ SR_PRIV int sq_get_status(struct dev_context *dc)
rv = ftdi_write_data(dc->ft, get_status_cmd, sizeof get_status_cmd);
CHECK_FTDI_RETVAL(TRUE, dc->ft, rv, sizeof get_status_cmd);
rv = ftdi_read_data(dc->ft, stat, sizeof stat);
rv = read_ftdi_blocking(dc->ft, stat, sizeof stat);
CHECK_FTDI_RETVAL(FALSE, dc->ft, rv, sizeof stat);
if (stat[0] != stat[1] || stat[0] != stat[2] || stat[0] != stat[3])
@ -204,7 +217,7 @@ SR_PRIV int sq_bl_spi_xfer(struct dev_context *dc, uint8_t val)
rv = ftdi_write_data(dc->ft, send_spi_xfer_cmd, sizeof send_spi_xfer_cmd);
CHECK_FTDI_RETVAL(TRUE, dc->ft, rv, sizeof send_spi_xfer_cmd);
rv = ftdi_read_data(dc->ft, &read, 1);
rv = read_ftdi_blocking(dc->ft, &read, 1);
CHECK_FTDI_RETVAL(FALSE, dc->ft, rv, (size_t)1);
sr_spew("SPI xfer: %02x -> %02x", val, read);
@ -257,7 +270,7 @@ SR_PRIV int sq_app_get_capture_result(struct dev_context *dc, struct ftdi_transf
if (!tc->completed) return SR_ERR_ARG;
rv = ftdi_read_data(dc->ft, result, sizeof result);
rv = read_ftdi_blocking(dc->ft, result, sizeof result);
CHECK_FTDI_RETVAL(FALSE, dc->ft, rv, sizeof result);
ti = (uint32_t)result[0] | ((uint32_t)result[1] << 8) | ((uint32_t)result[2] << 16);
@ -329,7 +342,6 @@ SR_PRIV int sq_app_download_capture(struct dev_context *dc, void *data, size_t l
{
static const uint8_t send_dl_capt_cmd[] = {0xf0,0x06};
int rv;
size_t pos = 0;
if (!dc || !data || !len) return SR_ERR;
@ -338,12 +350,8 @@ SR_PRIV int sq_app_download_capture(struct dev_context *dc, void *data, size_t l
rv = ftdi_write_data(dc->ft, send_dl_capt_cmd, sizeof send_dl_capt_cmd);
CHECK_FTDI_RETVAL(TRUE, dc->ft, rv, sizeof send_dl_capt_cmd);
do {
rv = ftdi_read_data(dc->ft, (uint8_t *)data + pos, len - pos);
CHECK_FTDI_RETVAL(FALSE, dc->ft, rv, len, FALSE);
pos += rv;
} while (pos < len);
rv = read_ftdi_blocking(dc->ft, data, len);
CHECK_FTDI_RETVAL(FALSE, dc->ft, rv, len);
return SR_OK;
}