* ASIX Sigma Logic Analyzer Driver
*/
+#include "config.h"
#include <ftdi.h>
#include <string.h>
#include <zlib.h>
#include <sigrok.h>
-#include <config.h>
#include "asix-sigma.h"
#define USB_VENDOR 0xa600
};
static int capabilities[] = {
- HWCAP_LOGIC_ANALYZER,
- HWCAP_SAMPLERATE,
- HWCAP_CAPTURE_RATIO,
- HWCAP_PROBECONFIG,
+ SR_HWCAP_LOGIC_ANALYZER,
+ SR_HWCAP_SAMPLERATE,
+ SR_HWCAP_CAPTURE_RATIO,
+ SR_HWCAP_PROBECONFIG,
- HWCAP_LIMIT_MSEC,
+ SR_HWCAP_LIMIT_MSEC,
0,
};
sigma_write_register(WRITE_TRIGGER_SELECT0, (uint8_t *) &lut->params,
sizeof(lut->params), sigma);
- return SIGROK_OK;
+ return SR_OK;
}
/* Generate the bitbang stream for programming the FPGA. */
int c, ret, bit, v;
uint32_t imm = 0x3f6df2ab;
- f = fopen(filename, "r");
+ f = g_fopen(filename, "rb");
if (!f) {
- g_warning("fopen(\"%s\", \"r\")", filename);
+ g_warning("g_fopen(\"%s\", \"rb\")", filename);
return -1;
}
static int hw_init(char *deviceinfo)
{
- struct sigrok_device_instance *sdi;
+ struct sr_device_instance *sdi;
struct sigma *sigma = g_malloc(sizeof(struct sigma));
deviceinfo = deviceinfo;
sigma->use_triggers = 0;
/* Register SIGMA device. */
- sdi = sigrok_device_instance_new(0, ST_INITIALIZING,
+ sdi = sr_device_instance_new(0, SR_ST_INITIALIZING,
USB_VENDOR_NAME, USB_MODEL_NAME, USB_MODEL_VERSION);
if (!sdi)
goto free;
if (-1 == bin2bitbang(firmware_path, &buf, &buf_size)) {
g_warning("An error occured while reading the firmware: %s",
firmware_path);
- return SIGROK_ERR;
+ return SR_ERR;
}
/* Upload firmare. */
if ((ret = ftdi_set_bitmode(&sigma->ftdic, 0x00, BITMODE_RESET)) < 0) {
g_warning("ftdi_set_bitmode failed: %s",
ftdi_get_error_string(&sigma->ftdic));
- return SIGROK_ERR;
+ return SR_ERR;
}
ftdi_usb_purge_buffers(&sigma->ftdic);
if (ret != 3 ||
result[0] != 0xa6 || result[1] != 0x55 || result[2] != 0xaa) {
g_warning("Configuration failed. Invalid reply received.");
- return SIGROK_ERR;
+ return SR_ERR;
}
sigma->cur_firmware = firmware_idx;
- return SIGROK_OK;
+ return SR_OK;
}
static int hw_opendev(int device_index)
{
- struct sigrok_device_instance *sdi;
+ struct sr_device_instance *sdi;
struct sigma *sigma;
int ret;
- if (!(sdi = get_sigrok_device_instance(device_instances, device_index)))
- return SIGROK_ERR;
+ if (!(sdi = sr_get_device_instance(device_instances, device_index)))
+ return SR_ERR;
sigma = sdi->priv;
return 0;
}
- sdi->status = ST_ACTIVE;
+ sdi->status = SR_ST_ACTIVE;
- return SIGROK_OK;
+ return SR_OK;
}
-static int set_samplerate(struct sigrok_device_instance *sdi,
+static int set_samplerate(struct sr_device_instance *sdi,
uint64_t samplerate)
{
int i, ret;
break;
}
if (supported_samplerates[i] == 0)
- return SIGROK_ERR_SAMPLERATE;
+ return SR_ERR_SAMPLERATE;
if (samplerate <= MHZ(50)) {
ret = upload_firmware(0, sigma);
* The Sigma supports complex triggers using boolean expressions, but this
* has not been implemented yet.
*/
-static int configure_probes(struct sigrok_device_instance *sdi, GSList *probes)
+static int configure_probes(struct sr_device_instance *sdi, GSList *probes)
{
struct sigma *sigma = sdi->priv;
struct probe *probe;
g_warning("Asix Sigma only supports a single "
"pin trigger in 100 and 200 "
"MHz mode.");
- return SIGROK_ERR;
+ return SR_ERR;
}
if (probe->trigger[0] == 'f')
sigma->trigger.fallingmask |= probebit;
g_warning("Asix Sigma only supports "
"rising/falling trigger in 100 "
"and 200 MHz mode.");
- return SIGROK_ERR;
+ return SR_ERR;
}
++trigger_set;
if (trigger_set > 1) {
g_warning("Asix Sigma only supports 1 rising/"
"falling triggers.");
- return SIGROK_ERR;
+ return SR_ERR;
}
}
sigma->use_triggers = 1;
}
- return SIGROK_OK;
+ return SR_OK;
}
static void hw_closedev(int device_index)
{
- struct sigrok_device_instance *sdi;
+ struct sr_device_instance *sdi;
struct sigma *sigma;
- if ((sdi = get_sigrok_device_instance(device_instances, device_index)))
+ if ((sdi = sr_get_device_instance(device_instances, device_index)))
{
sigma = sdi->priv;
- if (sdi->status == ST_ACTIVE)
+ if (sdi->status == SR_ST_ACTIVE)
ftdi_usb_close(&sigma->ftdic);
- sdi->status = ST_INACTIVE;
+ sdi->status = SR_ST_INACTIVE;
}
}
static void hw_cleanup(void)
{
GSList *l;
- struct sigrok_device_instance *sdi;
+ struct sr_device_instance *sdi;
/* Properly close all devices. */
for (l = device_instances; l; l = l->next) {
sdi = l->data;
if (sdi->priv != NULL)
free(sdi->priv);
- sigrok_device_instance_free(sdi);
+ sr_device_instance_free(sdi);
}
g_slist_free(device_instances);
device_instances = NULL;
static void *hw_get_device_info(int device_index, int device_info_id)
{
- struct sigrok_device_instance *sdi;
+ struct sr_device_instance *sdi;
struct sigma *sigma;
void *info = NULL;
- if (!(sdi = get_sigrok_device_instance(device_instances, device_index))) {
+ if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
fprintf(stderr, "It's NULL.\n");
return NULL;
}
sigma = sdi->priv;
switch (device_info_id) {
- case DI_INSTANCE:
+ case SR_DI_INSTANCE:
info = sdi;
break;
- case DI_NUM_PROBES:
+ case SR_DI_NUM_PROBES:
info = GINT_TO_POINTER(16);
break;
- case DI_SAMPLERATES:
+ case SR_DI_SAMPLERATES:
info = &samplerates;
break;
- case DI_TRIGGER_TYPES:
+ case SR_DI_TRIGGER_TYPES:
info = (char *)TRIGGER_TYPES;
break;
- case DI_CUR_SAMPLERATE:
+ case SR_DI_CUR_SAMPLERATE:
info = &sigma->cur_samplerate;
break;
}
static int hw_get_status(int device_index)
{
- struct sigrok_device_instance *sdi;
+ struct sr_device_instance *sdi;
- sdi = get_sigrok_device_instance(device_instances, device_index);
+ sdi = sr_get_device_instance(device_instances, device_index);
if (sdi)
return sdi->status;
else
- return ST_NOT_FOUND;
+ return SR_ST_NOT_FOUND;
}
static int *hw_get_capabilities(void)
static int hw_set_configuration(int device_index, int capability, void *value)
{
- struct sigrok_device_instance *sdi;
+ struct sr_device_instance *sdi;
struct sigma *sigma;
int ret;
- if (!(sdi = get_sigrok_device_instance(device_instances, device_index)))
- return SIGROK_ERR;
+ if (!(sdi = sr_get_device_instance(device_instances, device_index)))
+ return SR_ERR;
sigma = sdi->priv;
- if (capability == HWCAP_SAMPLERATE) {
+ if (capability == SR_HWCAP_SAMPLERATE) {
ret = set_samplerate(sdi, *(uint64_t*) value);
- } else if (capability == HWCAP_PROBECONFIG) {
+ } else if (capability == SR_HWCAP_PROBECONFIG) {
ret = configure_probes(sdi, value);
- } else if (capability == HWCAP_LIMIT_MSEC) {
+ } else if (capability == SR_HWCAP_LIMIT_MSEC) {
sigma->limit_msec = *(uint64_t*) value;
if (sigma->limit_msec > 0)
- ret = SIGROK_OK;
+ ret = SR_OK;
else
- ret = SIGROK_ERR;
- } else if (capability == HWCAP_CAPTURE_RATIO) {
+ ret = SR_ERR;
+ } else if (capability == SR_HWCAP_CAPTURE_RATIO) {
sigma->capture_ratio = *(uint64_t*) value;
if (sigma->capture_ratio < 0 || sigma->capture_ratio > 100)
- ret = SIGROK_ERR;
+ ret = SR_ERR;
else
- ret = SIGROK_OK;
+ ret = SR_OK;
} else {
- ret = SIGROK_ERR;
+ ret = SR_ERR;
}
return ret;
uint16_t *lastsample, int triggerpos,
uint16_t limit_chunk, void *user_data)
{
- struct sigrok_device_instance *sdi = user_data;
+ struct sr_device_instance *sdi = user_data;
struct sigma *sigma = sdi->priv;
uint16_t tsdiff, ts;
uint16_t samples[65536 * sigma->samples_per_event];
- struct datafeed_packet packet;
+ struct sr_datafeed_packet packet;
int i, j, k, l, numpad, tosend;
size_t n = 0, sent = 0;
int clustersize = EVENTS_PER_CLUSTER * sigma->samples_per_event;
/* Decode partial chunk. */
if (limit_chunk && ts > limit_chunk)
- return SIGROK_OK;
+ return SR_OK;
/* Pad last sample up to current point. */
numpad = tsdiff * sigma->samples_per_event - clustersize;
while (sent < n) {
tosend = MIN(2048, n - sent);
- packet.type = DF_LOGIC;
+ packet.type = SR_DF_LOGIC;
packet.length = tosend * sizeof(uint16_t);
packet.unitsize = 2;
packet.payload = samples + sent;
&sigma->trigger);
if (tosend > 0) {
- packet.type = DF_LOGIC;
+ packet.type = SR_DF_LOGIC;
packet.length = tosend * sizeof(uint16_t);
packet.unitsize = 2;
packet.payload = samples;
/* Only send trigger if explicitly enabled. */
if (sigma->use_triggers) {
- packet.type = DF_TRIGGER;
+ packet.type = SR_DF_TRIGGER;
packet.length = 0;
packet.payload = 0;
session_bus(sigma->session_id, &packet);
tosend = n - sent;
if (tosend > 0) {
- packet.type = DF_LOGIC;
+ packet.type = SR_DF_LOGIC;
packet.length = tosend * sizeof(uint16_t);
packet.unitsize = 2;
packet.payload = samples + sent;
*lastsample = samples[n - 1];
}
- return SIGROK_OK;
+ return SR_OK;
}
static int receive_data(int fd, int revents, void *user_data)
{
- struct sigrok_device_instance *sdi = user_data;
+ struct sr_device_instance *sdi = user_data;
struct sigma *sigma = sdi->priv;
- struct datafeed_packet packet;
+ struct sr_datafeed_packet packet;
const int chunks_per_read = 32;
unsigned char buf[chunks_per_read * CHUNK_SIZE];
int bufsz, numchunks, i, newchunks;
} else if (sigma->state.state == SIGMA_DOWNLOAD) {
if (sigma->state.chunks_downloaded >= numchunks) {
/* End of samples. */
- packet.type = DF_END;
+ packet.type = SR_DF_END;
packet.length = 0;
session_bus(sigma->session_id, &packet);
/* Triggertype: event. */
lut->params.selres = 3;
- return SIGROK_OK;
+ return SR_OK;
}
static int hw_start_acquisition(int device_index, gpointer session_device_id)
{
- struct sigrok_device_instance *sdi;
+ struct sr_device_instance *sdi;
struct sigma *sigma;
- struct datafeed_packet packet;
- struct datafeed_header header;
+ struct sr_datafeed_packet packet;
+ struct sr_datafeed_header header;
struct clockselect_50 clockselect;
int frac;
uint8_t triggerselect;
session_device_id = session_device_id;
- if (!(sdi = get_sigrok_device_instance(device_instances, device_index)))
- return SIGROK_ERR;
+ if (!(sdi = sr_get_device_instance(device_instances, device_index)))
+ return SR_ERR;
sigma = sdi->priv;
sigma->session_id = session_device_id;
/* Send header packet to the session bus. */
- packet.type = DF_HEADER;
- packet.length = sizeof(struct datafeed_header);
+ packet.type = SR_DF_HEADER;
+ packet.length = sizeof(struct sr_datafeed_header);
packet.payload = &header;
header.feed_version = 1;
gettimeofday(&header.starttime, NULL);
header.samplerate = sigma->cur_samplerate;
- header.protocol_id = PROTO_RAW;
+ header.protocol_id = SR_PROTO_RAW;
header.num_logic_probes = sigma->num_probes;
header.num_analog_probes = 0;
session_bus(session_device_id, &packet);
sigma->state.state = SIGMA_CAPTURE;
- return SIGROK_OK;
+ return SR_OK;
}
static void hw_stop_acquisition(int device_index, gpointer session_device_id)
{
- struct sigrok_device_instance *sdi;
+ struct sr_device_instance *sdi;
struct sigma *sigma;
uint8_t modestatus;
- if (!(sdi = get_sigrok_device_instance(device_instances, device_index)))
+ if (!(sdi = sr_get_device_instance(device_instances, device_index)))
return;
sigma = sdi->priv;
sigma->state.state = SIGMA_DOWNLOAD;
}
-struct device_plugin asix_sigma_plugin_info = {
+struct sr_device_plugin asix_sigma_plugin_info = {
"asix-sigma",
+ "ASIX SIGMA",
1,
hw_init,
hw_cleanup,