asix-sigma: use driver-private storage for instances
This commit is contained in:
parent
dc9dbe949a
commit
0e1357e896
|
@ -126,27 +126,27 @@ static const char *firmware_files[] = {
|
||||||
static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi,
|
static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi,
|
||||||
void *cb_data);
|
void *cb_data);
|
||||||
|
|
||||||
static int sigma_read(void *buf, size_t size, struct context *ctx)
|
static int sigma_read(void *buf, size_t size, struct dev_context *devc)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = ftdi_read_data(&ctx->ftdic, (unsigned char *)buf, size);
|
ret = ftdi_read_data(&devc->ftdic, (unsigned char *)buf, size);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
sr_err("sigma: ftdi_read_data failed: %s",
|
sr_err("sigma: ftdi_read_data failed: %s",
|
||||||
ftdi_get_error_string(&ctx->ftdic));
|
ftdi_get_error_string(&devc->ftdic));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sigma_write(void *buf, size_t size, struct context *ctx)
|
static int sigma_write(void *buf, size_t size, struct dev_context *devc)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = ftdi_write_data(&ctx->ftdic, (unsigned char *)buf, size);
|
ret = ftdi_write_data(&devc->ftdic, (unsigned char *)buf, size);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
sr_err("sigma: ftdi_write_data failed: %s",
|
sr_err("sigma: ftdi_write_data failed: %s",
|
||||||
ftdi_get_error_string(&ctx->ftdic));
|
ftdi_get_error_string(&devc->ftdic));
|
||||||
} else if ((size_t) ret != size) {
|
} else if ((size_t) ret != size) {
|
||||||
sr_err("sigma: ftdi_write_data did not complete write.");
|
sr_err("sigma: ftdi_write_data did not complete write.");
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ static int sigma_write(void *buf, size_t size, struct context *ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sigma_write_register(uint8_t reg, uint8_t *data, size_t len,
|
static int sigma_write_register(uint8_t reg, uint8_t *data, size_t len,
|
||||||
struct context *ctx)
|
struct dev_context *devc)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
uint8_t buf[len + 2];
|
uint8_t buf[len + 2];
|
||||||
|
@ -169,16 +169,16 @@ static int sigma_write_register(uint8_t reg, uint8_t *data, size_t len,
|
||||||
buf[idx++] = REG_DATA_HIGH_WRITE | (data[i] >> 4);
|
buf[idx++] = REG_DATA_HIGH_WRITE | (data[i] >> 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sigma_write(buf, idx, ctx);
|
return sigma_write(buf, idx, devc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sigma_set_register(uint8_t reg, uint8_t value, struct context *ctx)
|
static int sigma_set_register(uint8_t reg, uint8_t value, struct dev_context *devc)
|
||||||
{
|
{
|
||||||
return sigma_write_register(reg, &value, 1, ctx);
|
return sigma_write_register(reg, &value, 1, devc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sigma_read_register(uint8_t reg, uint8_t *data, size_t len,
|
static int sigma_read_register(uint8_t reg, uint8_t *data, size_t len,
|
||||||
struct context *ctx)
|
struct dev_context *devc)
|
||||||
{
|
{
|
||||||
uint8_t buf[3];
|
uint8_t buf[3];
|
||||||
|
|
||||||
|
@ -186,16 +186,16 @@ static int sigma_read_register(uint8_t reg, uint8_t *data, size_t len,
|
||||||
buf[1] = REG_ADDR_HIGH | (reg >> 4);
|
buf[1] = REG_ADDR_HIGH | (reg >> 4);
|
||||||
buf[2] = REG_READ_ADDR;
|
buf[2] = REG_READ_ADDR;
|
||||||
|
|
||||||
sigma_write(buf, sizeof(buf), ctx);
|
sigma_write(buf, sizeof(buf), devc);
|
||||||
|
|
||||||
return sigma_read(data, len, ctx);
|
return sigma_read(data, len, devc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t sigma_get_register(uint8_t reg, struct context *ctx)
|
static uint8_t sigma_get_register(uint8_t reg, struct dev_context *devc)
|
||||||
{
|
{
|
||||||
uint8_t value;
|
uint8_t value;
|
||||||
|
|
||||||
if (1 != sigma_read_register(reg, &value, 1, ctx)) {
|
if (1 != sigma_read_register(reg, &value, 1, devc)) {
|
||||||
sr_err("sigma: sigma_get_register: 1 byte expected");
|
sr_err("sigma: sigma_get_register: 1 byte expected");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -204,7 +204,7 @@ static uint8_t sigma_get_register(uint8_t reg, struct context *ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sigma_read_pos(uint32_t *stoppos, uint32_t *triggerpos,
|
static int sigma_read_pos(uint32_t *stoppos, uint32_t *triggerpos,
|
||||||
struct context *ctx)
|
struct dev_context *devc)
|
||||||
{
|
{
|
||||||
uint8_t buf[] = {
|
uint8_t buf[] = {
|
||||||
REG_ADDR_LOW | READ_TRIGGER_POS_LOW,
|
REG_ADDR_LOW | READ_TRIGGER_POS_LOW,
|
||||||
|
@ -218,9 +218,9 @@ static int sigma_read_pos(uint32_t *stoppos, uint32_t *triggerpos,
|
||||||
};
|
};
|
||||||
uint8_t result[6];
|
uint8_t result[6];
|
||||||
|
|
||||||
sigma_write(buf, sizeof(buf), ctx);
|
sigma_write(buf, sizeof(buf), devc);
|
||||||
|
|
||||||
sigma_read(result, sizeof(result), ctx);
|
sigma_read(result, sizeof(result), devc);
|
||||||
|
|
||||||
*triggerpos = result[0] | (result[1] << 8) | (result[2] << 16);
|
*triggerpos = result[0] | (result[1] << 8) | (result[2] << 16);
|
||||||
*stoppos = result[3] | (result[4] << 8) | (result[5] << 16);
|
*stoppos = result[3] | (result[4] << 8) | (result[5] << 16);
|
||||||
|
@ -236,7 +236,7 @@ static int sigma_read_pos(uint32_t *stoppos, uint32_t *triggerpos,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sigma_read_dram(uint16_t startchunk, size_t numchunks,
|
static int sigma_read_dram(uint16_t startchunk, size_t numchunks,
|
||||||
uint8_t *data, struct context *ctx)
|
uint8_t *data, struct dev_context *devc)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
uint8_t buf[4096];
|
uint8_t buf[4096];
|
||||||
|
@ -245,7 +245,7 @@ static int sigma_read_dram(uint16_t startchunk, size_t numchunks,
|
||||||
/* Send the startchunk. Index start with 1. */
|
/* Send the startchunk. Index start with 1. */
|
||||||
buf[0] = startchunk >> 8;
|
buf[0] = startchunk >> 8;
|
||||||
buf[1] = startchunk & 0xff;
|
buf[1] = startchunk & 0xff;
|
||||||
sigma_write_register(WRITE_MEMROW, buf, 2, ctx);
|
sigma_write_register(WRITE_MEMROW, buf, 2, devc);
|
||||||
|
|
||||||
/* Read the DRAM. */
|
/* Read the DRAM. */
|
||||||
buf[idx++] = REG_DRAM_BLOCK;
|
buf[idx++] = REG_DRAM_BLOCK;
|
||||||
|
@ -262,13 +262,13 @@ static int sigma_read_dram(uint16_t startchunk, size_t numchunks,
|
||||||
buf[idx++] = REG_DRAM_WAIT_ACK;
|
buf[idx++] = REG_DRAM_WAIT_ACK;
|
||||||
}
|
}
|
||||||
|
|
||||||
sigma_write(buf, idx, ctx);
|
sigma_write(buf, idx, devc);
|
||||||
|
|
||||||
return sigma_read(data, numchunks * CHUNK_SIZE, ctx);
|
return sigma_read(data, numchunks * CHUNK_SIZE, devc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Upload trigger look-up tables to Sigma. */
|
/* Upload trigger look-up tables to Sigma. */
|
||||||
static int sigma_write_trigger_lut(struct triggerlut *lut, struct context *ctx)
|
static int sigma_write_trigger_lut(struct triggerlut *lut, struct dev_context *devc)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
uint8_t tmp[2];
|
uint8_t tmp[2];
|
||||||
|
@ -315,13 +315,13 @@ static int sigma_write_trigger_lut(struct triggerlut *lut, struct context *ctx)
|
||||||
tmp[1] |= 0x80;
|
tmp[1] |= 0x80;
|
||||||
|
|
||||||
sigma_write_register(WRITE_TRIGGER_SELECT0, tmp, sizeof(tmp),
|
sigma_write_register(WRITE_TRIGGER_SELECT0, tmp, sizeof(tmp),
|
||||||
ctx);
|
devc);
|
||||||
sigma_set_register(WRITE_TRIGGER_SELECT1, 0x30 | i, ctx);
|
sigma_set_register(WRITE_TRIGGER_SELECT1, 0x30 | i, devc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send the parameters */
|
/* Send the parameters */
|
||||||
sigma_write_register(WRITE_TRIGGER_SELECT0, (uint8_t *) &lut->params,
|
sigma_write_register(WRITE_TRIGGER_SELECT0, (uint8_t *) &lut->params,
|
||||||
sizeof(lut->params), ctx);
|
sizeof(lut->params), devc);
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
@ -411,24 +411,27 @@ static void clear_instances(void)
|
||||||
{
|
{
|
||||||
GSList *l;
|
GSList *l;
|
||||||
struct sr_dev_inst *sdi;
|
struct sr_dev_inst *sdi;
|
||||||
struct context *ctx;
|
struct drv_context *drvc;
|
||||||
|
struct dev_context *devc;
|
||||||
|
|
||||||
|
drvc = adi->priv;
|
||||||
|
|
||||||
/* Properly close all devices. */
|
/* Properly close all devices. */
|
||||||
for (l = adi->instances; l; l = l->next) {
|
for (l = drvc->instances; l; l = l->next) {
|
||||||
if (!(sdi = l->data)) {
|
if (!(sdi = l->data)) {
|
||||||
/* Log error, but continue cleaning up the rest. */
|
/* Log error, but continue cleaning up the rest. */
|
||||||
sr_err("sigma: %s: sdi was NULL, continuing", __func__);
|
sr_err("sigma: %s: sdi was NULL, continuing", __func__);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (sdi->priv) {
|
if (sdi->priv) {
|
||||||
ctx = sdi->priv;
|
devc = sdi->priv;
|
||||||
ftdi_free(&ctx->ftdic);
|
ftdi_free(&devc->ftdic);
|
||||||
g_free(ctx);
|
g_free(devc);
|
||||||
}
|
}
|
||||||
sr_dev_inst_free(sdi);
|
sr_dev_inst_free(sdi);
|
||||||
}
|
}
|
||||||
g_slist_free(adi->instances);
|
g_slist_free(drvc->instances);
|
||||||
adi->instances = NULL;
|
drvc->instances = NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,7 +447,8 @@ static GSList *hw_scan(GSList *options)
|
||||||
{
|
{
|
||||||
struct sr_dev_inst *sdi;
|
struct sr_dev_inst *sdi;
|
||||||
struct sr_probe *probe;
|
struct sr_probe *probe;
|
||||||
struct context *ctx;
|
struct drv_context *drvc;
|
||||||
|
struct dev_context *devc;
|
||||||
GSList *devices;
|
GSList *devices;
|
||||||
struct ftdi_device_list *devlist;
|
struct ftdi_device_list *devlist;
|
||||||
char serial_txt[10];
|
char serial_txt[10];
|
||||||
|
@ -452,19 +456,20 @@ static GSList *hw_scan(GSList *options)
|
||||||
int ret, i;
|
int ret, i;
|
||||||
|
|
||||||
(void)options;
|
(void)options;
|
||||||
|
drvc = adi->priv;
|
||||||
devices = NULL;
|
devices = NULL;
|
||||||
clear_instances();
|
clear_instances();
|
||||||
|
|
||||||
if (!(ctx = g_try_malloc(sizeof(struct context)))) {
|
if (!(devc = g_try_malloc(sizeof(struct dev_context)))) {
|
||||||
sr_err("sigma: %s: ctx malloc failed", __func__);
|
sr_err("sigma: %s: devc malloc failed", __func__);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ftdi_init(&ctx->ftdic);
|
ftdi_init(&devc->ftdic);
|
||||||
|
|
||||||
/* Look for SIGMAs. */
|
/* Look for SIGMAs. */
|
||||||
|
|
||||||
if ((ret = ftdi_usb_find_all(&ctx->ftdic, &devlist,
|
if ((ret = ftdi_usb_find_all(&devc->ftdic, &devlist,
|
||||||
USB_VENDOR, USB_PRODUCT)) <= 0) {
|
USB_VENDOR, USB_PRODUCT)) <= 0) {
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
sr_err("ftdi_usb_find_all(): %d", ret);
|
sr_err("ftdi_usb_find_all(): %d", ret);
|
||||||
|
@ -472,7 +477,7 @@ static GSList *hw_scan(GSList *options)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure it's a version 1 or 2 SIGMA. */
|
/* Make sure it's a version 1 or 2 SIGMA. */
|
||||||
ftdi_usb_get_strings(&ctx->ftdic, devlist->dev, NULL, 0, NULL, 0,
|
ftdi_usb_get_strings(&devc->ftdic, devlist->dev, NULL, 0, NULL, 0,
|
||||||
serial_txt, sizeof(serial_txt));
|
serial_txt, sizeof(serial_txt));
|
||||||
sscanf(serial_txt, "%x", &serial);
|
sscanf(serial_txt, "%x", &serial);
|
||||||
|
|
||||||
|
@ -484,14 +489,14 @@ static GSList *hw_scan(GSList *options)
|
||||||
|
|
||||||
sr_info("Found ASIX SIGMA - Serial: %s", serial_txt);
|
sr_info("Found ASIX SIGMA - Serial: %s", serial_txt);
|
||||||
|
|
||||||
ctx->cur_samplerate = 0;
|
devc->cur_samplerate = 0;
|
||||||
ctx->period_ps = 0;
|
devc->period_ps = 0;
|
||||||
ctx->limit_msec = 0;
|
devc->limit_msec = 0;
|
||||||
ctx->cur_firmware = -1;
|
devc->cur_firmware = -1;
|
||||||
ctx->num_probes = 0;
|
devc->num_probes = 0;
|
||||||
ctx->samples_per_event = 0;
|
devc->samples_per_event = 0;
|
||||||
ctx->capture_ratio = 50;
|
devc->capture_ratio = 50;
|
||||||
ctx->use_triggers = 0;
|
devc->use_triggers = 0;
|
||||||
|
|
||||||
/* Register SIGMA device. */
|
/* Register SIGMA device. */
|
||||||
if (!(sdi = sr_dev_inst_new(0, SR_ST_INITIALIZING, USB_VENDOR_NAME,
|
if (!(sdi = sr_dev_inst_new(0, SR_ST_INITIALIZING, USB_VENDOR_NAME,
|
||||||
|
@ -509,8 +514,8 @@ static GSList *hw_scan(GSList *options)
|
||||||
}
|
}
|
||||||
|
|
||||||
devices = g_slist_append(devices, sdi);
|
devices = g_slist_append(devices, sdi);
|
||||||
adi->instances = g_slist_append(adi->instances, sdi);
|
drvc->instances = g_slist_append(drvc->instances, sdi);
|
||||||
sdi->priv = ctx;
|
sdi->priv = devc;
|
||||||
|
|
||||||
/* We will open the device again when we need it. */
|
/* We will open the device again when we need it. */
|
||||||
ftdi_list_free(&devlist);
|
ftdi_list_free(&devlist);
|
||||||
|
@ -518,12 +523,12 @@ static GSList *hw_scan(GSList *options)
|
||||||
return devices;
|
return devices;
|
||||||
|
|
||||||
free:
|
free:
|
||||||
ftdi_deinit(&ctx->ftdic);
|
ftdi_deinit(&devc->ftdic);
|
||||||
g_free(ctx);
|
g_free(devc);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int upload_firmware(int firmware_idx, struct context *ctx)
|
static int upload_firmware(int firmware_idx, struct dev_context *devc)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
unsigned char *buf;
|
unsigned char *buf;
|
||||||
|
@ -533,40 +538,40 @@ static int upload_firmware(int firmware_idx, struct context *ctx)
|
||||||
char firmware_path[128];
|
char firmware_path[128];
|
||||||
|
|
||||||
/* Make sure it's an ASIX SIGMA. */
|
/* Make sure it's an ASIX SIGMA. */
|
||||||
if ((ret = ftdi_usb_open_desc(&ctx->ftdic,
|
if ((ret = ftdi_usb_open_desc(&devc->ftdic,
|
||||||
USB_VENDOR, USB_PRODUCT, USB_DESCRIPTION, NULL)) < 0) {
|
USB_VENDOR, USB_PRODUCT, USB_DESCRIPTION, NULL)) < 0) {
|
||||||
sr_err("sigma: ftdi_usb_open failed: %s",
|
sr_err("sigma: ftdi_usb_open failed: %s",
|
||||||
ftdi_get_error_string(&ctx->ftdic));
|
ftdi_get_error_string(&devc->ftdic));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret = ftdi_set_bitmode(&ctx->ftdic, 0xdf, BITMODE_BITBANG)) < 0) {
|
if ((ret = ftdi_set_bitmode(&devc->ftdic, 0xdf, BITMODE_BITBANG)) < 0) {
|
||||||
sr_err("sigma: ftdi_set_bitmode failed: %s",
|
sr_err("sigma: ftdi_set_bitmode failed: %s",
|
||||||
ftdi_get_error_string(&ctx->ftdic));
|
ftdi_get_error_string(&devc->ftdic));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Four times the speed of sigmalogan - Works well. */
|
/* Four times the speed of sigmalogan - Works well. */
|
||||||
if ((ret = ftdi_set_baudrate(&ctx->ftdic, 750000)) < 0) {
|
if ((ret = ftdi_set_baudrate(&devc->ftdic, 750000)) < 0) {
|
||||||
sr_err("sigma: ftdi_set_baudrate failed: %s",
|
sr_err("sigma: ftdi_set_baudrate failed: %s",
|
||||||
ftdi_get_error_string(&ctx->ftdic));
|
ftdi_get_error_string(&devc->ftdic));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Force the FPGA to reboot. */
|
/* Force the FPGA to reboot. */
|
||||||
sigma_write(suicide, sizeof(suicide), ctx);
|
sigma_write(suicide, sizeof(suicide), devc);
|
||||||
sigma_write(suicide, sizeof(suicide), ctx);
|
sigma_write(suicide, sizeof(suicide), devc);
|
||||||
sigma_write(suicide, sizeof(suicide), ctx);
|
sigma_write(suicide, sizeof(suicide), devc);
|
||||||
sigma_write(suicide, sizeof(suicide), ctx);
|
sigma_write(suicide, sizeof(suicide), devc);
|
||||||
|
|
||||||
/* Prepare to upload firmware (FPGA specific). */
|
/* Prepare to upload firmware (FPGA specific). */
|
||||||
sigma_write(init, sizeof(init), ctx);
|
sigma_write(init, sizeof(init), devc);
|
||||||
|
|
||||||
ftdi_usb_purge_buffers(&ctx->ftdic);
|
ftdi_usb_purge_buffers(&devc->ftdic);
|
||||||
|
|
||||||
/* Wait until the FPGA asserts INIT_B. */
|
/* Wait until the FPGA asserts INIT_B. */
|
||||||
while (1) {
|
while (1) {
|
||||||
ret = sigma_read(result, 1, ctx);
|
ret = sigma_read(result, 1, devc);
|
||||||
if (result[0] & 0x20)
|
if (result[0] & 0x20)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -583,34 +588,34 @@ static int upload_firmware(int firmware_idx, struct context *ctx)
|
||||||
|
|
||||||
/* Upload firmare. */
|
/* Upload firmare. */
|
||||||
sr_info("sigma: Uploading firmware %s", firmware_files[firmware_idx]);
|
sr_info("sigma: Uploading firmware %s", firmware_files[firmware_idx]);
|
||||||
sigma_write(buf, buf_size, ctx);
|
sigma_write(buf, buf_size, devc);
|
||||||
|
|
||||||
g_free(buf);
|
g_free(buf);
|
||||||
|
|
||||||
if ((ret = ftdi_set_bitmode(&ctx->ftdic, 0x00, BITMODE_RESET)) < 0) {
|
if ((ret = ftdi_set_bitmode(&devc->ftdic, 0x00, BITMODE_RESET)) < 0) {
|
||||||
sr_err("sigma: ftdi_set_bitmode failed: %s",
|
sr_err("sigma: ftdi_set_bitmode failed: %s",
|
||||||
ftdi_get_error_string(&ctx->ftdic));
|
ftdi_get_error_string(&devc->ftdic));
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
ftdi_usb_purge_buffers(&ctx->ftdic);
|
ftdi_usb_purge_buffers(&devc->ftdic);
|
||||||
|
|
||||||
/* Discard garbage. */
|
/* Discard garbage. */
|
||||||
while (1 == sigma_read(&pins, 1, ctx))
|
while (1 == sigma_read(&pins, 1, devc))
|
||||||
;
|
;
|
||||||
|
|
||||||
/* Initialize the logic analyzer mode. */
|
/* Initialize the logic analyzer mode. */
|
||||||
sigma_write(logic_mode_start, sizeof(logic_mode_start), ctx);
|
sigma_write(logic_mode_start, sizeof(logic_mode_start), devc);
|
||||||
|
|
||||||
/* Expect a 3 byte reply. */
|
/* Expect a 3 byte reply. */
|
||||||
ret = sigma_read(result, 3, ctx);
|
ret = sigma_read(result, 3, devc);
|
||||||
if (ret != 3 ||
|
if (ret != 3 ||
|
||||||
result[0] != 0xa6 || result[1] != 0x55 || result[2] != 0xaa) {
|
result[0] != 0xa6 || result[1] != 0x55 || result[2] != 0xaa) {
|
||||||
sr_err("sigma: Configuration failed. Invalid reply received.");
|
sr_err("sigma: Configuration failed. Invalid reply received.");
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->cur_firmware = firmware_idx;
|
devc->cur_firmware = firmware_idx;
|
||||||
|
|
||||||
sr_info("sigma: Firmware uploaded");
|
sr_info("sigma: Firmware uploaded");
|
||||||
|
|
||||||
|
@ -619,17 +624,17 @@ static int upload_firmware(int firmware_idx, struct context *ctx)
|
||||||
|
|
||||||
static int hw_dev_open(struct sr_dev_inst *sdi)
|
static int hw_dev_open(struct sr_dev_inst *sdi)
|
||||||
{
|
{
|
||||||
struct context *ctx;
|
struct dev_context *devc;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ctx = sdi->priv;
|
devc = sdi->priv;
|
||||||
|
|
||||||
/* Make sure it's an ASIX SIGMA. */
|
/* Make sure it's an ASIX SIGMA. */
|
||||||
if ((ret = ftdi_usb_open_desc(&ctx->ftdic,
|
if ((ret = ftdi_usb_open_desc(&devc->ftdic,
|
||||||
USB_VENDOR, USB_PRODUCT, USB_DESCRIPTION, NULL)) < 0) {
|
USB_VENDOR, USB_PRODUCT, USB_DESCRIPTION, NULL)) < 0) {
|
||||||
|
|
||||||
sr_err("sigma: ftdi_usb_open failed: %s",
|
sr_err("sigma: ftdi_usb_open failed: %s",
|
||||||
ftdi_get_error_string(&ctx->ftdic));
|
ftdi_get_error_string(&devc->ftdic));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -642,7 +647,7 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
|
||||||
static int set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate)
|
static int set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate)
|
||||||
{
|
{
|
||||||
int i, ret;
|
int i, ret;
|
||||||
struct context *ctx = sdi->priv;
|
struct dev_context *devc = sdi->priv;
|
||||||
|
|
||||||
for (i = 0; supported_samplerates[i]; i++) {
|
for (i = 0; supported_samplerates[i]; i++) {
|
||||||
if (supported_samplerates[i] == samplerate)
|
if (supported_samplerates[i] == samplerate)
|
||||||
|
@ -652,22 +657,22 @@ static int set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate)
|
||||||
return SR_ERR_SAMPLERATE;
|
return SR_ERR_SAMPLERATE;
|
||||||
|
|
||||||
if (samplerate <= SR_MHZ(50)) {
|
if (samplerate <= SR_MHZ(50)) {
|
||||||
ret = upload_firmware(0, ctx);
|
ret = upload_firmware(0, devc);
|
||||||
ctx->num_probes = 16;
|
devc->num_probes = 16;
|
||||||
}
|
}
|
||||||
if (samplerate == SR_MHZ(100)) {
|
if (samplerate == SR_MHZ(100)) {
|
||||||
ret = upload_firmware(1, ctx);
|
ret = upload_firmware(1, devc);
|
||||||
ctx->num_probes = 8;
|
devc->num_probes = 8;
|
||||||
}
|
}
|
||||||
else if (samplerate == SR_MHZ(200)) {
|
else if (samplerate == SR_MHZ(200)) {
|
||||||
ret = upload_firmware(2, ctx);
|
ret = upload_firmware(2, devc);
|
||||||
ctx->num_probes = 4;
|
devc->num_probes = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->cur_samplerate = samplerate;
|
devc->cur_samplerate = samplerate;
|
||||||
ctx->period_ps = 1000000000000 / samplerate;
|
devc->period_ps = 1000000000000 / samplerate;
|
||||||
ctx->samples_per_event = 16 / ctx->num_probes;
|
devc->samples_per_event = 16 / devc->num_probes;
|
||||||
ctx->state.state = SIGMA_IDLE;
|
devc->state.state = SIGMA_IDLE;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -682,13 +687,13 @@ static int set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate)
|
||||||
*/
|
*/
|
||||||
static int configure_probes(const struct sr_dev_inst *sdi, const GSList *probes)
|
static int configure_probes(const struct sr_dev_inst *sdi, const GSList *probes)
|
||||||
{
|
{
|
||||||
struct context *ctx = sdi->priv;
|
struct dev_context *devc = sdi->priv;
|
||||||
const struct sr_probe *probe;
|
const struct sr_probe *probe;
|
||||||
const GSList *l;
|
const GSList *l;
|
||||||
int trigger_set = 0;
|
int trigger_set = 0;
|
||||||
int probebit;
|
int probebit;
|
||||||
|
|
||||||
memset(&ctx->trigger, 0, sizeof(struct sigma_trigger));
|
memset(&devc->trigger, 0, sizeof(struct sigma_trigger));
|
||||||
|
|
||||||
for (l = probes; l; l = l->next) {
|
for (l = probes; l; l = l->next) {
|
||||||
probe = (struct sr_probe *)l->data;
|
probe = (struct sr_probe *)l->data;
|
||||||
|
@ -697,7 +702,7 @@ static int configure_probes(const struct sr_dev_inst *sdi, const GSList *probes)
|
||||||
if (!probe->enabled || !probe->trigger)
|
if (!probe->enabled || !probe->trigger)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (ctx->cur_samplerate >= SR_MHZ(100)) {
|
if (devc->cur_samplerate >= SR_MHZ(100)) {
|
||||||
/* Fast trigger support. */
|
/* Fast trigger support. */
|
||||||
if (trigger_set) {
|
if (trigger_set) {
|
||||||
sr_err("sigma: ASIX SIGMA only supports a single "
|
sr_err("sigma: ASIX SIGMA only supports a single "
|
||||||
|
@ -705,9 +710,9 @@ static int configure_probes(const struct sr_dev_inst *sdi, const GSList *probes)
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
if (probe->trigger[0] == 'f')
|
if (probe->trigger[0] == 'f')
|
||||||
ctx->trigger.fallingmask |= probebit;
|
devc->trigger.fallingmask |= probebit;
|
||||||
else if (probe->trigger[0] == 'r')
|
else if (probe->trigger[0] == 'r')
|
||||||
ctx->trigger.risingmask |= probebit;
|
devc->trigger.risingmask |= probebit;
|
||||||
else {
|
else {
|
||||||
sr_err("sigma: ASIX SIGMA only supports "
|
sr_err("sigma: ASIX SIGMA only supports "
|
||||||
"rising/falling trigger in 100 "
|
"rising/falling trigger in 100 "
|
||||||
|
@ -719,19 +724,19 @@ static int configure_probes(const struct sr_dev_inst *sdi, const GSList *probes)
|
||||||
} else {
|
} else {
|
||||||
/* Simple trigger support (event). */
|
/* Simple trigger support (event). */
|
||||||
if (probe->trigger[0] == '1') {
|
if (probe->trigger[0] == '1') {
|
||||||
ctx->trigger.simplevalue |= probebit;
|
devc->trigger.simplevalue |= probebit;
|
||||||
ctx->trigger.simplemask |= probebit;
|
devc->trigger.simplemask |= probebit;
|
||||||
}
|
}
|
||||||
else if (probe->trigger[0] == '0') {
|
else if (probe->trigger[0] == '0') {
|
||||||
ctx->trigger.simplevalue &= ~probebit;
|
devc->trigger.simplevalue &= ~probebit;
|
||||||
ctx->trigger.simplemask |= probebit;
|
devc->trigger.simplemask |= probebit;
|
||||||
}
|
}
|
||||||
else if (probe->trigger[0] == 'f') {
|
else if (probe->trigger[0] == 'f') {
|
||||||
ctx->trigger.fallingmask |= probebit;
|
devc->trigger.fallingmask |= probebit;
|
||||||
++trigger_set;
|
++trigger_set;
|
||||||
}
|
}
|
||||||
else if (probe->trigger[0] == 'r') {
|
else if (probe->trigger[0] == 'r') {
|
||||||
ctx->trigger.risingmask |= probebit;
|
devc->trigger.risingmask |= probebit;
|
||||||
++trigger_set;
|
++trigger_set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -748,7 +753,7 @@ static int configure_probes(const struct sr_dev_inst *sdi, const GSList *probes)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trigger_set)
|
if (trigger_set)
|
||||||
ctx->use_triggers = 1;
|
devc->use_triggers = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
|
@ -756,16 +761,16 @@ static int configure_probes(const struct sr_dev_inst *sdi, const GSList *probes)
|
||||||
|
|
||||||
static int hw_dev_close(struct sr_dev_inst *sdi)
|
static int hw_dev_close(struct sr_dev_inst *sdi)
|
||||||
{
|
{
|
||||||
struct context *ctx;
|
struct dev_context *devc;
|
||||||
|
|
||||||
if (!(ctx = sdi->priv)) {
|
if (!(devc = sdi->priv)) {
|
||||||
sr_err("sigma: %s: sdi->priv was NULL", __func__);
|
sr_err("sigma: %s: sdi->priv was NULL", __func__);
|
||||||
return SR_ERR_BUG;
|
return SR_ERR_BUG;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO */
|
/* TODO */
|
||||||
if (sdi->status == SR_ST_ACTIVE)
|
if (sdi->status == SR_ST_ACTIVE)
|
||||||
ftdi_usb_close(&ctx->ftdic);
|
ftdi_usb_close(&devc->ftdic);
|
||||||
|
|
||||||
sdi->status = SR_ST_INACTIVE;
|
sdi->status = SR_ST_INACTIVE;
|
||||||
|
|
||||||
|
@ -783,7 +788,7 @@ static int hw_cleanup(void)
|
||||||
static int hw_info_get(int info_id, const void **data,
|
static int hw_info_get(int info_id, const void **data,
|
||||||
const struct sr_dev_inst *sdi)
|
const struct sr_dev_inst *sdi)
|
||||||
{
|
{
|
||||||
struct context *ctx;
|
struct dev_context *devc;
|
||||||
|
|
||||||
switch (info_id) {
|
switch (info_id) {
|
||||||
case SR_DI_HWCAPS:
|
case SR_DI_HWCAPS:
|
||||||
|
@ -803,8 +808,8 @@ static int hw_info_get(int info_id, const void **data,
|
||||||
break;
|
break;
|
||||||
case SR_DI_CUR_SAMPLERATE:
|
case SR_DI_CUR_SAMPLERATE:
|
||||||
if (sdi) {
|
if (sdi) {
|
||||||
ctx = sdi->priv;
|
devc = sdi->priv;
|
||||||
*data = &ctx->cur_samplerate;
|
*data = &devc->cur_samplerate;
|
||||||
} else
|
} else
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
break;
|
break;
|
||||||
|
@ -818,24 +823,24 @@ static int hw_info_get(int info_id, const void **data,
|
||||||
static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
|
static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
|
||||||
const void *value)
|
const void *value)
|
||||||
{
|
{
|
||||||
struct context *ctx;
|
struct dev_context *devc;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ctx = sdi->priv;
|
devc = sdi->priv;
|
||||||
|
|
||||||
if (hwcap == SR_HWCAP_SAMPLERATE) {
|
if (hwcap == SR_HWCAP_SAMPLERATE) {
|
||||||
ret = set_samplerate(sdi, *(const uint64_t *)value);
|
ret = set_samplerate(sdi, *(const uint64_t *)value);
|
||||||
} else if (hwcap == SR_HWCAP_PROBECONFIG) {
|
} else if (hwcap == SR_HWCAP_PROBECONFIG) {
|
||||||
ret = configure_probes(sdi, value);
|
ret = configure_probes(sdi, value);
|
||||||
} else if (hwcap == SR_HWCAP_LIMIT_MSEC) {
|
} else if (hwcap == SR_HWCAP_LIMIT_MSEC) {
|
||||||
ctx->limit_msec = *(const uint64_t *)value;
|
devc->limit_msec = *(const uint64_t *)value;
|
||||||
if (ctx->limit_msec > 0)
|
if (devc->limit_msec > 0)
|
||||||
ret = SR_OK;
|
ret = SR_OK;
|
||||||
else
|
else
|
||||||
ret = SR_ERR;
|
ret = SR_ERR;
|
||||||
} else if (hwcap == SR_HWCAP_CAPTURE_RATIO) {
|
} else if (hwcap == SR_HWCAP_CAPTURE_RATIO) {
|
||||||
ctx->capture_ratio = *(const uint64_t *)value;
|
devc->capture_ratio = *(const uint64_t *)value;
|
||||||
if (ctx->capture_ratio < 0 || ctx->capture_ratio > 100)
|
if (devc->capture_ratio < 0 || devc->capture_ratio > 100)
|
||||||
ret = SR_ERR;
|
ret = SR_ERR;
|
||||||
else
|
else
|
||||||
ret = SR_OK;
|
ret = SR_OK;
|
||||||
|
@ -891,21 +896,21 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts,
|
||||||
uint16_t limit_chunk, void *cb_data)
|
uint16_t limit_chunk, void *cb_data)
|
||||||
{
|
{
|
||||||
struct sr_dev_inst *sdi = cb_data;
|
struct sr_dev_inst *sdi = cb_data;
|
||||||
struct context *ctx = sdi->priv;
|
struct dev_context *devc = sdi->priv;
|
||||||
uint16_t tsdiff, ts;
|
uint16_t tsdiff, ts;
|
||||||
uint16_t samples[65536 * ctx->samples_per_event];
|
uint16_t samples[65536 * devc->samples_per_event];
|
||||||
struct sr_datafeed_packet packet;
|
struct sr_datafeed_packet packet;
|
||||||
struct sr_datafeed_logic logic;
|
struct sr_datafeed_logic logic;
|
||||||
int i, j, k, l, numpad, tosend;
|
int i, j, k, l, numpad, tosend;
|
||||||
size_t n = 0, sent = 0;
|
size_t n = 0, sent = 0;
|
||||||
int clustersize = EVENTS_PER_CLUSTER * ctx->samples_per_event;
|
int clustersize = EVENTS_PER_CLUSTER * devc->samples_per_event;
|
||||||
uint16_t *event;
|
uint16_t *event;
|
||||||
uint16_t cur_sample;
|
uint16_t cur_sample;
|
||||||
int triggerts = -1;
|
int triggerts = -1;
|
||||||
|
|
||||||
/* Check if trigger is in this chunk. */
|
/* Check if trigger is in this chunk. */
|
||||||
if (triggerpos != -1) {
|
if (triggerpos != -1) {
|
||||||
if (ctx->cur_samplerate <= SR_MHZ(50))
|
if (devc->cur_samplerate <= SR_MHZ(50))
|
||||||
triggerpos -= EVENTS_PER_CLUSTER - 1;
|
triggerpos -= EVENTS_PER_CLUSTER - 1;
|
||||||
|
|
||||||
if (triggerpos < 0)
|
if (triggerpos < 0)
|
||||||
|
@ -926,7 +931,7 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts,
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
|
|
||||||
/* Pad last sample up to current point. */
|
/* Pad last sample up to current point. */
|
||||||
numpad = tsdiff * ctx->samples_per_event - clustersize;
|
numpad = tsdiff * devc->samples_per_event - clustersize;
|
||||||
if (numpad > 0) {
|
if (numpad > 0) {
|
||||||
for (j = 0; j < numpad; ++j)
|
for (j = 0; j < numpad; ++j)
|
||||||
samples[j] = *lastsample;
|
samples[j] = *lastsample;
|
||||||
|
@ -944,7 +949,7 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts,
|
||||||
logic.length = tosend * sizeof(uint16_t);
|
logic.length = tosend * sizeof(uint16_t);
|
||||||
logic.unitsize = 2;
|
logic.unitsize = 2;
|
||||||
logic.data = samples + sent;
|
logic.data = samples + sent;
|
||||||
sr_session_send(ctx->session_dev_id, &packet);
|
sr_session_send(devc->session_dev_id, &packet);
|
||||||
|
|
||||||
sent += tosend;
|
sent += tosend;
|
||||||
}
|
}
|
||||||
|
@ -957,13 +962,13 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts,
|
||||||
for (j = 0; j < 7; ++j) {
|
for (j = 0; j < 7; ++j) {
|
||||||
|
|
||||||
/* For each sample in event. */
|
/* For each sample in event. */
|
||||||
for (k = 0; k < ctx->samples_per_event; ++k) {
|
for (k = 0; k < devc->samples_per_event; ++k) {
|
||||||
cur_sample = 0;
|
cur_sample = 0;
|
||||||
|
|
||||||
/* For each probe. */
|
/* For each probe. */
|
||||||
for (l = 0; l < ctx->num_probes; ++l)
|
for (l = 0; l < devc->num_probes; ++l)
|
||||||
cur_sample |= (!!(event[j] & (1 << (l *
|
cur_sample |= (!!(event[j] & (1 << (l *
|
||||||
ctx->samples_per_event + k)))) << l;
|
devc->samples_per_event + k)))) << l;
|
||||||
|
|
||||||
samples[n++] = cur_sample;
|
samples[n++] = cur_sample;
|
||||||
}
|
}
|
||||||
|
@ -979,7 +984,7 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts,
|
||||||
* samples to pinpoint the exact position of the trigger.
|
* samples to pinpoint the exact position of the trigger.
|
||||||
*/
|
*/
|
||||||
tosend = get_trigger_offset(samples, *lastsample,
|
tosend = get_trigger_offset(samples, *lastsample,
|
||||||
&ctx->trigger);
|
&devc->trigger);
|
||||||
|
|
||||||
if (tosend > 0) {
|
if (tosend > 0) {
|
||||||
packet.type = SR_DF_LOGIC;
|
packet.type = SR_DF_LOGIC;
|
||||||
|
@ -987,15 +992,15 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts,
|
||||||
logic.length = tosend * sizeof(uint16_t);
|
logic.length = tosend * sizeof(uint16_t);
|
||||||
logic.unitsize = 2;
|
logic.unitsize = 2;
|
||||||
logic.data = samples;
|
logic.data = samples;
|
||||||
sr_session_send(ctx->session_dev_id, &packet);
|
sr_session_send(devc->session_dev_id, &packet);
|
||||||
|
|
||||||
sent += tosend;
|
sent += tosend;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Only send trigger if explicitly enabled. */
|
/* Only send trigger if explicitly enabled. */
|
||||||
if (ctx->use_triggers) {
|
if (devc->use_triggers) {
|
||||||
packet.type = SR_DF_TRIGGER;
|
packet.type = SR_DF_TRIGGER;
|
||||||
sr_session_send(ctx->session_dev_id, &packet);
|
sr_session_send(devc->session_dev_id, &packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1008,7 +1013,7 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts,
|
||||||
logic.length = tosend * sizeof(uint16_t);
|
logic.length = tosend * sizeof(uint16_t);
|
||||||
logic.unitsize = 2;
|
logic.unitsize = 2;
|
||||||
logic.data = samples + sent;
|
logic.data = samples + sent;
|
||||||
sr_session_send(ctx->session_dev_id, &packet);
|
sr_session_send(devc->session_dev_id, &packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
*lastsample = samples[n - 1];
|
*lastsample = samples[n - 1];
|
||||||
|
@ -1020,7 +1025,7 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts,
|
||||||
static int receive_data(int fd, int revents, void *cb_data)
|
static int receive_data(int fd, int revents, void *cb_data)
|
||||||
{
|
{
|
||||||
struct sr_dev_inst *sdi = cb_data;
|
struct sr_dev_inst *sdi = cb_data;
|
||||||
struct context *ctx = sdi->priv;
|
struct dev_context *devc = sdi->priv;
|
||||||
struct sr_datafeed_packet packet;
|
struct sr_datafeed_packet packet;
|
||||||
const int chunks_per_read = 32;
|
const int chunks_per_read = 32;
|
||||||
unsigned char buf[chunks_per_read * CHUNK_SIZE];
|
unsigned char buf[chunks_per_read * CHUNK_SIZE];
|
||||||
|
@ -1033,50 +1038,50 @@ static int receive_data(int fd, int revents, void *cb_data)
|
||||||
(void)revents;
|
(void)revents;
|
||||||
|
|
||||||
/* Get the current position. */
|
/* Get the current position. */
|
||||||
sigma_read_pos(&ctx->state.stoppos, &ctx->state.triggerpos, ctx);
|
sigma_read_pos(&devc->state.stoppos, &devc->state.triggerpos, devc);
|
||||||
|
|
||||||
numchunks = (ctx->state.stoppos + 511) / 512;
|
numchunks = (devc->state.stoppos + 511) / 512;
|
||||||
|
|
||||||
if (ctx->state.state == SIGMA_IDLE)
|
if (devc->state.state == SIGMA_IDLE)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
if (ctx->state.state == SIGMA_CAPTURE) {
|
if (devc->state.state == SIGMA_CAPTURE) {
|
||||||
/* Check if the timer has expired, or memory is full. */
|
/* Check if the timer has expired, or memory is full. */
|
||||||
gettimeofday(&tv, 0);
|
gettimeofday(&tv, 0);
|
||||||
running_msec = (tv.tv_sec - ctx->start_tv.tv_sec) * 1000 +
|
running_msec = (tv.tv_sec - devc->start_tv.tv_sec) * 1000 +
|
||||||
(tv.tv_usec - ctx->start_tv.tv_usec) / 1000;
|
(tv.tv_usec - devc->start_tv.tv_usec) / 1000;
|
||||||
|
|
||||||
if (running_msec < ctx->limit_msec && numchunks < 32767)
|
if (running_msec < devc->limit_msec && numchunks < 32767)
|
||||||
return TRUE; /* While capturing... */
|
return TRUE; /* While capturing... */
|
||||||
else
|
else
|
||||||
hw_dev_acquisition_stop(sdi, sdi);
|
hw_dev_acquisition_stop(sdi, sdi);
|
||||||
|
|
||||||
} else if (ctx->state.state == SIGMA_DOWNLOAD) {
|
} else if (devc->state.state == SIGMA_DOWNLOAD) {
|
||||||
if (ctx->state.chunks_downloaded >= numchunks) {
|
if (devc->state.chunks_downloaded >= numchunks) {
|
||||||
/* End of samples. */
|
/* End of samples. */
|
||||||
packet.type = SR_DF_END;
|
packet.type = SR_DF_END;
|
||||||
sr_session_send(ctx->session_dev_id, &packet);
|
sr_session_send(devc->session_dev_id, &packet);
|
||||||
|
|
||||||
ctx->state.state = SIGMA_IDLE;
|
devc->state.state = SIGMA_IDLE;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
newchunks = MIN(chunks_per_read,
|
newchunks = MIN(chunks_per_read,
|
||||||
numchunks - ctx->state.chunks_downloaded);
|
numchunks - devc->state.chunks_downloaded);
|
||||||
|
|
||||||
sr_info("sigma: Downloading sample data: %.0f %%",
|
sr_info("sigma: Downloading sample data: %.0f %%",
|
||||||
100.0 * ctx->state.chunks_downloaded / numchunks);
|
100.0 * devc->state.chunks_downloaded / numchunks);
|
||||||
|
|
||||||
bufsz = sigma_read_dram(ctx->state.chunks_downloaded,
|
bufsz = sigma_read_dram(devc->state.chunks_downloaded,
|
||||||
newchunks, buf, ctx);
|
newchunks, buf, devc);
|
||||||
/* TODO: Check bufsz. For now, just avoid compiler warnings. */
|
/* TODO: Check bufsz. For now, just avoid compiler warnings. */
|
||||||
(void)bufsz;
|
(void)bufsz;
|
||||||
|
|
||||||
/* Find first ts. */
|
/* Find first ts. */
|
||||||
if (ctx->state.chunks_downloaded == 0) {
|
if (devc->state.chunks_downloaded == 0) {
|
||||||
ctx->state.lastts = *(uint16_t *) buf - 1;
|
devc->state.lastts = *(uint16_t *) buf - 1;
|
||||||
ctx->state.lastsample = 0;
|
devc->state.lastsample = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Decode chunks and send them to sigrok. */
|
/* Decode chunks and send them to sigrok. */
|
||||||
|
@ -1084,24 +1089,24 @@ static int receive_data(int fd, int revents, void *cb_data)
|
||||||
int limit_chunk = 0;
|
int limit_chunk = 0;
|
||||||
|
|
||||||
/* The last chunk may potentially be only in part. */
|
/* The last chunk may potentially be only in part. */
|
||||||
if (ctx->state.chunks_downloaded == numchunks - 1) {
|
if (devc->state.chunks_downloaded == numchunks - 1) {
|
||||||
/* Find the last valid timestamp */
|
/* Find the last valid timestamp */
|
||||||
limit_chunk = ctx->state.stoppos % 512 + ctx->state.lastts;
|
limit_chunk = devc->state.stoppos % 512 + devc->state.lastts;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->state.chunks_downloaded + i == ctx->state.triggerchunk)
|
if (devc->state.chunks_downloaded + i == devc->state.triggerchunk)
|
||||||
decode_chunk_ts(buf + (i * CHUNK_SIZE),
|
decode_chunk_ts(buf + (i * CHUNK_SIZE),
|
||||||
&ctx->state.lastts,
|
&devc->state.lastts,
|
||||||
&ctx->state.lastsample,
|
&devc->state.lastsample,
|
||||||
ctx->state.triggerpos & 0x1ff,
|
devc->state.triggerpos & 0x1ff,
|
||||||
limit_chunk, sdi);
|
limit_chunk, sdi);
|
||||||
else
|
else
|
||||||
decode_chunk_ts(buf + (i * CHUNK_SIZE),
|
decode_chunk_ts(buf + (i * CHUNK_SIZE),
|
||||||
&ctx->state.lastts,
|
&devc->state.lastts,
|
||||||
&ctx->state.lastsample,
|
&devc->state.lastsample,
|
||||||
-1, limit_chunk, sdi);
|
-1, limit_chunk, sdi);
|
||||||
|
|
||||||
++ctx->state.chunks_downloaded;
|
++devc->state.chunks_downloaded;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1219,7 +1224,7 @@ static void add_trigger_function(enum triggerop oper, enum triggerfunc func,
|
||||||
* simple pin change and state triggers. Only two transitions (rise/fall) can be
|
* simple pin change and state triggers. Only two transitions (rise/fall) can be
|
||||||
* set at any time, but a full mask and value can be set (0/1).
|
* set at any time, but a full mask and value can be set (0/1).
|
||||||
*/
|
*/
|
||||||
static int build_basic_trigger(struct triggerlut *lut, struct context *ctx)
|
static int build_basic_trigger(struct triggerlut *lut, struct dev_context *devc)
|
||||||
{
|
{
|
||||||
int i,j;
|
int i,j;
|
||||||
uint16_t masks[2] = { 0, 0 };
|
uint16_t masks[2] = { 0, 0 };
|
||||||
|
@ -1230,13 +1235,13 @@ static int build_basic_trigger(struct triggerlut *lut, struct context *ctx)
|
||||||
lut->m4 = 0xa000;
|
lut->m4 = 0xa000;
|
||||||
|
|
||||||
/* Value/mask trigger support. */
|
/* Value/mask trigger support. */
|
||||||
build_lut_entry(ctx->trigger.simplevalue, ctx->trigger.simplemask,
|
build_lut_entry(devc->trigger.simplevalue, devc->trigger.simplemask,
|
||||||
lut->m2d);
|
lut->m2d);
|
||||||
|
|
||||||
/* Rise/fall trigger support. */
|
/* Rise/fall trigger support. */
|
||||||
for (i = 0, j = 0; i < 16; ++i) {
|
for (i = 0, j = 0; i < 16; ++i) {
|
||||||
if (ctx->trigger.risingmask & (1 << i) ||
|
if (devc->trigger.risingmask & (1 << i) ||
|
||||||
ctx->trigger.fallingmask & (1 << i))
|
devc->trigger.fallingmask & (1 << i))
|
||||||
masks[j++] = 1 << i;
|
masks[j++] = 1 << i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1246,13 +1251,13 @@ static int build_basic_trigger(struct triggerlut *lut, struct context *ctx)
|
||||||
/* Add glue logic */
|
/* Add glue logic */
|
||||||
if (masks[0] || masks[1]) {
|
if (masks[0] || masks[1]) {
|
||||||
/* Transition trigger. */
|
/* Transition trigger. */
|
||||||
if (masks[0] & ctx->trigger.risingmask)
|
if (masks[0] & devc->trigger.risingmask)
|
||||||
add_trigger_function(OP_RISE, FUNC_OR, 0, 0, &lut->m3);
|
add_trigger_function(OP_RISE, FUNC_OR, 0, 0, &lut->m3);
|
||||||
if (masks[0] & ctx->trigger.fallingmask)
|
if (masks[0] & devc->trigger.fallingmask)
|
||||||
add_trigger_function(OP_FALL, FUNC_OR, 0, 0, &lut->m3);
|
add_trigger_function(OP_FALL, FUNC_OR, 0, 0, &lut->m3);
|
||||||
if (masks[1] & ctx->trigger.risingmask)
|
if (masks[1] & devc->trigger.risingmask)
|
||||||
add_trigger_function(OP_RISE, FUNC_OR, 1, 0, &lut->m3);
|
add_trigger_function(OP_RISE, FUNC_OR, 1, 0, &lut->m3);
|
||||||
if (masks[1] & ctx->trigger.fallingmask)
|
if (masks[1] & devc->trigger.fallingmask)
|
||||||
add_trigger_function(OP_FALL, FUNC_OR, 1, 0, &lut->m3);
|
add_trigger_function(OP_FALL, FUNC_OR, 1, 0, &lut->m3);
|
||||||
} else {
|
} else {
|
||||||
/* Only value/mask trigger. */
|
/* Only value/mask trigger. */
|
||||||
|
@ -1268,7 +1273,7 @@ static int build_basic_trigger(struct triggerlut *lut, struct context *ctx)
|
||||||
static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
void *cb_data)
|
void *cb_data)
|
||||||
{
|
{
|
||||||
struct context *ctx;
|
struct dev_context *devc;
|
||||||
struct sr_datafeed_packet *packet;
|
struct sr_datafeed_packet *packet;
|
||||||
struct sr_datafeed_header *header;
|
struct sr_datafeed_header *header;
|
||||||
struct sr_datafeed_meta_logic meta;
|
struct sr_datafeed_meta_logic meta;
|
||||||
|
@ -1278,24 +1283,24 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
struct triggerinout triggerinout_conf;
|
struct triggerinout triggerinout_conf;
|
||||||
struct triggerlut lut;
|
struct triggerlut lut;
|
||||||
|
|
||||||
ctx = sdi->priv;
|
devc = sdi->priv;
|
||||||
|
|
||||||
/* If the samplerate has not been set, default to 200 kHz. */
|
/* If the samplerate has not been set, default to 200 kHz. */
|
||||||
if (ctx->cur_firmware == -1) {
|
if (devc->cur_firmware == -1) {
|
||||||
if ((ret = set_samplerate(sdi, SR_KHZ(200))) != SR_OK)
|
if ((ret = set_samplerate(sdi, SR_KHZ(200))) != SR_OK)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Enter trigger programming mode. */
|
/* Enter trigger programming mode. */
|
||||||
sigma_set_register(WRITE_TRIGGER_SELECT1, 0x20, ctx);
|
sigma_set_register(WRITE_TRIGGER_SELECT1, 0x20, devc);
|
||||||
|
|
||||||
/* 100 and 200 MHz mode. */
|
/* 100 and 200 MHz mode. */
|
||||||
if (ctx->cur_samplerate >= SR_MHZ(100)) {
|
if (devc->cur_samplerate >= SR_MHZ(100)) {
|
||||||
sigma_set_register(WRITE_TRIGGER_SELECT1, 0x81, ctx);
|
sigma_set_register(WRITE_TRIGGER_SELECT1, 0x81, devc);
|
||||||
|
|
||||||
/* Find which pin to trigger on from mask. */
|
/* Find which pin to trigger on from mask. */
|
||||||
for (triggerpin = 0; triggerpin < 8; ++triggerpin)
|
for (triggerpin = 0; triggerpin < 8; ++triggerpin)
|
||||||
if ((ctx->trigger.risingmask | ctx->trigger.fallingmask) &
|
if ((devc->trigger.risingmask | devc->trigger.fallingmask) &
|
||||||
(1 << triggerpin))
|
(1 << triggerpin))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1303,14 +1308,14 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
triggerselect = (1 << LEDSEL1) | (triggerpin & 0x7);
|
triggerselect = (1 << LEDSEL1) | (triggerpin & 0x7);
|
||||||
|
|
||||||
/* Default rising edge. */
|
/* Default rising edge. */
|
||||||
if (ctx->trigger.fallingmask)
|
if (devc->trigger.fallingmask)
|
||||||
triggerselect |= 1 << 3;
|
triggerselect |= 1 << 3;
|
||||||
|
|
||||||
/* All other modes. */
|
/* All other modes. */
|
||||||
} else if (ctx->cur_samplerate <= SR_MHZ(50)) {
|
} else if (devc->cur_samplerate <= SR_MHZ(50)) {
|
||||||
build_basic_trigger(&lut, ctx);
|
build_basic_trigger(&lut, devc);
|
||||||
|
|
||||||
sigma_write_trigger_lut(&lut, ctx);
|
sigma_write_trigger_lut(&lut, devc);
|
||||||
|
|
||||||
triggerselect = (1 << LEDSEL1) | (1 << LEDSEL0);
|
triggerselect = (1 << LEDSEL1) | (1 << LEDSEL0);
|
||||||
}
|
}
|
||||||
|
@ -1322,24 +1327,24 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
|
|
||||||
sigma_write_register(WRITE_TRIGGER_OPTION,
|
sigma_write_register(WRITE_TRIGGER_OPTION,
|
||||||
(uint8_t *) &triggerinout_conf,
|
(uint8_t *) &triggerinout_conf,
|
||||||
sizeof(struct triggerinout), ctx);
|
sizeof(struct triggerinout), devc);
|
||||||
|
|
||||||
/* Go back to normal mode. */
|
/* Go back to normal mode. */
|
||||||
sigma_set_register(WRITE_TRIGGER_SELECT1, triggerselect, ctx);
|
sigma_set_register(WRITE_TRIGGER_SELECT1, triggerselect, devc);
|
||||||
|
|
||||||
/* Set clock select register. */
|
/* Set clock select register. */
|
||||||
if (ctx->cur_samplerate == SR_MHZ(200))
|
if (devc->cur_samplerate == SR_MHZ(200))
|
||||||
/* Enable 4 probes. */
|
/* Enable 4 probes. */
|
||||||
sigma_set_register(WRITE_CLOCK_SELECT, 0xf0, ctx);
|
sigma_set_register(WRITE_CLOCK_SELECT, 0xf0, devc);
|
||||||
else if (ctx->cur_samplerate == SR_MHZ(100))
|
else if (devc->cur_samplerate == SR_MHZ(100))
|
||||||
/* Enable 8 probes. */
|
/* Enable 8 probes. */
|
||||||
sigma_set_register(WRITE_CLOCK_SELECT, 0x00, ctx);
|
sigma_set_register(WRITE_CLOCK_SELECT, 0x00, devc);
|
||||||
else {
|
else {
|
||||||
/*
|
/*
|
||||||
* 50 MHz mode (or fraction thereof). Any fraction down to
|
* 50 MHz mode (or fraction thereof). Any fraction down to
|
||||||
* 50 MHz / 256 can be used, but is not supported by sigrok API.
|
* 50 MHz / 256 can be used, but is not supported by sigrok API.
|
||||||
*/
|
*/
|
||||||
frac = SR_MHZ(50) / ctx->cur_samplerate - 1;
|
frac = SR_MHZ(50) / devc->cur_samplerate - 1;
|
||||||
|
|
||||||
clockselect.async = 0;
|
clockselect.async = 0;
|
||||||
clockselect.fraction = frac;
|
clockselect.fraction = frac;
|
||||||
|
@ -1347,18 +1352,18 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
|
|
||||||
sigma_write_register(WRITE_CLOCK_SELECT,
|
sigma_write_register(WRITE_CLOCK_SELECT,
|
||||||
(uint8_t *) &clockselect,
|
(uint8_t *) &clockselect,
|
||||||
sizeof(clockselect), ctx);
|
sizeof(clockselect), devc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Setup maximum post trigger time. */
|
/* Setup maximum post trigger time. */
|
||||||
sigma_set_register(WRITE_POST_TRIGGER,
|
sigma_set_register(WRITE_POST_TRIGGER,
|
||||||
(ctx->capture_ratio * 255) / 100, ctx);
|
(devc->capture_ratio * 255) / 100, devc);
|
||||||
|
|
||||||
/* Start acqusition. */
|
/* Start acqusition. */
|
||||||
gettimeofday(&ctx->start_tv, 0);
|
gettimeofday(&devc->start_tv, 0);
|
||||||
sigma_set_register(WRITE_MODE, 0x0d, ctx);
|
sigma_set_register(WRITE_MODE, 0x0d, devc);
|
||||||
|
|
||||||
ctx->session_dev_id = cb_data;
|
devc->session_dev_id = cb_data;
|
||||||
|
|
||||||
if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
|
if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
|
||||||
sr_err("sigma: %s: packet malloc failed.", __func__);
|
sr_err("sigma: %s: packet malloc failed.", __func__);
|
||||||
|
@ -1375,14 +1380,14 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
packet->payload = header;
|
packet->payload = header;
|
||||||
header->feed_version = 1;
|
header->feed_version = 1;
|
||||||
gettimeofday(&header->starttime, NULL);
|
gettimeofday(&header->starttime, NULL);
|
||||||
sr_session_send(ctx->session_dev_id, packet);
|
sr_session_send(devc->session_dev_id, packet);
|
||||||
|
|
||||||
/* Send metadata about the SR_DF_LOGIC packets to come. */
|
/* Send metadata about the SR_DF_LOGIC packets to come. */
|
||||||
packet->type = SR_DF_META_LOGIC;
|
packet->type = SR_DF_META_LOGIC;
|
||||||
packet->payload = &meta;
|
packet->payload = &meta;
|
||||||
meta.samplerate = ctx->cur_samplerate;
|
meta.samplerate = devc->cur_samplerate;
|
||||||
meta.num_probes = ctx->num_probes;
|
meta.num_probes = devc->num_probes;
|
||||||
sr_session_send(ctx->session_dev_id, packet);
|
sr_session_send(devc->session_dev_id, packet);
|
||||||
|
|
||||||
/* Add capture source. */
|
/* Add capture source. */
|
||||||
sr_source_add(0, G_IO_IN, 10, receive_data, (void *)sdi);
|
sr_source_add(0, G_IO_IN, 10, receive_data, (void *)sdi);
|
||||||
|
@ -1390,7 +1395,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
g_free(header);
|
g_free(header);
|
||||||
g_free(packet);
|
g_free(packet);
|
||||||
|
|
||||||
ctx->state.state = SIGMA_CAPTURE;
|
devc->state.state = SIGMA_CAPTURE;
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
@ -1398,36 +1403,36 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi,
|
static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi,
|
||||||
void *cb_data)
|
void *cb_data)
|
||||||
{
|
{
|
||||||
struct context *ctx;
|
struct dev_context *devc;
|
||||||
uint8_t modestatus;
|
uint8_t modestatus;
|
||||||
|
|
||||||
/* Avoid compiler warnings. */
|
/* Avoid compiler warnings. */
|
||||||
(void)cb_data;
|
(void)cb_data;
|
||||||
|
|
||||||
if (!(ctx = sdi->priv)) {
|
if (!(devc = sdi->priv)) {
|
||||||
sr_err("sigma: %s: sdi->priv was NULL", __func__);
|
sr_err("sigma: %s: sdi->priv was NULL", __func__);
|
||||||
return SR_ERR_BUG;
|
return SR_ERR_BUG;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stop acquisition. */
|
/* Stop acquisition. */
|
||||||
sigma_set_register(WRITE_MODE, 0x11, ctx);
|
sigma_set_register(WRITE_MODE, 0x11, devc);
|
||||||
|
|
||||||
/* Set SDRAM Read Enable. */
|
/* Set SDRAM Read Enable. */
|
||||||
sigma_set_register(WRITE_MODE, 0x02, ctx);
|
sigma_set_register(WRITE_MODE, 0x02, devc);
|
||||||
|
|
||||||
/* Get the current position. */
|
/* Get the current position. */
|
||||||
sigma_read_pos(&ctx->state.stoppos, &ctx->state.triggerpos, ctx);
|
sigma_read_pos(&devc->state.stoppos, &devc->state.triggerpos, devc);
|
||||||
|
|
||||||
/* Check if trigger has fired. */
|
/* Check if trigger has fired. */
|
||||||
modestatus = sigma_get_register(READ_MODE, ctx);
|
modestatus = sigma_get_register(READ_MODE, devc);
|
||||||
if (modestatus & 0x20)
|
if (modestatus & 0x20)
|
||||||
ctx->state.triggerchunk = ctx->state.triggerpos / 512;
|
devc->state.triggerchunk = devc->state.triggerpos / 512;
|
||||||
else
|
else
|
||||||
ctx->state.triggerchunk = -1;
|
devc->state.triggerchunk = -1;
|
||||||
|
|
||||||
ctx->state.chunks_downloaded = 0;
|
devc->state.chunks_downloaded = 0;
|
||||||
|
|
||||||
ctx->state.state = SIGMA_DOWNLOAD;
|
devc->state.state = SIGMA_DOWNLOAD;
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
@ -1445,5 +1450,5 @@ SR_PRIV struct sr_dev_driver asix_sigma_driver_info = {
|
||||||
.dev_config_set = hw_dev_config_set,
|
.dev_config_set = hw_dev_config_set,
|
||||||
.dev_acquisition_start = hw_dev_acquisition_start,
|
.dev_acquisition_start = hw_dev_acquisition_start,
|
||||||
.dev_acquisition_stop = hw_dev_acquisition_stop,
|
.dev_acquisition_stop = hw_dev_acquisition_stop,
|
||||||
.instances = NULL,
|
.priv = NULL,
|
||||||
};
|
};
|
||||||
|
|
|
@ -173,8 +173,13 @@ struct sigma_state {
|
||||||
int chunks_downloaded;
|
int chunks_downloaded;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Private driver context. */
|
||||||
|
struct drv_context {
|
||||||
|
GSList *instances;
|
||||||
|
};
|
||||||
|
|
||||||
/* Private, per-device-instance driver context. */
|
/* Private, per-device-instance driver context. */
|
||||||
struct context {
|
struct dev_context {
|
||||||
struct ftdi_context ftdic;
|
struct ftdi_context ftdic;
|
||||||
uint64_t cur_samplerate;
|
uint64_t cur_samplerate;
|
||||||
uint64_t period_ps;
|
uint64_t period_ps;
|
||||||
|
|
Loading…
Reference in New Issue