*/
#include <glib.h>
-#include "sigrok.h"
+#include <sigrok.h>
int sigrok_init(void)
{
- int ret;
-
- ret = load_hwplugins();
-
- return ret;
+ return load_hwplugins();
}
-
void sigrok_cleanup(void)
{
-
device_close_all();
-
}
-
-
#include <stdint.h>
#include <string.h>
#include <glib.h>
-#include "sigrok.h"
+#include <sigrok.h>
static gpointer new_chunk(struct datastore **ds);
-
-
struct datastore *datastore_new(int unitsize)
{
struct datastore *ds;
return ds;
}
-
void datastore_destroy(struct datastore *ds)
{
GSList *chunk;
- for(chunk = ds->chunklist; chunk; chunk = chunk->next)
+ for (chunk = ds->chunklist; chunk; chunk = chunk->next)
g_free(chunk->data);
g_slist_free(ds->chunklist);
g_free(ds);
-
}
-
-void datastore_put(struct datastore *ds, void *data, unsigned int length, int in_unitsize, int *probelist)
+void datastore_put(struct datastore *ds, void *data, unsigned int length,
+ int in_unitsize, int *probelist)
{
unsigned int stored;
int capacity, size, num_chunks, chunk_bytes_free, chunk_offset;
in_unitsize = in_unitsize;
probelist = probelist;
- if(ds->chunklist == NULL)
+ if (ds->chunklist == NULL)
chunk = new_chunk(&ds);
else
chunk = g_slist_last(ds->chunklist)->data;
+
num_chunks = g_slist_length(ds->chunklist);
capacity = (num_chunks * DATASTORE_CHUNKSIZE);
chunk_bytes_free = capacity - (ds->ds_unitsize * ds->num_units);
- chunk_offset = capacity - (DATASTORE_CHUNKSIZE * (num_chunks - 1)) - chunk_bytes_free;
+ chunk_offset = capacity - (DATASTORE_CHUNKSIZE * (num_chunks - 1))
+ - chunk_bytes_free;
stored = 0;
- while(stored < length) {
- if(chunk_bytes_free == 0) {
+ while (stored < length) {
+ if (chunk_bytes_free == 0) {
chunk = new_chunk(&ds);
chunk_bytes_free = DATASTORE_CHUNKSIZE;
chunk_offset = 0;
}
- if(length - stored > (unsigned int)chunk_bytes_free)
+ if (length - stored > (unsigned int)chunk_bytes_free)
size = chunk_bytes_free;
else
- /* last part, won't fill up this chunk */
+ /* Last part, won't fill up this chunk. */
size = length - stored;
+
memcpy(chunk + chunk_offset, data + stored, size);
chunk_bytes_free -= size;
stored += size;
}
ds->num_units += stored / ds->ds_unitsize;
-
}
-
static gpointer new_chunk(struct datastore **ds)
{
gpointer chunk;
return chunk;
}
-
-
*/
#include <stdio.h>
-#include "sigrok.h"
+#include <sigrok.h>
void hexdump(unsigned char *address, int length)
{
int i;
- for(i = 0; i < length; i++)
- {
- if((i & 0x0f) == 0)
- {
- if(i)
+ for (i = 0; i < length; i++) {
+ if ((i & 0x0f) == 0) {
+ if (i)
printf("\n");
printf("%.4x ", i);
}
printf("%.2x ", address[i]);
}
printf("\n");
-
}
#include <stdio.h>
#include <glib.h>
-#include "sigrok.h"
+#include <sigrok.h>
extern struct sigrok_global *global;
GSList *devices = NULL;
-
void device_scan(void)
{
GSList *plugins, *l;
plugins = list_hwplugins();
- /* initialize all plugins first. Since the init() call may involve
+ /*
+ * Initialize all plugins first. Since the init() call may involve
* a firmware upload and associated delay, we may as well get all
* of these out of the way first.
*/
- for(l = plugins; l; l = l->next)
- {
+ for (l = plugins; l; l = l->next) {
plugin = l->data;
g_message("initializing %s plugin", plugin->name);
num_devices = plugin->init(NULL);
- for(i = 0; i < num_devices; i++)
- {
+ for (i = 0; i < num_devices; i++)
device_new(plugin, i);
- }
}
-
}
-
void device_close_all(void)
{
struct device *device;
- while(devices)
- {
+ while (devices) {
device = devices->data;
device->plugin->close(device->plugin_index);
device_destroy(device);
}
-
}
-
GSList *device_list(void)
{
-
return devices;
}
-
struct device *device_new(struct device_plugin *plugin, int plugin_index)
{
struct device *device;
device->plugin_index = plugin_index;
devices = g_slist_append(devices, device);
- num_probes = (int) device->plugin->get_device_info(device->plugin_index, DI_NUM_PROBES);
- for(i = 0; i < num_probes; i++)
- {
- snprintf(probename, 16, "%d", i+1);
+ num_probes = (int)device->plugin->get_device_info(device->plugin_index,
+ DI_NUM_PROBES);
+ for (i = 0; i < num_probes; i++) {
+ snprintf(probename, 16, "%d", i + 1);
device_probe_add(device, probename);
}
return device;
}
-
void device_clear(struct device *device)
{
- unsigned int probenum;
+ unsigned int pnum;
- /* TODO: plugin-specific clear call? */
+ /* TODO: Plugin-specific clear call? */
- if(device->probes)
- for(probenum = 1; probenum <= g_slist_length(device->probes); probenum++)
- device_probe_clear(device, probenum);
+ if (!device->probes)
+ return;
+ for (pnum = 1; pnum <= g_slist_length(device->probes); pnum++)
+ device_probe_clear(device, pnum);
}
-
void device_destroy(struct device *device)
{
- unsigned int probenum;
+ unsigned int pnum;
- /* TODO: plugin-specific destroy call, need to decrease refcount in plugin */
+ /*
+ * TODO: Plugin-specific destroy call, need to decrease refcount
+ * in plugin.
+ */
devices = g_slist_remove(devices, device);
- if(device->probes)
- {
- for(probenum = 1; probenum <= g_slist_length(device->probes); probenum++)
- device_probe_clear(device, probenum);
+ if (device->probes) {
+ for (pnum = 1; pnum <= g_slist_length(device->probes); pnum++)
+ device_probe_clear(device, pnum);
g_slist_free(device->probes);
}
g_free(device);
-
}
-
void device_probe_clear(struct device *device, int probenum)
{
struct probe *p;
p = probe_find(device, probenum);
- if(!p)
+ if (!p)
return;
- if(p->name)
- {
+ if (p->name) {
g_free(p->name);
p->name = NULL;
}
- if(p->trigger)
- {
+ if (p->trigger) {
g_free(p->trigger);
p->trigger = NULL;
}
-
}
-
void device_probe_add(struct device *device, char *name)
{
struct probe *p;
p->name = g_strdup(name);
p->trigger = NULL;
device->probes = g_slist_append(device->probes, p);
-
}
-
struct probe *probe_find(struct device *device, int probenum)
{
GSList *l;
struct probe *p, *found_probe;
found_probe = NULL;
- for(l = device->probes; l; l = l->next)
- {
+ for (l = device->probes; l; l = l->next) {
p = l->data;
- if(p->index == probenum)
- {
+ if (p->index == probenum) {
found_probe = p;
break;
}
return found_probe;
}
-
void device_probe_name(struct device *device, int probenum, char *name)
{
struct probe *p;
p = probe_find(device, probenum);
- if(!p)
+ if (!p)
return;
- if(p->name)
+ if (p->name)
g_free(p->name);
p->name = g_strdup(name);
-
}
-
void device_trigger_clear(struct device *device)
{
struct probe *p;
- unsigned int probenum;
-
- if(device->probes)
- for(probenum = 1; probenum <= g_slist_length(device->probes); probenum++)
- {
- p = probe_find(device, probenum);
- if(p && p->trigger)
- {
- g_free(p->trigger);
- p->trigger = NULL;
- }
- }
+ unsigned int pnum;
-}
+ if (!device->probes)
+ return;
+ for (pnum = 1; pnum <= g_slist_length(device->probes); pnum++) {
+ p = probe_find(device, pnum);
+ if (p && p->trigger) {
+ g_free(p->trigger);
+ p->trigger = NULL;
+ }
+ }
+}
void device_trigger_set(struct device *device, int probenum, char *trigger)
{
struct probe *p;
p = probe_find(device, probenum);
- if(!p)
+ if (!p)
return;
- if(p->trigger)
+ if (p->trigger)
g_free(p->trigger);
p->trigger = g_strdup(trigger);
-
}
-
-
};
/*
- * datafeed
+ * Datafeed
*/
/* datafeed_packet.type values */
};
/*
- * output
+ * Output
*/
struct output {
struct output_format *format;
/* Hardware plugin capabilities */
enum {
- HWCAP_DUMMY, // used to terminate lists
+ HWCAP_DUMMY, /* Used to terminate lists */
HWCAP_LOGIC_ANALYZER,
- HWCAP_SAMPLERATE, // change samplerate
- HWCAP_PROBECONFIG, // configure probe mask
- HWCAP_CAPTURE_RATIO, // set pre-trigger / post-trigger ratio
- HWCAP_LIMIT_MSEC, // set a time limit for sample acquisition
- HWCAP_LIMIT_SAMPLES, // set a limit on number of samples
+ HWCAP_SAMPLERATE, /* Change samplerate */
+ HWCAP_PROBECONFIG, /* Configure probe mask */
+ HWCAP_CAPTURE_RATIO, /* Set pre-trigger / post-trigger ratio */
+ HWCAP_LIMIT_MSEC, /* Set a time limit for sample acquisition */
+ HWCAP_LIMIT_SAMPLES, /* Set a limit on number of samples */
};
struct hwcap_option {
DI_CUR_SAMPLERATE,
};
-/* a device supports either a range of samplerates with steps of a given
- * granularity, or is limited to a set of defined samplerates. use either
+/*
+ * A device supports either a range of samplerates with steps of a given
+ * granularity, or is limited to a set of defined samplerates. Use either
* step or list, but not both.
*/
struct samplerates {
};
struct device_plugin {
- /* plugin-specific */
+ /* Plugin-specific */
char *name;
int api_version;
int (*init) (char *deviceinfo);
void (*cleanup) (void);
- /* device-specific */
+ /* Device-specific */
int (*open) (int device_index);
void (*close) (int device_index);
void *(*get_device_info) (int device_index, int device_info_id);
/* Generic device instances */
struct sigrok_device_instance *sigrok_device_instance_new(int index,
int status, char *vendor, char *model, char *version);
-struct sigrok_device_instance *get_sigrok_device_instance(GSList *device_instances, int device_index);
+struct sigrok_device_instance *get_sigrok_device_instance(
+ GSList *device_instances, int device_index);
void sigrok_device_instance_free(struct sigrok_device_instance *sdi);
/* USB-specific instances */
int find_hwcap(int *capabilities, int hwcap);
struct hwcap_option *find_hwcap_option(int hwcap);
void source_remove(int fd);
-void source_add(int fd, int events, int timeout, receive_data_callback rcv_cb, void *user_data);
+void source_add(int fd, int events, int timeout, receive_data_callback rcv_cb,
+ void *user_data);
/*--- session.c -------------------------------------------------------------*/
GSList *devices;
/* List of struct analyzer* */
GSList *analyzers;
- /* datafeed callbacks */
+ /* Datafeed callbacks */
GSList *datafeed_callbacks;
GTimeVal starttime;
};
int serial_close(int fd);
void *serial_backup_params(int fd);
void serial_restore_params(int fd, void *backup);
-int serial_set_params(int fd, int speed, int bits, int parity, int stopbits, int flowcontrol);
+int serial_set_params(int fd, int speed, int bits, int parity, int stopbits,
+ int flowcontrol);
#endif