sigma: Add support for SIGMA2 (req. new firmware).
This commit is contained in:
parent
3c36c403fa
commit
e3fff420da
|
@ -330,14 +330,14 @@ static int bin2bitbang(const char *filename,
|
|||
unsigned char **buf, size_t *buf_size)
|
||||
{
|
||||
FILE *f;
|
||||
long file_size;
|
||||
unsigned long file_size;
|
||||
unsigned long offset = 0;
|
||||
unsigned char *p;
|
||||
uint8_t *compressed_buf, *firmware;
|
||||
uLongf csize, fwsize;
|
||||
uint8_t *firmware;
|
||||
unsigned long fwsize = 0;
|
||||
const int buffer_size = 65536;
|
||||
size_t i;
|
||||
int c, ret, bit, v;
|
||||
int c, bit, v;
|
||||
uint32_t imm = 0x3f6df2ab;
|
||||
|
||||
f = g_fopen(filename, "rb");
|
||||
|
@ -356,44 +356,30 @@ static int bin2bitbang(const char *filename,
|
|||
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
if (!(compressed_buf = g_try_malloc(file_size))) {
|
||||
sr_err("sigma: %s: compressed_buf malloc failed", __func__);
|
||||
fclose(f);
|
||||
return SR_ERR_MALLOC;
|
||||
}
|
||||
|
||||
if (!(firmware = g_try_malloc(buffer_size))) {
|
||||
sr_err("sigma: %s: firmware malloc failed", __func__);
|
||||
fclose(f);
|
||||
g_free(compressed_buf);
|
||||
return SR_ERR_MALLOC;
|
||||
}
|
||||
|
||||
csize = 0;
|
||||
while ((c = getc(f)) != EOF) {
|
||||
imm = (imm + 0xa853753) % 177 + (imm * 0x8034052);
|
||||
compressed_buf[csize++] = c ^ imm;
|
||||
firmware[fwsize++] = c ^ imm;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
fwsize = buffer_size;
|
||||
ret = uncompress(firmware, &fwsize, compressed_buf, csize);
|
||||
if (ret < 0) {
|
||||
g_free(compressed_buf);
|
||||
g_free(firmware);
|
||||
sr_err("sigma: Could not unpack Sigma firmware. "
|
||||
"(Error %d).", ret);
|
||||
return SR_ERR;
|
||||
if(fwsize != file_size) {
|
||||
sr_err("sigma: %s: Error reading firmware", filename);
|
||||
fclose(f);
|
||||
g_free(firmware);
|
||||
return SR_ERR;
|
||||
}
|
||||
|
||||
g_free(compressed_buf);
|
||||
|
||||
*buf_size = fwsize * 2 * 8;
|
||||
|
||||
*buf = p = (unsigned char *)g_try_malloc(*buf_size);
|
||||
if (!p) {
|
||||
sr_err("sigma: %s: buf/p malloc failed", __func__);
|
||||
g_free(compressed_buf);
|
||||
g_free(firmware);
|
||||
return SR_ERR_MALLOC;
|
||||
}
|
||||
|
@ -424,22 +410,39 @@ static int hw_init(const char *devinfo)
|
|||
{
|
||||
struct sr_dev_inst *sdi;
|
||||
struct context *ctx;
|
||||
struct ftdi_device_list *devlist;
|
||||
char serial_txt[10];
|
||||
uint32_t serial;
|
||||
|
||||
/* Avoid compiler warnings. */
|
||||
(void)devinfo;
|
||||
|
||||
if (!(ctx = g_try_malloc(sizeof(struct context)))) {
|
||||
sr_err("sigma: %s: ctx malloc failed", __func__);
|
||||
return 0; /* FIXME: Should be SR_ERR_MALLOC. */
|
||||
return SR_ERR_MALLOC;
|
||||
}
|
||||
|
||||
ftdi_init(&ctx->ftdic);
|
||||
|
||||
/* Look for SIGMAs. */
|
||||
if (ftdi_usb_open_desc(&ctx->ftdic, USB_VENDOR, USB_PRODUCT,
|
||||
USB_DESCRIPTION, NULL) < 0)
|
||||
|
||||
if (ftdi_usb_find_all(&ctx->ftdic, &devlist,
|
||||
USB_VENDOR, USB_PRODUCT) < 0)
|
||||
goto free;
|
||||
|
||||
/* Make sure it's a version 1 or 2 SIGMA. */
|
||||
ftdi_usb_get_strings(&ctx->ftdic, devlist->dev, NULL, 0, NULL, 0,
|
||||
serial_txt, sizeof(serial_txt));
|
||||
sscanf(serial_txt, "%x", &serial);
|
||||
|
||||
if (serial < 0xa6010000 || serial > 0xa602ffff ) {
|
||||
sr_err("sigma: Only SIGMA and SIGMA2 are supported "
|
||||
"in this version of Sigrok.");
|
||||
goto free;
|
||||
}
|
||||
|
||||
sr_info("Found ASIX SIGMA - Serial: %s", serial_txt);
|
||||
|
||||
ctx->cur_samplerate = 0;
|
||||
ctx->period_ps = 0;
|
||||
ctx->limit_msec = 0;
|
||||
|
@ -461,7 +464,7 @@ static int hw_init(const char *devinfo)
|
|||
dev_insts = g_slist_append(dev_insts, sdi);
|
||||
|
||||
/* We will open the device again when we need it. */
|
||||
ftdi_usb_close(&ctx->ftdic);
|
||||
ftdi_list_free(&devlist);
|
||||
|
||||
return 1;
|
||||
|
||||
|
@ -529,6 +532,7 @@ static int upload_firmware(int firmware_idx, struct context *ctx)
|
|||
}
|
||||
|
||||
/* Upload firmare. */
|
||||
sr_info("sigma: Uploading firmware %s", firmware_files[firmware_idx]);
|
||||
sigma_write(buf, buf_size, ctx);
|
||||
|
||||
g_free(buf);
|
||||
|
@ -558,6 +562,8 @@ static int upload_firmware(int firmware_idx, struct context *ctx)
|
|||
|
||||
ctx->cur_firmware = firmware_idx;
|
||||
|
||||
sr_info("sigma: Firmware uploaded");
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
|
@ -617,8 +623,6 @@ static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate)
|
|||
ctx->samples_per_event = 16 / ctx->num_probes;
|
||||
ctx->state.state = SIGMA_IDLE;
|
||||
|
||||
sr_info("sigma: Firmware uploaded");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1039,9 +1043,8 @@ static int receive_data(int fd, int revents, void *cb_data)
|
|||
|
||||
if (running_msec < ctx->limit_msec && numchunks < 32767)
|
||||
return TRUE; /* While capturing... */
|
||||
else {
|
||||
|
||||
hw_dev_acquisition_stop(sdi->index, sdi);
|
||||
else
|
||||
hw_dev_acquisition_stop(sdi->index, sdi);
|
||||
|
||||
} else if (ctx->state.state == SIGMA_DOWNLOAD) {
|
||||
if (ctx->state.chunks_downloaded >= numchunks) {
|
||||
|
|
Loading…
Reference in New Issue